File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -476,7 +476,8 @@ def draw_idle(self):
476476 # current event loop in order to ensure thread affinity and to
477477 # accumulate multiple draw requests from event handling.
478478 # TODO: queued signal connection might be safer than singleShot
479- if not (self ._draw_pending or self ._is_drawing ):
479+ if not (getattr (self , '_draw_pending' , False ) or
480+ getattr (self , '._is_drawing' , False )):
480481 self ._draw_pending = True
481482 QtCore .QTimer .singleShot (0 , self ._draw_idle )
482483
Original file line number Diff line number Diff line change @@ -293,3 +293,23 @@ def test_double_resize():
293293 fig .set_size_inches (w , h )
294294 assert window .width () == old_width
295295 assert window .height () == old_height
296+
297+
298+ @pytest .mark .backend ("Qt5Agg" )
299+ def test_canvas_reinit ():
300+ import matplotlib .pyplot as plt
301+ from matplotlib .backends .backend_qt5agg import FigureCanvasQTAgg
302+ from functools import partial
303+
304+ called = False
305+
306+ def crashing_callback (fig , stale ):
307+ nonlocal called
308+ fig .canvas .draw_idle ()
309+ called = True
310+
311+ fig , ax = plt .subplots ()
312+ fig .stale_callback = crashing_callback
313+ # this should not raise
314+ canvas = FigureCanvasQTAgg (fig )
315+ assert called
You can’t perform that action at this time.
0 commit comments