daboide Commit
Revision 574
Date: 2006-05-15 14:10:31 -0700 (Mon, 15 May 2006)
Author: ed
Changed:
U trunk/ClassDesigner.py
U trunk/ClassDesignerComponents.py
U trunk/ClassDesignerControlMixin.py
U trunk/ClassDesignerTreeSheet.py
Log:
Revamped context menus so that they should work equally well when
right-clicking on the object in the Object Tree as it does in the designer
surface.
Fixed a display bug for spacers in the tree.
Diff:
Modified: trunk/ClassDesigner.py
===================================================================
--- trunk/ClassDesigner.py 2006-05-15 17:30:56 UTC (rev 573)
+++ trunk/ClassDesigner.py 2006-05-15 21:10:31 UTC (rev 574)
@@ -62,8 +62,8 @@
# Create the clipboard
self._clipboard = None
# This holds a reference to the target object when
- # there is a context menu event on the tree.
- self._treeContextObj = None
+ # there is a context menu event.
+ self._contextObj = None
# When saving classes, we need to note when we are inside
# a class definition. The list is used as the class stack.
self._classStack = []
@@ -1557,46 +1557,31 @@
the appropriate context menu, or None if no context menu is
appropriate.
"""
- ret = dui.dMenu()
- self._treeContextObj = obj
- if isinstance(obj, dui.dSizerMixin):
- isMain = (obj.ControllingSizer is None
- and isinstance(obj.Parent, dui.dForm))
- if not isMain:
- ret.append(_("Cut"), bindfunc=self.onTreeCut)
- ret.append(_("Copy"), bindfunc=self.onTreeCopy)
- if not isMain:
- # Don't delete the main sizer for the form.
- ret.appendSeparator()
- ret.append(_("Delete"),
bindfunc=self.onTreeDelete)
- if isinstance(obj, dui.dBorderSizer):
- prm = _("Remove Sizer Box")
- else:
- prm = _("Add Sizer Box")
- ret.append(prm, bindfunc=self.onTreeSwitchSizerType)
- elif isinstance(obj, (cmix, LayoutSpacerPanel)):
- # Control
- ret.append(_("Cut"), bindfunc=self.onTreeCut)
- ret.append(_("Copy"), bindfunc=self.onTreeCopy)
- ret.appendSeparator()
- ret.append(_("Delete"), bindfunc=self.onTreeDelete)
- elif isinstance(obj, LayoutPanel):
- if self._clipboard:
- ret.append(_("Paste"),
bindfunc=self.onTreePaste)
- if not isinstance(obj.ControllingSizer,
LayoutGridSizer):
- ret.append(_("Delete"),
bindfunc=self.onTreeDelete)
- else:
+ self._contextObj = obj
+ try:
+ ret = obj.createContextMenu()
+ except StandardError, e:
+ print "NO ON CONTEXT", e
ret = None
- self._treeContextObj = None
- if ret and not isinstance(self, (dui.dPage, LayoutPanel)):
- # Add the Sizer editing option
- ret.appendSeparator()
- ret.append(_("Edit Sizer Settings"),
bindfunc=self.onTreeEditSizer)
return ret
+ def onSwitchOrientation(self,evt):
+ """Called when the user selects a command to switch the sizer's
Orientation."""
+ obj = self._contextObj
+ self._contextObj = None
+ try:
+ if obj.Orientation == "Horizontal":
+ obj.Orientation = "Vertical"
+ elif obj.Orientation == "Vertical":
+ obj.Orientation = "Horizontal"
+ self.updateLayout()
+ except: pass
+
+
def onTreeSwitchSizerType(self, evt):
- fromSz = self._treeContextObj
+ """Switches between a non-border and a bordered sizer."""
+ fromSz = self._contextObj
ornt = fromSz.Orientation
parent = fromSz.Parent
setParentSizer = (fromSz.Parent is not None) and
(fromSz.Parent.Sizer is fromSz)
@@ -1620,7 +1605,7 @@
fromSz.remove(member)
# Delete the old sizer. We can use the onTreeDelete method,
since
- # the _treeContextObject is the same.
+ # the _contextObject is the same.
self.onTreeDelete(evt)
if setParentSizer:
parent.Sizer = toSz
@@ -1634,27 +1619,27 @@
def onTreeEditSizer(self, evt):
- self.editSizerSettings(self._treeContextObj)
+ self.editSizerSettings(self._contextObj)
def onTreeCut(self, evt):
- obj = self._treeContextObj
+ obj = self._contextObj
self.copyObject(obj)
self.onTreeDelete(evt)
def onTreeCopy(self, evt):
- obj = self._treeContextObj
+ obj = self._contextObj
self.copyObject(obj)
def onTreePaste(self, evt):
- obj = self._treeContextObj
+ obj = self._contextObj
self.pasteObject(obj)
def onTreeDelete(self, evt):
- obj = self._treeContextObj
+ obj = self._contextObj
if hasattr(obj, "onDelete"):
obj.onDelete(evt)
return
@@ -1872,6 +1857,38 @@
return ret
+ def addSlotOptions(self, obj, pop):
+ """Takes an object and a context menu, and adds the appropriate
options
+ depending on its position in the design surface.
+ """
+ self._contextObj = obj
+ if isinstance(obj.ControllingSizer, dabo.ui.dSizer):
+ if obj.ControllingSizer.Orientation == "Vertical":
+ pop.append(_("Add Slot Above"),
bindfunc=self.onAddSlotBefore)
+ pop.append(_("Add Slot Below"),
bindfunc=self.onAddSlotAfter)
+ else:
+ pop.append(_("Add Slot Left"),
bindfunc=self.onAddSlotBefore)
+ pop.append(_("Add Slot Right"),
bindfunc=self.onAddSlotAfter)
+
+
+ def onAddSlotBefore(self, evt):
+ self._addEmptySlot(0)
+
+
+ def onAddSlotAfter(self, evt):
+ self._addEmptySlot(1)
+
+
+ def _addEmptySlot(self, offset):
+ obj = self._contextObj
+ self._contextObj = None
+ if not obj:
+ return
+ lp = LayoutPanel(obj.Parent, AutoSizer=False)
+ obj.ControllingSizer.insert(obj.getPositionInSizer() + offset,
lp, 1, "x")
+ self.updateLayout()
+
+
def getControlMenu(self, srcObj, justSizers=False):
"""Creates the popup menu for selecting child objects"""
# Store the source object
Modified: trunk/ClassDesignerComponents.py
===================================================================
--- trunk/ClassDesignerComponents.py 2006-05-15 17:30:56 UTC (rev 573)
+++ trunk/ClassDesignerComponents.py 2006-05-15 21:10:31 UTC (rev 574)
@@ -421,6 +421,12 @@
def onContextMenu(self, evt):
if isinstance(self.Parent, dabo.ui.dPage):
self.Parent.activePanel = self
+ pop = self.createContextMenu()
+ dabo.ui.callAfter(self.showContextMenu, pop)
+ evt.stop()
+
+
+ def createContextMenu(self):
pop = self.Form.app.getControlMenu(self)
if isinstance(self.Parent, (dabo.ui.dPage, dabo.ui.dPanel)):
if not self.Parent is self.Form.mainPanel:
@@ -441,31 +447,10 @@
# Add the Sizer editing option
pop.appendSeparator()
pop.append(_("Edit Sizer Settings"), bindfunc=self.onEditSizer)
- if isinstance(self.ControllingSizer, dabo.ui.dSizer):
- if self.ControllingSizer.Orientation == "Vertical":
- pop.append(_("Add Slot Above"),
bindfunc=self.onAddSlotBefore)
- pop.append(_("Add Slot Below"),
bindfunc=self.onAddSlotAfter)
- else:
- pop.append(_("Add Slot Left"),
bindfunc=self.onAddSlotBefore)
- pop.append(_("Add Slot Right"),
bindfunc=self.onAddSlotAfter)
- dabo.ui.callAfter(self.showContextMenu, pop)
- evt.stop()
+ self.Application.addSlotOptions(self, pop)
+ return pop
- def onAddSlotBefore(self, evt):
- self._addEmptySlot(0)
-
-
- def onAddSlotAfter(self, evt):
- self._addEmptySlot(1)
-
-
- def _addEmptySlot(self, offset):
- lp = LayoutPanel(self.Parent, AutoSizer=False)
- self.ControllingSizer.insert(self.getPositionInSizer() +
offset, lp, 1, "x")
- self.Application.updateLayout()
-
-
def onEditSizer(self, evt):
"""Called when the user selects the context menu option
to edit this slot's sizer information.
@@ -878,6 +863,29 @@
return ret
+ def createContextMenu(self):
+ ret = dabo.ui.dMenu()
+ isMain = (self.ControllingSizer is None
+ and isinstance(self.Parent, dabo.ui.dForm))
+ if not isMain:
+ ret.append(_("Cut"),
bindfunc=self.Application.onTreeCut)
+ ret.append(_("Copy"), bindfunc=self.Application.onTreeCopy)
+ if not isMain:
+ # Don't delete the main sizer for the form.
+ ret.appendSeparator()
+ ret.append(_("Delete"),
bindfunc=self.Application.onTreeDelete)
+ if self.Orientation == "Horizontal":
+ ret.append(_("Make Vertical"),
bindfunc=self.Application.onSwitchOrientation)
+ elif self.Orientation == "Vertical":
+ ret.append(_("Make Horizontal"),
bindfunc=self.Application.onSwitchOrientation)
+ if isinstance(self, dabo.ui.dBorderSizer):
+ prm = _("Remove Sizer Box")
+ else:
+ prm = _("Add Sizer Box")
+ ret.append(prm, bindfunc=self.Application.onTreeSwitchSizerType)
+ return ret
+
+
def onCut(self, evt):
"""Place a copy of this sizer on the app clipboard,
and then delete the sizer
Modified: trunk/ClassDesignerControlMixin.py
===================================================================
--- trunk/ClassDesignerControlMixin.py 2006-05-15 17:30:56 UTC (rev 573)
+++ trunk/ClassDesignerControlMixin.py 2006-05-15 21:10:31 UTC (rev 574)
@@ -138,13 +138,18 @@
evt.stop()
if isinstance(self, (dabo.ui.dPage, LayoutPanel)):
return
- elif isinstance(self, (dabo.ui.dPanel,)):
+ pop = self.createContextMenu()
+ self.showContextMenu(pop)
+
+
+ def createContextMenu(self):
+ if isinstance(self, (dabo.ui.dPanel,)):
# If the control can contain child objects, get that
menu.
# If it already has child objects, though, do not get
the menu.
if len(self.Children) == 0:
pop = self.Form.app.getControlMenu(self, True)
else:
- return
+ return None
else:
pop = dabo.ui.dMenu()
if len(pop.Children):
@@ -157,30 +162,10 @@
# Add the Sizer editing option
pop.appendSeparator()
pop.append(_("Edit Sizer Settings"), bindfunc=self.onEditSizer)
- if isinstance(self.ControllingSizer, dabo.ui.dSizer):
- if self.ControllingSizer.Orientation == "Vertical":
- pop.append(_("Add Slot Above"),
bindfunc=self.onAddSlotBefore)
- pop.append(_("Add Slot Below"),
bindfunc=self.onAddSlotAfter)
- else:
- pop.append(_("Add Slot Left"),
bindfunc=self.onAddSlotBefore)
- pop.append(_("Add Slot Right"),
bindfunc=self.onAddSlotAfter)
- self.showContextMenu(pop)
-
-
- def onAddSlotBefore(self, evt):
- self._addEmptySlot(0)
+ self.Application.addSlotOptions(self, pop)
+ return pop
- def onAddSlotAfter(self, evt):
- self._addEmptySlot(1)
-
-
- def _addEmptySlot(self, offset):
- lp = LayoutPanel(self.Parent, AutoSizer=False)
- self.ControllingSizer.insert(self.getPositionInSizer() +
offset, lp, 1, "x")
- self.Application.updateLayout()
-
-
def onEditSizer(self, evt):
"""Called when the user selects the context menu option
to edit this control's sizer information.
Modified: trunk/ClassDesignerTreeSheet.py
===================================================================
--- trunk/ClassDesignerTreeSheet.py 2006-05-15 17:30:56 UTC (rev 573)
+++ trunk/ClassDesignerTreeSheet.py 2006-05-15 21:10:31 UTC (rev 574)
@@ -150,9 +150,8 @@
# Add the row,col info to the caption
r, c = obj.ControllingSizer.getGridPos(obj)
ret = "%s r:%s, c:%s" % (self._slotCaption, r,
c)
-
- elif isinstance(obj, LayoutSpacerPanel):
- ret = "%s - (%s)" % (self._spacerCaption, obj.Spacing)
+ else:
+ ret = "%s - (%s)" % (self._spacerCaption,
obj.Spacing)
else:
if hasattr(obj, "TreeDisplayCaption"):
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev