-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (26 loc) · 957 Bytes
/
utils.py
File metadata and controls
37 lines (26 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from contextlib import contextmanager
from ._base import Graphic
@contextmanager
def pause_events(*graphics: Graphic):
"""
Context manager for pausing Graphic events.
Examples
--------
.. code-block::
# pass in any number of graphics
with fpl.pause_events(graphic1, graphic2, graphic3):
# enter context manager
# all events are blocked from graphic1, graphic2, graphic3
# context manager exited, event states restored.
"""
if not all([isinstance(g, Graphic) for g in graphics]):
raise TypeError(
f"`pause_events` only takes Graphic instances as arguments, "
f"you have passed the following types:\n{[type(g) for g in graphics]}"
)
original_vals = [g.block_events for g in graphics]
for g in graphics:
g.block_events = True
yield
for g, value in zip(graphics, original_vals):
g.block_events = value