dabo Commit
Revision 1492
Date: 2005-10-30 16:52:35 -0800 (Sun, 30 Oct 2005)
Author: paul

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

Log:
Added dMenu.remove(pos). 
Added dMenu.getItem(caption) and dMenu.getItemIndex(caption). The latter
actually replaces an older function named getItemPosByCaption() - I wanted
to use the shorter name simply because it mirrors similar function in
dMenuBar.



Diff:
Modified: trunk/dabo/ui/uiwx/dMenu.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenu.py 2005-10-29 22:37:09 UTC (rev 1491)
+++ trunk/dabo/ui/uiwx/dMenu.py 2005-10-31 00:52:35 UTC (rev 1492)
@@ -133,6 +133,20 @@
                return item
                
                
+       def remove(self, index, release=True):
+               """Removes the item at the specified index from the menu.
+
+               If release is True (the default), the item is deleted as well. 
If release 
+               is False, a reference to the  object will be returned, and the 
caller 
+               is responsible for deleting it.
+               """
+               item = self.Children[index]
+               self.RemoveItem(item)
+               if release:
+                       item.Destroy()
+               return item
+
+
        def _getItem(self, prompt, bindfunc, help, icon, menutype, **kwargs):
                itmtyp = self._getItemType(menutype)
                itm = dMenuItem.dMenuItem(self, Caption=prompt, HelpText=help, 
Icon=icon, 
@@ -178,22 +192,28 @@
                return False
 
 
-       def getItemPosByCaption(self, cap):
-               """Given a caption, returns the position of the menu item whose
-               caption matches the specified value. Useful when you want to 
-               insert a menu item before a specific item.
+       def getItemIndex(self, caption):
+               """Returns the index of the item with the specified caption.
+
+               If the item isn't found, None is returned.
                """
-               ok = False
                for pos, itm in enumerate(self.Children):
-                       if itm.GetLabel() == cap:
-                               ok = True
-                               ret = pos
-                               break
-               if not ok:
-                       ret = None
-               return ret
+                       if itm.GetLabel() == caption:
+                               return pos
+               return None
                
-       
+
+       def getItem(self, caption):
+               """Returns a reference to the menu item with the specified 
caption.
+
+               If the item isn't found, None is returned.
+               """
+               idx = self.getItemIndex(caption)
+               if idx is not None:
+                       return self.FindItemByPosition(idx)
+               return None
+
+
        def GetChildren(self):
                # wx doesn't provide GetChildren() for menubars or menus, but 
dPemMixin
                # calls it in _getChildren(). The Dabo developer wants the 
submenus and




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to