Skip to content

Commit c60c60e

Browse files
committed
MNT: simplify close handler
1 parent ac06b2a commit c60c60e

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

mpl_gui/_promotion.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,17 @@ def promote_figure(fig, *, auto_draw=True, num):
7272

7373
# HACK: the callback in backend_bases uses GCF.destroy which misses these
7474
# figures by design!
75-
def _destroy(event):
75+
def _destroy_on_hotkey(event):
7676
if event.key in mpl.rcParams["keymap.quit"]:
7777
# grab the manager off the event
7878
mgr = event.canvas.manager
7979
if mgr is None:
80-
raise RuntimeError("Should never be here, please report a bug")
81-
fig = event.canvas.figure
82-
# remove this callback. Callbacks lives on the Figure so survive
83-
# the canvas being replaced.
84-
old_cid = getattr(mgr, "_destroy_cid", None)
85-
if old_cid is not None:
86-
fig.canvas.mpl_disconnect(old_cid)
87-
mgr._destroy_cid = None
80+
raise RuntimeError("Should never be here, please report a bug.")
8881
# close the window
8982
mgr.destroy()
9083

91-
manager._destroy_cid = fig.canvas.mpl_connect("key_press_event", _destroy)
84+
# remove this callback. Callbacks live on the Figure so survive the canvas
85+
# being replaced.
86+
fig.canvas.mpl_connect("key_press_event", _destroy_on_hotkey)
9287

9388
return manager

0 commit comments

Comments
 (0)