Skip to content

Commit b45f2ab

Browse files
committed
[2841525] wx backend: fix classic toolbar; Figure.clf: add kwarg to keep axobservers
svn path=/trunk/matplotlib/; revision=8390
1 parent d29f257 commit b45f2ab

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ def Printer_Setup(self, event=None):
861861
simply asks for image width and margin for printing. """
862862

863863
dmsg = """Width of output figure in inches.
864-
The current aspect ration will be kept."""
864+
The current aspect ratio will be kept."""
865865

866866
dlg = wx.Dialog(self, -1, 'Page Setup for Printing' , (-1,-1))
867867
df = dlg.GetFont()
@@ -1546,8 +1546,11 @@ def GetToolBar(self):
15461546
return self.toolbar
15471547

15481548
def Destroy(self, *args, **kwargs):
1549-
self.canvas.mpl_disconnect(self.toolbar._idDrag)
1550-
# Rationale for line above: see issue 2941338.
1549+
try:
1550+
self.canvas.mpl_disconnect(self.toolbar._idDrag)
1551+
# Rationale for line above: see issue 2941338.
1552+
except AttributeError:
1553+
pass # classic toolbar lacks the attribute
15511554
wx.Frame.Destroy(self, *args, **kwargs)
15521555
if self.toolbar is not None:
15531556
self.toolbar.Destroy()
@@ -1707,6 +1710,8 @@ def _onMenuItemSelected(self, evt):
17071710
else:
17081711
new = True
17091712
self._menu.Check(evt.GetId(), new)
1713+
# Lines above would be deleted based on svn tracker ID 2841525;
1714+
# not clear whether this matters or not.
17101715
self._toolbar.set_active(self.getActiveAxes())
17111716
evt.Skip()
17121717

@@ -1720,7 +1725,11 @@ def updateAxes(self, maxAxis):
17201725
self._menu.Append(menuId, "Axis %d" % i, "Select axis %d" % i, True)
17211726
self._menu.Check(menuId, True)
17221727
bind(self, wx.EVT_MENU, self._onMenuItemSelected, id=menuId)
1723-
self._toolbar.set_active(range(len(self._axisId)))
1728+
elif maxAxis < len(self._axisId):
1729+
for menuId in self._axisId[maxAxis:]:
1730+
self._menu.Delete(menuId)
1731+
self._axisId = self._axisId[:maxAxis]
1732+
self._toolbar.set_active(range(maxAxis))
17241733

17251734
def getActiveAxes(self):
17261735
"""Return a list of the selected axes."""
@@ -2080,7 +2089,8 @@ def zoomy(self, in_out):
20802089

20812090
def update(self):
20822091
"""
2083-
Update the toolbar menu - called when (e.g.) a new subplot or axes are added
2092+
Update the toolbar menu - called when (e.g.) a new subplot
2093+
or axes are added
20842094
"""
20852095
DEBUG_MSG("update()", 1, self)
20862096
self._axes = self.canvas.figure.get_axes()

lib/matplotlib/figure.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,12 @@ def add_subplot(self, *args, **kwargs):
691691
self.sca(a)
692692
return a
693693

694-
def clf(self):
694+
def clf(self, keep_observers=False):
695695
"""
696-
Clear the figure
696+
Clear the figure.
697+
698+
Set *keep_observers* to True if, for example,
699+
a gui widget is tracking the axes in the figure.
697700
"""
698701
self.suppressComposite = None
699702
self.callbacks = cbook.CallbackRegistry(('dpi_changed', ))
@@ -713,7 +716,8 @@ def clf(self):
713716
self.texts=[]
714717
self.images = []
715718
self.legends = []
716-
self._axobservers = []
719+
if not keep_observers:
720+
self._axobservers = []
717721

718722
def clear(self):
719723
"""

0 commit comments

Comments
 (0)