mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-10 13:57:08 +01:00
Merge pull request #1441 from wxWidgets/fix-issue1428-plotcanvas
Fix scrollbars and scrolling in plotcanvas
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
@@ -1852,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.
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user