@@ -261,43 +261,49 @@ def enterEvent(self, event):
261261 # Force querying of the modifiers, as the cached modifier state can
262262 # have been invalidated while the window was out of focus.
263263 mods = QtWidgets .QApplication .instance ().queryKeyboardModifiers ()
264+ if self .figure is None :
265+ return
264266 LocationEvent ("figure_enter_event" , self ,
265267 * self .mouseEventCoords (event ),
266268 modifiers = self ._mpl_modifiers (mods ),
267269 guiEvent = event )._process ()
268270
269271 def leaveEvent (self , event ):
270272 QtWidgets .QApplication .restoreOverrideCursor ()
273+ if self .figure is None :
274+ return
271275 LocationEvent ("figure_leave_event" , self ,
272276 * self .mouseEventCoords (),
273277 modifiers = self ._mpl_modifiers (),
274278 guiEvent = event )._process ()
275279
276280 def mousePressEvent (self , event ):
277281 button = self .buttond .get (event .button ())
278- if button is not None :
282+ if button is not None and self . figure is not None :
279283 MouseEvent ("button_press_event" , self ,
280284 * self .mouseEventCoords (event ), button ,
281285 modifiers = self ._mpl_modifiers (),
282286 guiEvent = event )._process ()
283287
284288 def mouseDoubleClickEvent (self , event ):
285289 button = self .buttond .get (event .button ())
286- if button is not None :
290+ if button is not None and self . figure is not None :
287291 MouseEvent ("button_press_event" , self ,
288292 * self .mouseEventCoords (event ), button , dblclick = True ,
289293 modifiers = self ._mpl_modifiers (),
290294 guiEvent = event )._process ()
291295
292296 def mouseMoveEvent (self , event ):
297+ if self .figure is None :
298+ return
293299 MouseEvent ("motion_notify_event" , self ,
294300 * self .mouseEventCoords (event ),
295301 modifiers = self ._mpl_modifiers (),
296302 guiEvent = event )._process ()
297303
298304 def mouseReleaseEvent (self , event ):
299305 button = self .buttond .get (event .button ())
300- if button is not None :
306+ if button is not None and self . figure is not None :
301307 MouseEvent ("button_release_event" , self ,
302308 * self .mouseEventCoords (event ), button ,
303309 modifiers = self ._mpl_modifiers (),
@@ -311,29 +317,31 @@ def wheelEvent(self, event):
311317 steps = event .angleDelta ().y () / 120
312318 else :
313319 steps = event .pixelDelta ().y ()
314- if steps :
320+ if steps and self . figure is not None :
315321 MouseEvent ("scroll_event" , self ,
316322 * self .mouseEventCoords (event ), step = steps ,
317323 modifiers = self ._mpl_modifiers (),
318324 guiEvent = event )._process ()
319325
320326 def keyPressEvent (self , event ):
321327 key = self ._get_key (event )
322- if key is not None :
328+ if key is not None and self . figure is not None :
323329 KeyEvent ("key_press_event" , self ,
324330 key , * self .mouseEventCoords (),
325331 guiEvent = event )._process ()
326332
327333 def keyReleaseEvent (self , event ):
328334 key = self ._get_key (event )
329- if key is not None :
335+ if key is not None and self . figure is not None :
330336 KeyEvent ("key_release_event" , self ,
331337 key , * self .mouseEventCoords (),
332338 guiEvent = event )._process ()
333339
334340 def resizeEvent (self , event ):
335341 if self ._in_resize_event : # Prevent PyQt6 recursion
336342 return
343+ if self .figure is None :
344+ return
337345 self ._in_resize_event = True
338346 try :
339347 w = event .size ().width () * self .device_pixel_ratio
0 commit comments