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

Skip to content

Commit d8318df

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 a76e037 commit d8318df

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
@@ -951,24 +951,13 @@ def _on_close(self, event):
951951
self.figmgr.frame = None
952952
# remove figure manager from Gcf.figs
953953
Gcf.destroy(self.figmgr)
954+
try: # See issue 2941338.
955+
self.canvas.mpl_disconnect(self.toolbar._id_drag)
956+
except AttributeError: # If there's no toolbar.
957+
pass
954958
# Carry on with close event propagation, frame & children destruction
955959
event.Skip()
956960

957-
def Destroy(self, *args, **kwargs):
958-
try:
959-
self.canvas.mpl_disconnect(self.toolbar._id_drag)
960-
# Rationale for line above: see issue 2941338.
961-
except AttributeError:
962-
pass # classic toolbar lacks the attribute
963-
# The "if self" check avoids a "wrapped C/C++ object has been deleted"
964-
# RuntimeError at exit with e.g.
965-
# MPLBACKEND=wxagg python -c 'from pylab import *; plot()'.
966-
if self and not self.IsBeingDeleted():
967-
super().Destroy(*args, **kwargs)
968-
# self.toolbar.Destroy() should not be necessary if the close event
969-
# is allowed to propagate.
970-
return True
971-
972961

973962
class FigureManagerWx(FigureManagerBase):
974963
"""

0 commit comments

Comments
 (0)