dabo Commit
Revision 1595
Date: 2005-11-29 08:33:32 -0800 (Tue, 29 Nov 2005)
Author: paul
Changed:
U trunk/dabo/ui/uiwx/dSplitter.py
Log:
Noticed that the dSplitter test when testing all controls at once wasn't
allowing the sash to be moved. Turns out, it was because the default
panel size was set to 100, but the size of the test was less than that.
But, I took some time to rework some things with dSplitter as well:
+ Changed the right-click binding to a context menu binding, and used the
dabo showContextMenu() function instead of the wx PopupMenu() function.
+ Changed python keyword 'dir' to 'dir_', to be safe.
+ Moved the pane colorization from dSplitter into the test.
+ Moved setting of default property values *before* the point where they would
override user settings.
+ Calling evt.stop() on the sash dclick event wasn't stopping the sash from
disappearing, which I expected it to do. Vetoing the event seems to make this
work as expected.
+ Added code for Minimum panel size property to be settable in initProperties().
+ Expanded the test a bit to make it a larger size, to include the panel
colorization, and to prompt the user whether or not to remove the sash on a
double-click.
Diff:
Modified: trunk/dabo/ui/uiwx/dSplitter.py
===================================================================
--- trunk/dabo/ui/uiwx/dSplitter.py 2005-11-29 15:47:15 UTC (rev 1594)
+++ trunk/dabo/ui/uiwx/dSplitter.py 2005-11-29 16:33:32 UTC (rev 1595)
@@ -12,16 +12,15 @@
class SplitterPanel(dabo.ui.dPanel):
def __init__(self, parent):
super(SplitterPanel, self).__init__(parent)
- self.bindEvent(dEvents.MouseRightClick, self._onRClick)
+ self.bindEvent(dEvents.ContextMenu, self._onContextMenu)
- def _onRClick(self, evt):
+ def _onContextMenu(self, evt):
sm = dabo.ui.dMenu(self)
sm.append("Split this pane", bindfunc=self.onSplit)
if self.Parent.canRemove(self):
sm.append("Remove this pane", bindfunc=self.onRemove)
- pos = evt.EventData["mousePosition"]
- self.PopupMenu(sm, pos)
+ self.showContextMenu(sm)
def onSplit(self, evt):
@@ -36,7 +35,7 @@
self.Parent.remove(self)
- def split(self, dir=None):
+ def split(self, dir_=None):
if not self.Parent.IsSplit():
# Re-show the hidden split panel
self.Parent.split()
@@ -49,10 +48,10 @@
newDir = "h"
if self.Sizer is None:
self.Sizer = dabo.ui.dSizer(newDir)
- if dir is None:
- dir = newDir
+ if dir_ is None:
+ dir_ = newDir
win = dSplitter(self, createPanes=True)
- win.Orientation = dir
+ win.Orientation = dir_
win.unsplit()
win.split()
self.Sizer.append(win, 1, "expand")
@@ -75,8 +74,12 @@
style = self._extractKey(kwargs, "style", 0) | baseStyle
self._createPanes = self._extractKey(kwargs, "createPanes",
False)
self._splitOnInit = self._extractKey(kwargs, "splitOnInit",
True)
- self._colorizePanes = self._extractKey(kwargs, "colorizePanes",
True)
+ # Default to vertical split
+ self._orientation = "v"
+ self._sashPos = 100
+ self._minPanelSize = 0
+
preClass = wx.PreSplitterWindow
cm.dControlMixin.__init__(self, preClass, parent, properties,
style=style, *args, **kwargs)
@@ -87,23 +90,17 @@
def _afterInit(self):
- super(dSplitter, self)._afterInit()
self.__p1 = None
self.__p2 = None
# Create the panes
if self._createPanes:
self.__p1 = SplitterPanel(self)
self.__p2 = SplitterPanel(self)
- if self._colorizePanes:
- self.__p1.BackColor =
random.choice(dColors.colorDict.values())
- self.__p2.BackColor =
random.choice(dColors.colorDict.values())
- # Default to vertical split
- self._orientation = "v"
- self._sashPos = 100
- self.MinPanelSize = 100
if self._splitOnInit:
self.split()
+
+ super(dSplitter, self)._afterInit()
def initialize(self, p1):
@@ -111,24 +108,27 @@
def _onSashDClick(self, evt):
- """ Handle the doubl-clicking of the sash. This will call
+ """ Handle the double-clicking of the sash. This will call
the user-customizable onSashDClick() method.
"""
+ ## Vetoing the event now will give user code the opportunity to
not do the
+ ## default of removing the sash, by calling evt.stop().
+ evt.Veto()
# Update the internal sash position attribute.
self._getSashPosition()
# Raise a dEvent for other code to bind to,
self.raiseEvent(dEvents.SashDoubleClick, evt)
- def split(self, dir=None):
+ def split(self, dir_=None):
if self.IsSplit():
return
if self.Panel1 is None or self.Panel2 is None:
# No panels, so we can't split
return
- if dir:
- self.Orientation = dir
+ if dir_:
+ self.Orientation = dir_
# Since unsplitting hides the panes, make sure that they are
visible
self.Panel1.Visible = True
self.Panel2.Visible = True
@@ -177,7 +177,10 @@
return self.GetMinimumPaneSize()
def _setMinPanelSize(self, val):
- self.SetMinimumPaneSize(val)
+ if self._constructed():
+ self.SetMinimumPaneSize(val)
+ else:
+ self._properties["MinimumPanelSize"] = val
def _getOrientation(self):
@@ -233,7 +236,7 @@
self._sashPos = self.GetSashPosition()
- MinPanelSize = property(_getMinPanelSize, _setMinPanelSize, None,
+ MinimumPanelSize = property(_getMinPanelSize, _setMinPanelSize, None,
_("Controls the minimum width/height of the panels.
(int)"))
Orientation = property(_getOrientation, _setOrientation, None,
@@ -253,7 +256,21 @@
def __init__(self, *args, **kwargs):
kwargs["createPanes"] = True
super(_dSplitter_test, self).__init__(*args, **kwargs)
-
+
+ def initProperties(self):
+ self.Width = 250
+ self.Height = 200
+ self.MinimumPanelSize = 20
+
+ def afterInit(self):
+ self.Panel1.BackColor =
random.choice(dColors.colorDict.values())
+ self.Panel2.BackColor =
random.choice(dColors.colorDict.values())
+
+ def onSashDoubleClick(self, evt):
+ if not dabo.ui.areYouSure("Remove the sash?"):
+ evt.stop()
+
+
if __name__ == "__main__":
import test
test.Test().runTest(_dSplitter_test)
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev