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

Skip to content

Commit b65d1e7

Browse files
committed
wx: Fix saving after window is closed.
We don't need to run `gui_repaint` if the window is gone, so just skip it.
1 parent 2acbdd0 commit b65d1e7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,9 @@ def gui_repaint(self, drawDC=None, origin='WX'):
623623
The 'WXAgg' backend sets origin accordingly.
624624
"""
625625
_log.debug("%s - gui_repaint()", type(self))
626-
if self.IsShownOnScreen():
626+
# The "if self" check avoids a "wrapped C/C++ object has been deleted"
627+
# RuntimeError if doing things after window is closed.
628+
if self and self.IsShownOnScreen():
627629
if not drawDC:
628630
# not called from OnPaint use a ClientDC
629631
drawDC = wx.ClientDC(self)
@@ -900,7 +902,10 @@ def _print_image(self, filename, filetype, *args, **kwargs):
900902
# otherwise.
901903
if self._isDrawn:
902904
self.draw()
903-
self.Refresh()
905+
# The "if self" check avoids a "wrapped C/C++ object has been deleted"
906+
# RuntimeError if doing things after window is closed.
907+
if self:
908+
self.Refresh()
904909

905910

906911
class FigureFrameWx(wx.Frame):

0 commit comments

Comments
 (0)