interactive-figure 0.3.4__py3-none-any.whl → 0.3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of interactive-figure might be problematic. Click here for more details.
- interactive_figure/__about__.py +1 -1
- interactive_figure/interactive_figure.py +46 -19
- {interactive_figure-0.3.4.dist-info → interactive_figure-0.3.6.dist-info}/METADATA +4 -1
- interactive_figure-0.3.6.dist-info/RECORD +7 -0
- interactive_figure-0.3.4.dist-info/RECORD +0 -7
- {interactive_figure-0.3.4.dist-info → interactive_figure-0.3.6.dist-info}/WHEEL +0 -0
- {interactive_figure-0.3.4.dist-info → interactive_figure-0.3.6.dist-info}/licenses/LICENSE.txt +0 -0
interactive_figure/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.3.
|
|
1
|
+
__version__ = "0.3.6"
|
|
@@ -7,6 +7,7 @@ Source: https://github.com/teuncm/interactive-figure
|
|
|
7
7
|
|
|
8
8
|
import matplotlib.pyplot as plt
|
|
9
9
|
from types import SimpleNamespace
|
|
10
|
+
import sys
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def create(aspect_ratio="auto", hide_toolbar=False, **kwargs):
|
|
@@ -15,14 +16,14 @@ def create(aspect_ratio="auto", hide_toolbar=False, **kwargs):
|
|
|
15
16
|
Parameters
|
|
16
17
|
----------
|
|
17
18
|
aspect_ratio : str, optional
|
|
18
|
-
aspect ratio of the Axes,
|
|
19
|
+
aspect ratio of the Axes, default "auto".
|
|
19
20
|
hide_toolbar : bool, optional
|
|
20
|
-
whether to hide the toolbar,
|
|
21
|
+
whether to hide the toolbar, default False.
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
Remaining arguments will be sent to the figure upon creation.
|
|
23
24
|
|
|
24
25
|
Raises
|
|
25
|
-
|
|
26
|
+
----------
|
|
26
27
|
RuntimeError
|
|
27
28
|
if multiple interactive figures are created.
|
|
28
29
|
"""
|
|
@@ -57,10 +58,12 @@ def create(aspect_ratio="auto", hide_toolbar=False, **kwargs):
|
|
|
57
58
|
fig.canvas.mpl_disconnect(fig.canvas.manager.button_press_handler_id)
|
|
58
59
|
fig.canvas.mpl_connect("key_press_event", _key_press_handler)
|
|
59
60
|
fig.canvas.mpl_connect("button_press_event", _button_press_handler)
|
|
61
|
+
fig.canvas.mpl_connect("close_event", _close_handler)
|
|
60
62
|
|
|
61
|
-
print("
|
|
63
|
+
print("Interactive figure: created")
|
|
62
64
|
else:
|
|
63
|
-
raise RuntimeError("Error: you cannot create multiple interactive figures.")
|
|
65
|
+
raise RuntimeError("Error: you cannot create multiple interactive figures at the same time.")
|
|
66
|
+
|
|
64
67
|
|
|
65
68
|
def draw():
|
|
66
69
|
"""Draw contents of the figure."""
|
|
@@ -75,10 +78,15 @@ def draw():
|
|
|
75
78
|
|
|
76
79
|
|
|
77
80
|
def clear(hide_labels=False, set_limits=True):
|
|
78
|
-
"""Reset contents and layout of the figure.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
"""Reset contents and layout of the figure.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
set_limits : bool, optional
|
|
86
|
+
set the Axes limits to [0, 100].
|
|
87
|
+
hide_labels : bool, optional
|
|
88
|
+
remove all labels from the figure.
|
|
89
|
+
"""
|
|
82
90
|
_check_exists()
|
|
83
91
|
|
|
84
92
|
ax = _state.ax
|
|
@@ -104,13 +112,13 @@ def close():
|
|
|
104
112
|
"""Close the figure."""
|
|
105
113
|
_check_exists()
|
|
106
114
|
|
|
115
|
+
_state.closed_using_ui = False
|
|
107
116
|
plt.close(_state.fig)
|
|
108
117
|
|
|
118
|
+
# Handle proper closure so that the figure can be reused.
|
|
109
119
|
_state_reset_fig()
|
|
110
120
|
_state_reset_press()
|
|
111
121
|
|
|
112
|
-
print("Successfully closed the interactive figure.")
|
|
113
|
-
|
|
114
122
|
|
|
115
123
|
def wait_for_interaction(timeout=-1):
|
|
116
124
|
"""Wait for interaction.
|
|
@@ -160,7 +168,7 @@ def wait_for_interaction(timeout=-1):
|
|
|
160
168
|
interaction_type = None if event is None else event.name == "key_press_event"
|
|
161
169
|
|
|
162
170
|
if interaction_type is None:
|
|
163
|
-
# No button was pressed, so reset the state.
|
|
171
|
+
# No button was pressed, so reset the press state.
|
|
164
172
|
_state_reset_press()
|
|
165
173
|
|
|
166
174
|
return interaction_type
|
|
@@ -172,7 +180,7 @@ def get_last_key_press():
|
|
|
172
180
|
Returns
|
|
173
181
|
-------
|
|
174
182
|
str | None
|
|
175
|
-
The last key that was pressed
|
|
183
|
+
The last key that was pressed.
|
|
176
184
|
"""
|
|
177
185
|
_check_exists()
|
|
178
186
|
|
|
@@ -190,7 +198,7 @@ def get_last_mouse_press():
|
|
|
190
198
|
Returns
|
|
191
199
|
-------
|
|
192
200
|
int | None
|
|
193
|
-
The identifier of the last mouse button that was pressed
|
|
201
|
+
The identifier of the last mouse button that was pressed.
|
|
194
202
|
"""
|
|
195
203
|
_check_exists()
|
|
196
204
|
|
|
@@ -208,7 +216,7 @@ def get_last_mouse_pos():
|
|
|
208
216
|
Returns
|
|
209
217
|
-------
|
|
210
218
|
(x: float, y: float) | (None, None)
|
|
211
|
-
The last registered mouse position after any interaction
|
|
219
|
+
The last registered mouse position after any interaction.
|
|
212
220
|
"""
|
|
213
221
|
_check_exists()
|
|
214
222
|
|
|
@@ -224,16 +232,16 @@ def wait(timeout):
|
|
|
224
232
|
Parameters
|
|
225
233
|
----------
|
|
226
234
|
timeout : float
|
|
227
|
-
Number of seconds to wait for
|
|
235
|
+
Number of seconds to wait for.
|
|
228
236
|
"""
|
|
229
237
|
_check_exists()
|
|
230
238
|
|
|
231
239
|
_state.fig.canvas.start_event_loop(timeout=timeout)
|
|
232
|
-
#
|
|
240
|
+
# Reset the press state.
|
|
233
241
|
_state_reset_press()
|
|
234
242
|
|
|
235
243
|
|
|
236
|
-
#
|
|
244
|
+
# HIDDEN METHODS
|
|
237
245
|
|
|
238
246
|
|
|
239
247
|
def _get_state():
|
|
@@ -263,6 +271,7 @@ def _state_reset_fig():
|
|
|
263
271
|
"""Reset figure information."""
|
|
264
272
|
_state.fig = None
|
|
265
273
|
_state.ax = None
|
|
274
|
+
_state.closed_using_ui = True
|
|
266
275
|
|
|
267
276
|
|
|
268
277
|
def _state_reset_press():
|
|
@@ -301,6 +310,23 @@ def _button_press_handler(event):
|
|
|
301
310
|
_state.last_mouse_y = event.ydata
|
|
302
311
|
|
|
303
312
|
|
|
313
|
+
def _close_handler(event):
|
|
314
|
+
"""Exit when the user presses the red x to close the figure
|
|
315
|
+
to prevent an infinite event loop.
|
|
316
|
+
|
|
317
|
+
Parameters
|
|
318
|
+
----------
|
|
319
|
+
event
|
|
320
|
+
The event object that was generated internally
|
|
321
|
+
"""
|
|
322
|
+
print("Interactive figure: closed")
|
|
323
|
+
|
|
324
|
+
# Triggered if the UI ('the red x') is used to close the figure.
|
|
325
|
+
if _state.closed_using_ui:
|
|
326
|
+
print("Interactive figure: exited script")
|
|
327
|
+
sys.exit(0)
|
|
328
|
+
|
|
329
|
+
|
|
304
330
|
# Namespace to track the internal state of the interactive figure.
|
|
305
331
|
_state = SimpleNamespace(
|
|
306
332
|
fig=None,
|
|
@@ -309,4 +335,5 @@ _state = SimpleNamespace(
|
|
|
309
335
|
last_mousepress=None,
|
|
310
336
|
last_mouse_x=None,
|
|
311
337
|
last_mouse_y=None,
|
|
338
|
+
closed_using_ui=True
|
|
312
339
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: interactive-figure
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.6
|
|
4
4
|
Summary: Create interactive Matplotlib figures!
|
|
5
5
|
Project-URL: Documentation, https://teuncm.github.io/interactive-figure/autoapi/interactive_figure/interactive_figure/index.html
|
|
6
6
|
Project-URL: Issues, https://github.com/teuncm/interactive-figure/issues
|
|
@@ -63,6 +63,9 @@ hatch shell
|
|
|
63
63
|
hatch version fix
|
|
64
64
|
hatch build -c
|
|
65
65
|
./generate_docs.sh
|
|
66
|
+
|
|
67
|
+
# Publish
|
|
68
|
+
hatch publish
|
|
66
69
|
```
|
|
67
70
|
|
|
68
71
|
## Links
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interactive_figure/__about__.py,sha256=rshQ1apZMMdkI5bameILs0GVFulDBuEpfDswTVoETqk,23
|
|
2
|
+
interactive_figure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
interactive_figure/interactive_figure.py,sha256=1vAsDyZj4D5Prdp8HXtx8JCa7Q-3mzkiaLXZo1gbCwE,9047
|
|
4
|
+
interactive_figure-0.3.6.dist-info/METADATA,sha256=aprlOHFNqf1hSv7VSMt1-9Z1h-_CdNfhNpnV0VXr0kw,2438
|
|
5
|
+
interactive_figure-0.3.6.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
+
interactive_figure-0.3.6.dist-info/licenses/LICENSE.txt,sha256=R6IpPdPKA5nLHPKRXIhlFHLE59dMUtve0qeXhZPr0Hk,1043
|
|
7
|
+
interactive_figure-0.3.6.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
interactive_figure/__about__.py,sha256=EVh84K2XkED4bsPB10qR4q6SCbIp-6LdYq5IuJweVoo,23
|
|
2
|
-
interactive_figure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
interactive_figure/interactive_figure.py,sha256=l3AWVe6oQePBCcv3kGb5qEV_qxHWiuZeXyrxd5OlZTk,8318
|
|
4
|
-
interactive_figure-0.3.4.dist-info/METADATA,sha256=Yx_G-2KYRrZ0IcVf1ZO1zewjlEZG66a02eVbOJJAQvQ,2413
|
|
5
|
-
interactive_figure-0.3.4.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
-
interactive_figure-0.3.4.dist-info/licenses/LICENSE.txt,sha256=R6IpPdPKA5nLHPKRXIhlFHLE59dMUtve0qeXhZPr0Hk,1043
|
|
7
|
-
interactive_figure-0.3.4.dist-info/RECORD,,
|
|
File without changes
|
{interactive_figure-0.3.4.dist-info → interactive_figure-0.3.6.dist-info}/licenses/LICENSE.txt
RENAMED
|
File without changes
|