Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab6ecda

Browse filesBrowse files
committed
Make guiEvent available only within the event handlers.
1 parent 7baa2b8 commit ab6ecda
Copy full SHA for ab6ecda

File tree

Expand file treeCollapse file tree

2 files changed

+22
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-2
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Accessing ``event.guiEvent`` after event handlers return
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated: for some GUI toolkits, it is unsafe to do so. In the
4+
future, ``event.guiEvent`` will be set to None once the event handlers return;
5+
you may separately stash the object at your own risk.

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,11 +1257,26 @@ class Event:
12571257
def __init__(self, name, canvas, guiEvent=None):
12581258
self.name = name
12591259
self.canvas = canvas
1260-
self.guiEvent = guiEvent
1260+
self._guiEvent = guiEvent
1261+
self._guiEvent_deleted = False
12611262

12621263
def _process(self):
1263-
"""Generate an event with name ``self.name`` on ``self.canvas``."""
1264+
"""Process this event on ``self.canvas``, then unset ``guiEvent``."""
12641265
self.canvas.callbacks.process(self.name, self)
1266+
self._guiEvent_deleted = True
1267+
1268+
@property
1269+
def guiEvent(self):
1270+
# After deprecation elapses: remove _guiEvent_deleted; make guiEvent a plain
1271+
# attribute set to None by _process.
1272+
if self._guiEvent_deleted:
1273+
_api.warn_deprecated(
1274+
"3.8", message="Accessing guiEvent outside of the original GUI event "
1275+
"handler is unsafe and deprecated since %(since)s; in the future, the "
1276+
"attribute will be set to None after quitting the event handler. You "
1277+
"may separately record the value of the guiEvent attribute at your own "
1278+
"risk.")
1279+
return self._guiEvent
12651280

12661281

12671282
class DrawEvent(Event):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.