Skip to content

Commit a5b58c2

Browse files
committed
Make guiEvent available only within the event handlers.
1 parent 7baa2b8 commit a5b58c2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines 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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,11 +1257,25 @@ 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; in the future, the attribute will "
1276+
"be set to None after quitting the event handler. You may separately "
1277+
"record the value of the guiEvent attribute at your own risk.")
1278+
return self._guiEvent
12651279

12661280

12671281
class DrawEvent(Event):

0 commit comments

Comments
 (0)