8000 Merge pull request #15206 from tacaswell/fix_python_ion_second_qtcanv… · matplotlib/matplotlib@5700347 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5700347

Browse files
authored
Merge pull request #15206 from tacaswell/fix_python_ion_second_qtcanvas_init
FIX: be more forgiving about expecting internal state in draw_idle
2 parents da5c232 + b9aed24 commit 5700347

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
@@ -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

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
391D canvas = FigureCanvasQTAgg(fig)
315+
assert called

0 commit comments

Comments
 (0)
0