File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -492,7 +492,8 @@ def draw_idle(self):
492492 # current event loop in order to ensure thread affinity and to
493493 # accumulate multiple draw requests from event handling.
494494 # TODO: queued signal connection might be safer than singleShot
495- if not (self ._draw_pending or self ._is_drawing ):
495+ if not (getattr (self , '_draw_pending' , False ) or
496+ getattr (self , '._is_drawing' , False )):
496497 self ._draw_pending = True
497498 QtCore .QTimer .singleShot (0 , self ._draw_idle )
498499
Original file line number Diff line number Diff line change @@ -307,3 +307,23 @@ def test_figureoptions():
307307 "matplotlib.backends.qt_editor._formlayout.FormDialog.exec_" ,
308308 lambda self : None ):
309309 fig .canvas .manager .toolbar .edit_parameters ()
310+
311+
312+ @pytest .mark .backend ("Qt5Agg" )
313+ def test_canvas_reinit ():
314+ import matplotlib .pyplot as plt
315+ from matplotlib .backends .backend_qt5agg import FigureCanvasQTAgg
316+ from functools import partial
317+
318+ called = False
319+
320+ def crashing_callback (fig , stale ):
321+ nonlocal called
322+ fig .canvas .draw_idle ()
323+ called = True
324+
325+ fig , ax = plt .subplots ()
326+ fig .stale_callback = crashing_callback
327+ # this should not raise
328+ canvas = FigureCanvasQTAgg (fig )
329+ assert called
You can’t perform that action at this time.
0 commit comments