8000 Backport PR #15206: FIX: be more forgiving about expecting internal s… · matplotlib/matplotlib@3ba761f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ba761f

Browse files
dstansbytacaswell
authored andcommitted
Backport PR #15206: FIX: be more forgiving about expecting internal state in draw_idle
Merge pull request #15206 from tacaswell/fix_python_ion_second_qtcanvas_init FIX: be more forgiving about expecting internal state in draw_idle Conflicts: lib/matplotlib/tests/test_backend_qt.py - two tests were added on master, only kept the relevant one
1 parent 39d4010 commit 3ba761f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)
0