Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a36985

Browse files
committed
Simplify wxframe deletion.
Instead of reimplementing Destroy and fiddling around with supercalls and IsBeingDeleted, move the toolbar disconnection to the _on_close handler (which anyways already unregisters the figure from Gcf, so it's definitely going to destroy the figure) and inherit Destroy from the base class.
1 parent 67e69e9 commit 0a36985

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -937,24 +937,13 @@ def _on_close(self, event):
937937
self.figmgr.frame = None
938938
# remove figure manager from Gcf.figs
939939
Gcf.destroy(self.figmgr)
940+
try: # See issue 2941338.
941+
self.canvas.mpl_disconnect(self.canvas.toolbar._id_drag)
942+
except AttributeError: # If there's no toolbar.
943+
pass
940944
# Carry on with close event propagation, frame & children destruction
941945
event.Skip()
942946

943-
def Destroy(self, *args, **kwargs):
944-
try:
945-
self.canvas.mpl_disconnect(self.canvas.manager.toolbar._id_drag)
946-
# Rationale for line above: see issue 2941338.
947-
except AttributeError:
948-
pass # classic toolbar lacks the attribute
949-
# The "if self" check avoids a "wrapped C/C++ object has been deleted"
950-
# RuntimeError at exit with e.g.
951-
# MPLBACKEND=wxagg python -c 'from pylab import *; plot()'.
952-
if self and not self.IsBeingDeleted():
953-
super().Destroy(*args, **kwargs)
954-
# toolbar.Destroy() should not be necessary if the close event is
955-
# allowed to propagate.
956-
return True
957-
958947

959948
class FigureManagerWx(FigureManagerBase):
960949
"""

0 commit comments

Comments
 (0)