File tree 2 files changed +22
-2
lines changed
doc/api/next_api_changes/deprecations
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change @@ -1257,11 +1257,26 @@ class Event:
1257
1257
def __init__ (self , name , canvas , guiEvent = None ):
1258
1258
self .name = name
1259
1259
self .canvas = canvas
1260
- self .guiEvent = guiEvent
1260
+ self ._guiEvent = guiEvent
1261
+ self ._guiEvent_deleted = False
1261
1262
1262
1263
def _process (self ):
1263
- """Generate an event with name ``self.name`` on ``self.canvas ``."""
1264
+ """Process this event on ``self.canvas``, then unset ``guiEvent ``."""
1264
1265
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
1265
1280
1266
1281
1267
1282
class DrawEvent (Event ):
You can’t perform that action at this time.
0 commit comments