dabo Commit
Revision 4345
Date: 2008-08-03 10:07:55 -0700 (Sun, 03 Aug 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4345

Changed:
U   trunk/dabo/ui/uiwx/dMenu.py

Log:
Fixed the problem reported by Nate Lowrie where menus running under Windows 
would not properly space their captions. This was analogous to the problem 
solved earlier for submenus, and the same solution worked in this case.

Refactored out the menu item creation code into a single method named 
_createMenuItem() that is called from append(), insert() and prepend().

Renamed the append-, insert- and prependItem() methods to have a leading 
underscore. These are "internal use only" methods and should never be called in 
application code.


Diff:
Modified: trunk/dabo/ui/uiwx/dMenu.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenu.py 2008-08-03 15:46:14 UTC (rev 4344)
+++ trunk/dabo/ui/uiwx/dMenu.py 2008-08-03 17:07:55 UTC (rev 4345)
@@ -148,19 +148,19 @@
                        wx.App_SetMacPreferencesMenuItemId(id_)
 
        
-       def appendItem(self, item):
+       def _appendItem(self, item):
                """Insert a dMenuItem at the bottom of the menu."""
                wxItem = self._getWxItem(self.AppendItem, item)
                return item
                
 
-       def insertItem(self, pos, item):
+       def _insertItem(self, pos, item):
                """Insert a dMenuItem before the specified position in the 
menu."""
                wxItem = self._getWxItem(self.InsertItem, item, pos)
                return item
                
 
-       def prependItem(self, item):
+       def _prependItem(self, item):
                """Insert a dMenuItem at the top of the menu."""
                wxItem = self._getWxItem(self.PrependItem, item)
                return item
@@ -214,6 +214,26 @@
                return self.PrependSeparator()
        
 
+       def _createMenuItem(self, pos, caption, help, bmp, picture, menutype, 
*args, **kwargs):
+               """Handles the menu item creation for append(), insert() and 
prepend()."""
+               if pos is None:
+                       pos = len(self.Children)
+               if picture is None:
+                       picture = bmp
+               def _actualCreation(caption, help, picture, menutype, *args, 
**kwargs):
+                       _item = self._getItem(help, picture, menutype, *args, 
**kwargs)
+                       self._appendItem(_item)
+                       _item.Caption = caption
+                       return _item
+               dummySpacer = None
+               if not self.Children:
+                       dummySpacer = _actualCreation(" ", "", None, "")
+               item = _actualCreation(caption, help, picture, menutype, *args, 
**kwargs)
+               if dummySpacer:
+                       self.remove(dummySpacer)
+               return item
+
+
        def append(self, caption, help="", bmp=None, picture=None,
                        menutype="", *args, **kwargs):
                """Append a dMenuItem with the specified properties.
@@ -225,12 +245,8 @@
                of the dMenuItem: if valid property names/values, the dMenuItem 
will take
                them on; if not valid, an exception will be raised.
                """
-               if picture is None:
-                       picture = bmp
-               item = self._getItem(help, picture, menutype, *args, **kwargs)
-               self.appendItem(item)
-               item.Caption = caption
-               return item
+               return self._createMenuItem(None, caption=caption, help=help, 
bmp=bmp, picture=picture, 
+                               menutype=menutype, *args, **kwargs)
 
 
        def insert(self, pos, caption, help="", bmp=None, picture=None,
@@ -244,12 +260,8 @@
                of the dMenuItem: if valid property names/values, the dMenuItem 
will take
                them on; if not valid, an exception will be raised.
                """
-               if picture is None:
-                       picture = bmp
-               item = self._getItem(help, picture, menutype, *args, **kwargs)
-               self.insertItem(pos, item)
-               item.Caption = caption
-               return item
+               return self._createMenuItem(pos, caption, help=help, bmp=bmp, 
picture=picture, 
+                               menutype=menutype, *args, **kwargs)
                
 
        def prepend(self, caption, help="", bmp=None, picture=None,
@@ -263,12 +275,8 @@
                of the dMenuItem: if valid property names/values, the dMenuItem 
will take
                them on; if not valid, an exception will be raised.
                """
-               if picture is None:
-                       picture = bmp
-               item = self._getItem(help, picture, menutype, *args, **kwargs)
-               self.prependItem(item)
-               item.Caption = caption
-               return item
+               return self._createMenuItem(0, caption, help=help, bmp=bmp, 
picture=picture, 
+                               menutype=menutype, *args, **kwargs)
                
 
        def _resolveItem(self, capIdxOrItem):




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to