dabo Commit
Revision 4945
Date: 2009-01-21 18:50:34 -0800 (Wed, 21 Jan 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/4945

Changed:
U   trunk/dabo/ui/uiwx/dBaseMenuBar.py
U   trunk/dabo/ui/uiwx/dMenu.py
U   trunk/dabo/ui/uiwx/dMenuBar.py
U   trunk/dabo/ui/uiwx/dMenuItem.py

Log:
Initial work on implementing an ID-based system for menus and menu items. They 
now have MenuID and ItemID properties, respectively. dMenuBar.getMenu() now 
will find based on MenuID or Caption, and dMenu.getItem() will likewise search 
on ItemID or Caption.

Comments, suggestions, etc. are always welcome.


Diff:
Modified: trunk/dabo/ui/uiwx/dBaseMenuBar.py
===================================================================
--- trunk/dabo/ui/uiwx/dBaseMenuBar.py  2009-01-22 01:49:03 UTC (rev 4944)
+++ trunk/dabo/ui/uiwx/dBaseMenuBar.py  2009-01-22 02:50:34 UTC (rev 4945)
@@ -34,14 +34,17 @@
                if self.Application.ShowCommandWindowMenu:
                        self.commandWinMenuItem = self.append(_("Command 
Win&dow"), HotKey="Ctrl+D", 
                                        OnHit=app.onCmdWin, 
bmp="%s/apps/utilities-terminal.png" % iconPath,
+                                       ItemID="file_commandwin",
                                        help=_("Open up a command window for 
debugging") )
 
                        self.debugMenuItem = self.append(_("De&bug Output 
Window"), HotKey="Ctrl+B", 
                                        OnHit=app.onDebugWin, 
bmp="%s/apps/utilities-terminal.png" % iconPath, 
+                                       ItemID="file_debugwin",
                                        menutype="check", help=_("Open up a 
debug output window") )
 
                prmpt = _("Close Windo&w")
                self.append(prmpt, HotKey="Ctrl+W", OnHit=app.onWinClose,
+                               ItemID="file_close",
                                help=_("Close the current window") )
 
                self.appendSeparator()
@@ -49,6 +52,7 @@
                prmpt = _("&Quit")
                self.append(prmpt, HotKey="Ctrl+Q", id=wx.ID_EXIT, 
OnHit=app.onFileExit, 
                                bmp="%s/actions/system-log-out.png" % iconPath, 
+                               ItemID="file_quit",
                                help=_("Exit the application") )
 
 
@@ -61,28 +65,34 @@
 
                self.append(_("&Undo"), HotKey="Ctrl+Z", OnHit=app.onEditUndo, 
                                bmp="%s/actions/edit-undo.png" % iconPath,
+                               ItemID="edit_undo",
                                help=_("Undo last action") )
 
                self.append(_("&Redo"), HotKey="Ctrl+R", OnHit=app.onEditRedo, 
                                bmp="%s/actions/edit-redo.png" % iconPath,
+                               ItemID="edit_redo",
                                help=_("Undo last undo") )
 
                self.appendSeparator()
 
                self.append(_("Cu&t"), HotKey="Ctrl+X", OnHit=app.onEditCut, 
                                bmp="%s/actions/edit-cut.png" % iconPath,
+                               ItemID="edit_cut",
                                help=_("Cut selected text") )
 
                self.append(_("&Copy"), HotKey="Ctrl+C", OnHit=app.onEditCopy, 
                                bmp="%s/actions/edit-copy.png" % iconPath,
+                               ItemID="edit_copy",
                                help=_("Copy selected text") )
 
                self.append(_("&Paste"), HotKey="Ctrl+V", 
OnHit=app.onEditPaste, 
                                bmp="%s/actions/edit-paste.png" % iconPath,
+                               ItemID="edit_paste",
                                help=_("Paste text from clipboard") )
 
                self.append(_("Select &All"), HotKey="Ctrl+A", 
OnHit=app.onEditSelectAll, 
                                bmp="%s/actions/edit-select-all.png" % iconPath,
+                               ItemID="edit_selectall",
                                help=_("Select all text") )
 
                self.appendSeparator()
@@ -90,19 +100,22 @@
                # By default, the Find and Replace functions use a single 
dialog. The
                # commented lines below this enable the plain Find dialog call.
                self.append(_("&Find / Replace"), HotKey="Ctrl+F", 
OnHit=app.onEditFind, 
-                               bmp="%s/actions/edit-find-replace.png" % 
iconPath, 
+                               bmp="%s/actions/edit-find-replace.png" % 
iconPath,
+                               ItemID="edit_findreplace",
                                help=_("Find or Replace text in the active 
window") )
 
 #              self.append(_("Find"), HotKey="Shift+Ctrl+F", 
OnHit=app.onEditFindAlone, 
 #                              bmp="%s/actions/edit-find.png" % iconPath, 
help=_("Find text in the active window") )
 
                self.append(_("Find A&gain"), HotKey="Ctrl+G", 
OnHit=app.onEditFindAgain, bmp="",
+                               ItemID="edit_findagain",
                                help=_("Repeat the last search") )
 
                self.appendSeparator()
 
                itm = self.append(_("Pr&eferences"), 
OnHit=app.onEditPreferences, 
                                bmp="%s/categories/preferences-system.png" % 
iconPath,
+                               ItemID="edit_preferences",
                                help=_("Set user preferences"), special="pref" )
 
 
@@ -113,14 +126,18 @@
                app = self.Application
                self.Caption = _("&View")
        
-               self.append(_("Increase Font Size"), HotKey="Ctrl++", 
OnHit=app.fontZoomIn)
-               self.append(_("Decrease Font Size"), HotKey="Ctrl+-", 
OnHit=app.fontZoomOut)
-               self.append(_("Normal Font Size"), HotKey="Ctrl+/", 
OnHit=app.fontZoomNormal)
+               self.append(_("Increase Font Size"), HotKey="Ctrl++", 
+                               ItemID="view_zoomin", OnHit=app.fontZoomIn)
+               self.append(_("Decrease Font Size"), HotKey="Ctrl+-", 
+                               ItemID="view_zoomout", OnHit=app.fontZoomOut)
+               self.append(_("Normal Font Size"), HotKey="Ctrl+/", 
+                               ItemID="view_zoomnormal", 
OnHit=app.fontZoomNormal)
        
                if app.ShowSizerLinesMenu:
                        self.appendSeparator()
                        self.append(_("Show/Hide Sizer &Lines"), 
HotKey="Ctrl+L",       
-                                       OnHit=app.onShowSizerLines, 
menutype="check",
+                                       OnHit=app.onShowSizerLines, 
menutype="check", 
+                                       ItemID="view_showsizerlines",
                                        help=_("Cool sizer visualizing feature; 
check it out!"))
 
 
@@ -137,6 +154,7 @@
 
                itm = self.append(caption, id=wx.ID_ABOUT, 
                                OnHit=app.onHelpAbout,
+                               ItemID="help_about",
                                help=_("About this application") )
 
 
@@ -154,10 +172,10 @@
        """
        def _afterInit(self):
                super(dBaseMenuBar, self)._afterInit()
-               self.appendMenu(FileMenu(self))
-               self.appendMenu(EditMenu(self))
-               self.appendMenu(ViewMenu(self))
-               self.appendMenu(HelpMenu(self))
+               self.appendMenu(FileMenu(self, MenuID="base_file"))
+               self.appendMenu(EditMenu(self, MenuID="base_edit"))
+               self.appendMenu(ViewMenu(self, MenuID="base_view"))
+               self.appendMenu(HelpMenu(self, MenuID="base_help"))
 
 
 # Trying to expose menu atts as menubar atts. Not sure if this is a good idea 
yet...

Modified: trunk/dabo/ui/uiwx/dMenu.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenu.py 2009-01-22 01:49:03 UTC (rev 4944)
+++ trunk/dabo/ui/uiwx/dMenu.py 2009-01-22 02:50:34 UTC (rev 4945)
@@ -31,6 +31,10 @@
                else:
                        self._useMRU = self._extractKey((properties, kwargs), 
"MRU", False)
                self._mruSeparator = None
+               # Identifying attribute that can be used to locate the menu 
+               # independent of its Caption or index.
+               self._menuID = None
+               
                ## pkm: When a dMenuItem is added to a dMenu, the wx functions 
only
                ##      add the C++ portion, not the mixed-in dabo dMenuItem 
object.
                ##      To work around this, we maintain an internal dictionary 
that
@@ -418,18 +422,28 @@
                return self._itemByCaption(caption, True)
                
 
-       def getItem(self, caption):
-               """Returns a reference to the menu item with the specified 
caption. If the item
-               isn't found, None is returned.
+       def getItem(self, idOrCaption):
+               """Returns a reference to the menu item with the specified 
ItemID or Caption. 
+               The ItemID property is checked first; then the Caption. If no 
match is found, 
+               None is returned.
                """
-               return self._itemByCaption(caption)
+               menuitems = (itm for itm in self.Children
+                               if hasattr(itm, "ItemID"))
+               try:
+                       ret = [mn for mn in menuitems
+                                       if mn.ItemID == idOrCaption][0]
+               except IndexError:
+                       ret = None
+                       # Try the Caption
+                       ret = self._itemByCaption(idOrCaption)
+               return ret
 
 
        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
                items in this menu, but is using the consistent Children 
property to 
-               do it.
+               do it. The Children property will thus return both menu items 
and separators.
                """
                children = self.GetMenuItems()
                daboChildren = [self._daboChildren.get(c.GetId(), c) for c in 
children]
@@ -492,6 +506,16 @@
                self._helpText = val
 
 
+       def _getMenuID(self):
+               return self._menuID
+
+       def _setMenuID(self, val):
+               if self._constructed():
+                       self._menuID = val
+               else:
+                       self._properties["MenuID"] = val
+
+
        def _getParent(self):
                try:
                        v = self._parent
@@ -515,6 +539,11 @@
        HelpText = property(_getHelpText, _setHelpText, None,
                        _("Specifies the help text associated with this menu. 
(str)"))
 
+       MenuID = property(_getMenuID, _setMenuID, None,
+                       _("""Identifying value for this menu. NOTE: there is no 
checking for
+                       duplicate values; it is the responsibility to ensure 
that MenuID values
+                       are unique.  (varies)"""))
+
        Parent = property(_getParent, _setParent, None, 
                        _("Specifies the parent menu or menubar."))
 

Modified: trunk/dabo/ui/uiwx/dMenuBar.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenuBar.py      2009-01-22 01:49:03 UTC (rev 4944)
+++ trunk/dabo/ui/uiwx/dMenuBar.py      2009-01-22 02:50:34 UTC (rev 4945)
@@ -129,15 +129,21 @@
                return menu
 
 
-       def getMenu(self, caption):
-               """Returns a reference to the menu with the specified caption.
-
-               If the menu isn't found, None is returned.
+       def getMenu(self, idOrCaption):
+               """Returns a reference to the menu with the specified MenuID or 
Caption. 
+               The MenuID property is checked first; then the Caption. If no 
match is found, 
+               None is returned.
                """
-               idx = self.getMenuIndex(caption)
-               if idx is not None:
-                       return self.GetMenu(idx)
-               return None
+               try:
+                       ret = [mn for mn in self.Children
+                                       if mn.MenuID == idOrCaption][0]
+               except IndexError:
+                       ret = None
+                       # Try the Caption
+                       idx = self.getMenuIndex(idOrCaption)
+                       if idx is not None:
+                               ret = self.GetMenu(idx)
+               return ret
 
 
        def getMenuIndex(self, caption):

Modified: trunk/dabo/ui/uiwx/dMenuItem.py
===================================================================
--- trunk/dabo/ui/uiwx/dMenuItem.py     2009-01-22 01:49:03 UTC (rev 4944)
+++ trunk/dabo/ui/uiwx/dMenuItem.py     2009-01-22 02:50:34 UTC (rev 4945)
@@ -24,7 +24,9 @@
                # Main text of the menu item
                self._caption = ""
                # Holds the key combination used to trigger the menu
-               self._hotKey = None             
+               self._hotKey = None
+               # Holds the unique ID, if any
+               self._itemID = None
                
                pm.dPemMixin.__init__(self, preClass, parent, properties, 
*args, **kwargs)
 
@@ -157,6 +159,16 @@
                        self._properties["Icon"] = val
 
 
+       def _getItemID(self):
+               return self._itemID
+
+       def _setItemID(self, val):
+               if self._constructed():
+                       self._itemID = val
+               else:
+                       self._properties["ItemID"] = val
+
+
        def _getParent(self):
                try:
                        ret = self._parent
@@ -174,18 +186,23 @@
        Enabled = property(_getEnabled, _setEnabled, None,
                        _("Specifies whether the menu item can be interacted 
with."))
 
+       Form = property(_getForm, None, None,
+                       _("Specifies the containing form."))
+
+       HelpText = property(_getHelpText, _setHelpText, None,
+                       _("Specifies the help text associated with this menu. 
(str)"))
+
        HotKey = property(_getHotKey, _setHotKey, None,
                        _("Key combination that will trigger the menu  (str)"))
        
        Icon = property(_getIcon, _setIcon, None,
                        _("Specifies the icon for the menu item."))
 
-       Form = property(_getForm, None, None,
-                       _("Specifies the containing form."))
+       ItemID = property(_getItemID, _setItemID, None,
+                       _("""Identifying value for this menuitem. NOTE: there 
is no checking for
+                       duplicate values; it is the responsibility to ensure 
that ItemID values
+                       are unique within a menu.  (varies)"""))
 
-       HelpText = property(_getHelpText, _setHelpText, None,
-                       _("Specifies the help text associated with this menu. 
(str)"))
-
        Parent = property(_getParent, _setParent, None, 
                        _("Specifies the parent menu."))
 



_______________________________________________
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