From 16bed7e7f1ee912dbd2f47ec26537a40558ac943 Mon Sep 17 00:00:00 2001 From: wernerfb Date: Wed, 8 Apr 2015 17:09:38 +0200 Subject: [PATCH 1/2] add some tests --- unittests/test_lib_splitter.py | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 unittests/test_lib_splitter.py diff --git a/unittests/test_lib_splitter.py b/unittests/test_lib_splitter.py new file mode 100644 index 00000000..d2d17f55 --- /dev/null +++ b/unittests/test_lib_splitter.py @@ -0,0 +1,35 @@ +import imp_unittest, unittest +import wtc +import wx +import wx.lib.splitter as sp + +#--------------------------------------------------------------------------- + +class splitter_Tests(wtc.WidgetTestCase): + + def test_splitterCtor(self): + splitter = sp.MultiSplitterWindow(self.frame, style=wx.SP_LIVE_UPDATE) + + def test_splitterMulti(self): + splitter = sp.MultiSplitterWindow(self.frame, style=wx.SP_LIVE_UPDATE) + + p = wx.Panel(self.frame) + splitter.AppendWindow(p, 140) + + p = wx.Panel(self.frame) + splitter.AppendWindow(p, 160) + + p = wx.Panel(self.frame) + splitter.AppendWindow(p, 180) + + splitter.SetOrientation(wx.VERTICAL) + self.assertEqual(splitter.GetOrientation(), wx.VERTICAL) + + splitter.SetOrientation(wx.HORIZONTAL) + self.assertEqual(splitter.GetOrientation(), wx.HORIZONTAL) + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() From 0f98f444f6187ad96af3e50a2daa38b7812092fd Mon Sep 17 00:00:00 2001 From: wernerfb Date: Wed, 8 Apr 2015 17:10:37 +0200 Subject: [PATCH 2/2] documentation --- wx/lib/splitter.py | 155 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 146 insertions(+), 9 deletions(-) diff --git a/wx/lib/splitter.py b/wx/lib/splitter.py index 09fbb1e6..765592d2 100644 --- a/wx/lib/splitter.py +++ b/wx/lib/splitter.py @@ -8,7 +8,7 @@ # Created: 9-June-2005 # Copyright: (c) 2005 by Total Control Software # Licence: wxWindows license -# Tags: phoenix-port +# Tags: phoenix-port, unittest, documentation, py3-port #---------------------------------------------------------------------- """ This module provides the `MultiSplitterWindow` class, which is very @@ -57,6 +57,18 @@ class MultiSplitterWindow(wx.Panel): def __init__(self, parent, id=-1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = 0, name="multiSplitter"): + """ + Default class constructor. + + :param Window `parent`: the parent window + :param integer `id`: an identifier for the control: a value of -1 is taken to mean a default + :param Point `pos`: the control position. A value of (-1, -1) indicates a default position, + chosen by either the windowing system or wxPython, depending on platform + :param Size `size`: the control size. A value of (-1, -1) indicates a default size, + chosen by either the windowing system or wxPython, depending on platform + :param integer `style`: the control window style + :param string `name`: the control name + """ # always turn on tab traversal style |= wx.TAB_TRAVERSAL @@ -100,6 +112,8 @@ class MultiSplitterWindow(wx.Panel): Set whether the windows managed by the splitter will be stacked vertically or horizontally. The default is horizontal. + + :param `orient`: either ``wx.VERTICAL`` or ``wx.HORIZONTAL`` """ assert orient in [ wx.VERTICAL, wx.HORIZONTAL ] self._orient = orient @@ -107,11 +121,17 @@ class MultiSplitterWindow(wx.Panel): def GetOrientation(self): """ Returns the current orientation of the splitter, either - wx.VERTICAL or wx.HORIZONTAL. + ``wx.VERTICAL`` or ``wx.HORIZONTAL``. """ return self._orient def SetBackgroundColour(self,color): + """ + Sets the back ground colour. + + :param Colour `color`: the colour to use. + + """ wx.Panel.SetBackgroundColour(self,color) self._drawSashInBackgroundColour = True if wx.NullColour == color: @@ -122,6 +142,9 @@ class MultiSplitterWindow(wx.Panel): """ Set the smallest size that any pane will be allowed to be resized to. + + :param int `minSize`: the minimum size of pane + """ self._minimumPaneSize = minSize @@ -136,16 +159,23 @@ class MultiSplitterWindow(wx.Panel): def AppendWindow(self, window, sashPos=-1): """ Add a new window to the splitter at the right side or bottom - of the window stack. If sashPos is given then it is used to - size the new window. + of the window stack. + + :param `window`: the window to add to the splitter + :param `sashPos`: if given it is used to size the new window + """ self.InsertWindow(len(self._windows), window, sashPos) def InsertWindow(self, idx, window, sashPos=-1): """ - Insert a new window into the splitter at the position given in - ``idx``. + Insert a new window into the splitter. + + :param int `idx`: the position to insert the window at. + :param `window`: the window to add to the splitter + :param `sashPos`: if given it is used to size the new window + """ assert window not in self._windows, "A window can only be in the splitter once!" self._windows.insert(idx, window) @@ -163,6 +193,9 @@ class MultiSplitterWindow(wx.Panel): Removes the window from the stack of windows managed by the splitter. The window will still exist so you should `Hide` or `Destroy` it as needed. + + :param `window`: the window to be removed from the splitter + """ assert window in self._windows, "Unknown window!" idx = self._windows.index(window) @@ -176,6 +209,10 @@ class MultiSplitterWindow(wx.Panel): Replaces oldWindow (which is currently being managed by the splitter) with newWindow. The oldWindow window will still exist so you should `Hide` or `Destroy` it as needed. + + :param `oldWindow`: the window to be replace + :param `newWindow`: the window to replace the above window + """ assert oldWindow in self._windows, "Unknown window!" idx = self._windows.index(oldWindow) @@ -188,6 +225,10 @@ class MultiSplitterWindow(wx.Panel): def ExchangeWindows(self, window1, window2): """ Trade the positions in the splitter of the two windows. + + :param `window1`: the first window to switch position + :param `window2`: the second window to switch position + """ assert window1 in self._windows, "Unknown window!" assert window2 in self._windows, "Unknown window!" @@ -201,6 +242,9 @@ class MultiSplitterWindow(wx.Panel): def GetWindow(self, idx): """ Returns the idx'th window being managed by the splitter. + + :param int `idx`: get the window at the given index + """ assert idx < len(self._windows) return self._windows[idx] @@ -210,6 +254,9 @@ class MultiSplitterWindow(wx.Panel): """ Returns the position of the idx'th sash, measured from the left/top of the window preceding the sash. + + :param int `idx`: get the sash position of the given index + """ assert idx < len(self._sashes) return self._sashes[idx] @@ -217,8 +264,12 @@ class MultiSplitterWindow(wx.Panel): def SetSashPosition(self, idx, pos): """ - Set the psition of the idx'th sash, measured from the left/top + Set the position of the idx'th sash, measured from the left/top of the window preceding the sash. + + :param int `idx`: set the sash position of the given index + :param int `pos`: the sash position + """ assert idx < len(self._sashes) self._sashes[idx] = pos @@ -386,9 +437,9 @@ class MultiSplitterWindow(wx.Panel): self._DrawSashTracker(self._oldX, self._oldY) if self._orient == wx.HORIZONTAL: - x = self._SashToCoord(self._activeSash, newPos1) + x = self._SashToCoord(self._activeSash, newPos1) else: - y = self._SashToCoord(self._activeSash, newPos1) + y = self._SashToCoord(self._activeSash, newPos1) # Remember old positions self._oldX = x @@ -752,6 +803,17 @@ class MultiSplitterEvent(wx.PyCommandEvent): `wx.SplitterEvent`. """ def __init__(self, type=wx.wxEVT_NULL, splitter=None): + """ + Constructor. + + Used internally by wxWidgets only. + + :param `eventType`: + :type `eventType`: EventType + :param `splitter`: + :type `splitter`: SplitterWindow + + """ wx.PyCommandEvent.__init__(self, type) if splitter: self.SetEventObject(splitter) @@ -761,23 +823,98 @@ class MultiSplitterEvent(wx.PyCommandEvent): self.isAllowed = True def SetSashIdx(self, idx): + """ + In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events, sets the + new sash index. + + In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGING`` events, sets the + new tracking bar position so visual feedback during dragging will + represent that change that will actually take place. Set to -1 from + the event handler code to prevent reindexing. + + May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING`` + and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events. + + :param int `pos`: New sash index. + + """ self.sashIdx = idx def SetSashPosition(self, pos): + """ + In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events, sets the + new sash position. + + In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGING`` events, sets the + new tracking bar position so visual feedback during dragging will + represent that change that will actually take place. Set to -1 from + the event handler code to prevent repositioning. + + May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING`` + and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events. + + :param int `pos`: New sash position. + + """ self.sashPos = pos def GetSashIdx(self): + """ + Returns the new sash index. + + May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING`` + and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events. + + :rtype: `int` + + """ return self.sashIdx def GetSashPosition(self): + """ + Returns the new sash position. + + May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING`` + and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events. + + :rtype: `int` + + """ return self.sashPos # methods from wx.NotifyEvent def Veto(self): + """ + Prevents the change announced by this event from happening. + + It is in general a good idea to notify the user about the reasons + for vetoing the change because otherwise the applications behaviour + (which just refuses to do what the user wants) might be quite + surprising. + + """ self.isAllowed = False + def Allow(self): + """ + This is the opposite of :meth:`Veto` : it explicitly allows the + event to be processed. + + For most events it is not necessary to call this method as the events + are allowed anyhow but some are forbidden by default (this will be + mentioned in the corresponding event description). + + """ self.isAllowed = True + def IsAllowed(self): + """ + Returns ``True`` if the change is allowed (:meth:`Veto` hasn't been + called) or ``False`` otherwise (if it was). + + :rtype: `bool` + + """ return self.isAllowed