From 5b91b8443e24d072c6e4ad8acfb32c339fe6b5e5 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 13 Nov 2019 11:30:22 -0800 Subject: [PATCH 1/4] Decouple showScrollbars property from the actual showing/hiding of the scrollbar widgets. Instead it indicates whether the scrollbars are allowed to be shown if _adjustScrollbars() determines that they are needed. Also fix issues with calculating scrolled view positions when scrolling with the scrollbars. --- wx/lib/plot/plotcanvas.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/wx/lib/plot/plotcanvas.py b/wx/lib/plot/plotcanvas.py index 12eaa0a0..dec91d83 100644 --- a/wx/lib/plot/plotcanvas.py +++ b/wx/lib/plot/plotcanvas.py @@ -101,6 +101,7 @@ class PlotCanvas(wx.Panel): # scrollbar variables self._sb_ignore = False + self._sb_show = False self._adjustingSB = False self._sb_xfullrange = 0 self._sb_yfullrange = 0 @@ -690,19 +691,23 @@ class PlotCanvas(wx.Panel): :type: bool :raises: `TypeError` if setting a non-boolean value. """ - # XXX: should have sb_hor.IsShown() as well. - return self.sb_vert.IsShown() + return self._sb_show @showScrollbars.setter def showScrollbars(self, value): if not isinstance(value, bool): raise TypeError("Value should be True or False") - if value == self.showScrollbars: + if value == self._sb_show: # no change, so don't do anything return + self._sb_show = value self.sb_vert.Show(value) self.sb_hor.Show(value) - wx.CallAfter(self.Layout) + + def _do_update(): + self.Layout() + self._adjustScrollbars() + wx.CallAfter(_do_update) def SetUseScientificNotation(self, useScientificNotation): """ @@ -2180,11 +2185,11 @@ class PlotCanvas(wx.Panel): sbpos = evt.GetPosition() if evt.GetOrientation() == wx.VERTICAL: - fullrange, pagesize = self.sb_vert.GetRange( - ), self.sb_vert.GetPageSize() + fullrange = self.sb_vert.GetRange() + pagesize = self.sb_vert.GetPageSize() sbpos = fullrange - pagesize - sbpos - dist = (sbpos * self._sb_xunit - - (self._getXCurrentRange()[0] - self._sb_xfullrange)) + dist = (sbpos * self._sb_yunit - + (self._getYCurrentRange()[0] - self._sb_yfullrange[0])) self.ScrollUp(dist) if evt.GetOrientation() == wx.HORIZONTAL: @@ -2909,6 +2914,7 @@ class PlotCanvas(wx.Panel): _multiples = [(2., np.log10(2.)), (5., np.log10(5.))] + def _adjustScrollbars(self): if self._sb_ignore: self._sb_ignore = False @@ -2964,5 +2970,6 @@ class PlotCanvas(wx.Panel): else: self.sb_vert.SetScrollbar(0, 1000, 1000, 1000) - self.SetShowScrollbars(needScrollbars) + self.sb_hor.Show(needScrollbars) + self.sb_vert.Show(needScrollbars) self._adjustingSB = False From 8f5bfd6484a689b682257f9b3a710b2eb8f335bc Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 13 Nov 2019 12:00:52 -0800 Subject: [PATCH 2/4] Add option to the plot demo for toggling the scrollbars --- wx/lib/plot/examples/demo.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/wx/lib/plot/examples/demo.py b/wx/lib/plot/examples/demo.py index eac498b0..98fbaad3 100644 --- a/wx/lib/plot/examples/demo.py +++ b/wx/lib/plot/examples/demo.py @@ -339,6 +339,8 @@ class PlotDemoMainFrame(wx.Frame): # Show closest point when enabled self.client.canvas.Bind(wx.EVT_MOTION, self.OnMotion) + self.OnPlotDraw1(None) + wx.CallAfter(wx.MessageBox, "Various plot types can be shown using the Plot menu. " + "Check out the Options menu too.", @@ -427,6 +429,10 @@ class PlotDemoMainFrame(wx.Frame): 'Activates dragging mode', kind=wx.ITEM_CHECK) self.Bind(wx.EVT_MENU, self.OnEnableDrag, id=217) + item = menu.Append(-1, 'Enable &Scrollbars (if needed)', + 'Enable Scrollbars (if needed)', kind=wx.ITEM_CHECK) + self.Bind(wx.EVT_MENU, self.OnEnableScrollbars, item) + menu.Append(222, 'Enable &Point Label', 'Show Closest Point', kind=wx.ITEM_CHECK) self.Bind(wx.EVT_MENU, self.OnEnablePointLabel, id=222) @@ -468,7 +474,7 @@ class PlotDemoMainFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.OnEnableGridY, id=2152) self.Bind(wx.EVT_MENU, self.OnEnableGridAll, id=2153) - menu.Append(215, 'Enable Grid', submenu, 'Turn on Grid') + menu.AppendSubMenu(submenu, 'Enable Grid', 'Turn on Grid') ### SubMenu for Axes submenu = wx.Menu() @@ -486,8 +492,7 @@ class PlotDemoMainFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.OnEnableAxesBottomLeft, id=2405) self.Bind(wx.EVT_MENU, self.OnEnableAxesAll, id=2406) - menu.Append(240, 'Enable Axes', submenu, - 'Enables the display of the Axes') + menu.AppendSubMenu(submenu, 'Enable Axes', 'Enables the display of the Axes') submenu = wx.Menu() submenu_items = ("Bottom", "Left", "Top", "Right") @@ -506,8 +511,7 @@ class PlotDemoMainFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.OnEnableAxesValuesTop, id=2453) self.Bind(wx.EVT_MENU, self.OnEnableAxesValuesRight, id=2454) - menu.Append(245, 'Enable Axes Values', submenu, - 'Enables the display of the axes values') + menu.AppendSubMenu(submenu, 'Enable Axes Values', 'Enables the display of the axes values') submenu = wx.Menu() submenu_items = ("Bottom", "Left", "Top", "Right", @@ -529,8 +533,7 @@ class PlotDemoMainFrame(wx.Frame): self.Bind(wx.EVT_MENU, self.OnEnableTicksBottomLeft, id=2505) self.Bind(wx.EVT_MENU, self.OnEnableTicksAll, id=2506) - menu.Append(250, 'Enable Ticks', submenu, - 'Enables the display of the ticks') + menu.AppendSubMenu(submenu, 'Enable Ticks','Enables the display of the ticks') menu.Append(255, 'Enable Plot Title', 'Enables the plot title', kind=wx.ITEM_CHECK) @@ -907,6 +910,9 @@ class PlotDemoMainFrame(wx.Frame): if self.mainmenu.IsChecked(214): self.mainmenu.Check(214, False) + def OnEnableScrollbars(self, event): + self.client.showScrollbars = event.IsChecked() + def OnEnableLegend(self, event): self.client.enableLegend = event.IsChecked() From 171df70a437a6efde10723baea0f5800fe6bdeee Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 14 Nov 2019 12:22:45 -0800 Subject: [PATCH 3/4] Fix SyntaxWarnings --- wx/lib/plot/plotcanvas.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wx/lib/plot/plotcanvas.py b/wx/lib/plot/plotcanvas.py index dec91d83..dd3f77d5 100644 --- a/wx/lib/plot/plotcanvas.py +++ b/wx/lib/plot/plotcanvas.py @@ -1857,12 +1857,12 @@ class PlotCanvas(wx.Panel): # Get ticks and textExtents for axis if required xticks = yticks = None xTextExtent = yTextExtent = (0, 0) # No text for ticks - if self._xSpec is not 'none': + if self._xSpec != 'none': xticks = self._xticks(xAxis[0], xAxis[1]) # w h of x axis text last number on axis xTextExtent = dc.GetTextExtent(xticks[-1][1]) - if self._ySpec is not 'none': + if self._ySpec != 'none': yticks = self._yticks(yAxis[0], yAxis[1]) if self.logScale[1]: # make sure we have enough room to display SI notation. From f0ea4640d2147edc58153e8a8bcf2bc38d39aa82 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 14 Nov 2019 12:24:40 -0800 Subject: [PATCH 4/4] Changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index fa8481f1..8f186a9e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -83,6 +83,8 @@ New and improved in this release: * Added wrappers for the wx.CollapsibleHeaderCtrl class. +* Fixed issues in PlotCanvas around displaying and using scrollbars. (#1428) +