@@ -261,43 +261,49 @@ def enterEvent(self, event):
261
261
# Force querying of the modifiers, as the cached modifier state can
262
262
# have been invalidated while the window was out of focus.
263
263
mods = QtWidgets .QApplication .instance ().queryKeyboardModifiers ()
264
+ if self .figure is None :
265
+ return
264
266
LocationEvent ("figure_enter_event" , self ,
265
267
* self .mouseEventCoords (event ),
266
268
modifiers = self ._mpl_modifiers (mods ),
267
269
guiEvent = event )._process ()
268
270
269
271
def leaveEvent (self , event ):
270
272
QtWidgets .QApplication .restoreOverrideCursor ()
273
+ if self .figure is None :
274
+ return
271
275
LocationEvent ("figure_leave_event" , self ,
272
276
* self .mouseEventCoords (),
273
277
modifiers = self ._mpl_modifiers (),
274
278
guiEvent = event )._process ()
275
279
276
280
def mousePressEvent (self , event ):
277
281
button = self .buttond .get (event .button ())
278
- if button is not None :
282
+ if button is not None and self . figure is not None :
279
283
MouseEvent ("button_press_event" , self ,
280
284
* self .mouseEventCoords (event ), button ,
281
285
modifiers = self ._mpl_modifiers (),
282
286
guiEvent = event )._process ()
283
287
284
288
def mouseDoubleClickEvent (self , event ):
285
289
button = self .buttond .get (event .button ())
286
- if button is not None :
290
+ if button is not None and self . figure is not None :
287
291
MouseEvent ("button_press_event" , self ,
288
292
* self .mouseEventCoords (event ), button , dblclick = True ,
289
293
modifiers = self ._mpl_modifiers (),
290
294
guiEvent = event )._process ()
291
295
292
296
def mouseMoveEvent (self , event ):
297
+ if self .figure is None :
298
+ return
293
299
MouseEvent ("motion_notify_event" , self ,
294
300
* self .mouseEventCoords (event ),
295
301
modifiers = self ._mpl_modifiers (),
296
302
guiEvent = event )._process ()
297
303
298
304
def mouseReleaseEvent (self , event ):
299
305
button = self .buttond .get (event .button ())
300
- if button is not None :
306
+ if button is not None and self . figure is not None :
301
307
MouseEvent ("button_release_event" , self ,
302
308
* self .mouseEventCoords (event ), button ,
303
309
modifiers = self ._mpl_modifiers (),
@@ -311,29 +317,31 @@ def wheelEvent(self, event):
311
317
steps = event .angleDelta ().y () / 120
312
318
else :
313
319
steps = event .pixelDelta ().y ()
314
- if steps :
320
+ if steps and self . figure is not None :
315
321
MouseEvent ("scroll_event" , self ,
316
322
* self .mouseEventCoords (event ), step = steps ,
317
323
modifiers = self ._mpl_modifiers (),
318
324
guiEvent = event )._process ()
319
325
320
326
def keyPressEvent (self , event ):
321
327
key = self ._get_key (event )
322
- if key is not None :
328
+ if key is not None and self . figure is not None :
323
329
KeyEvent ("key_press_event" , self ,
324
330
key , * self .mouseEventCoords (),
325
331
guiEvent = event )._process ()
326
332
327
333
def keyReleaseEvent (self , event ):
328
334
key = self ._get_key (event )
329
- if key is not None :
335
+ if key is not None and self . figure is not None :
330
336
KeyEvent ("key_release_event" , self ,
331
337
key , * self .mouseEventCoords (),
332
338
guiEvent = event )._process ()
333
339
334
340
def resizeEvent (self , event ):
335
341
if self ._in_resize_event : # Prevent PyQt6 recursion
336
342
return
343
+ if self .figure is None :
344
+ return
337
345
self ._in_resize_event = True
338
346
try :
339
347
w = event .size ().width () * self .device_pixel_ratio
0 commit comments