Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bce6263

Browse filesBrowse files
committed
Add test for close_event.
Test that a single close_event is triggered when a window is closed. This caught a bug in the gtk3 backends, which used to emit *two* close_events (see comment there; a better fix would be welcome); and another in the wx backends (which emit *no* close_events when the window is closed by pressing "q" -- now fixed).
1 parent 54b4263 commit bce6263
Copy full SHA for bce6263

File tree

Expand file treeCollapse file tree

3 files changed

+17
-5
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-5
lines changed

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def add_widget(child):
367367

368368
self.window.set_default_size(w, h)
369369

370+
self._destroying = False
370371
self.window.connect("destroy", lambda *args: Gcf.destroy(self))
371372
self.window.connect("delete_event", lambda *args: Gcf.destroy(self))
372373
if mpl.is_interactive():
@@ -376,6 +377,13 @@ def add_widget(child):
376377
self.canvas.grab_focus()
377378

378379
def destroy(self, *args):
380+
if self._destroying:
381+
# Otherwise, this can be called twice when the user presses 'q',
382+
# which calls Gcf.destroy(self), then this destroy(), then triggers
383+
# Gcf.destroy(self) once again via
384+
# `connect("destroy", lambda *args: Gcf.destroy(self))`.
385+
return
386+
self._destroying = True
379387
self.vbox.destroy()
380388
self.window.destroy()
381389
self.canvas.destroy()

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@ def _onClose(self, event):
10081008
self.canvas.close_event()
10091009
self.canvas.stop_event_loop()
10101010
Gcf.destroy(self)
1011-
# self.Destroy()
1011+
if self:
1012+
self.Destroy()
10121013

10131014
def GetToolBar(self):
10141015
"""Override wxFrame::GetToolBar as we don't have managed toolbar"""
@@ -1066,7 +1067,7 @@ def show(self):
10661067

10671068
def destroy(self, *args):
10681069
_log.debug("%s - destroy()", type(self))
1069-
self.frame.Destroy()
1070+
self.frame.Close()
10701071
wxapp = wx.GetApp()
10711072
if wxapp:
10721073
wxapp.Yield()

‎lib/matplotlib/tests/test_backends_interactive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backends_interactive.py
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def check_alt_backend(alt_backend):
111111
timer.add_callback(FigureCanvasBase.key_press_event, fig.canvas, "q")
112112
# Trigger quitting upon draw.
113113
fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
114+
fig.canvas.mpl_connect("close_event", print)
114115
115116
plt.show()
116117
"""
@@ -120,12 +121,14 @@ def check_alt_backend(alt_backend):
120121
@pytest.mark.parametrize("backend", _get_testable_interactive_backends())
121122
@pytest.mark.flaky(reruns=3)
122123
def test_interactive_backend(backend):
123-
proc = subprocess.run([sys.executable, "-c", _test_script],
124-
env={**os.environ, "MPLBACKEND": backend},
125-
timeout=_test_timeout)
124+
proc = subprocess.run(
125+
[sys.executable, "-c", _test_script],
126+
env={**os.environ, "MPLBACKEND": backend}, timeout=_test_timeout,
127+
stdout=subprocess.PIPE, universal_newlines=True)
126128
if proc.returncode:
127129
pytest.fail("The subprocess returned with non-zero exit status "
128130
f"{proc.returncode}.")
131+
assert proc.stdout.count("CloseEvent") == 1
129132

130133

131134
@pytest.mark.skipif('SYSTEM_TEAMFOUNDATIONCOLLECTIONURI' in os.environ,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.