Преглед на файлове

wxGUI/menu: add icon tag

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58562 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa преди 11 години
родител
ревизия
6be65073bb
променени са 4 файла, в които са добавени 18 реда и са изтрити 5 реда
  1. 7 2
      gui/wxpython/core/menutree.py
  2. 9 3
      gui/wxpython/gui_core/menu.py
  3. 1 0
      gui/wxpython/xml/menudata.README
  4. 1 0
      gui/wxpython/xml/wxgui_items.xml

+ 7 - 2
gui/wxpython/core/menutree.py

@@ -90,7 +90,7 @@ class MenuTreeModelBuilder:
     def _createItem(self, item, node):
         if item.tag == 'separator':
             data = dict(label='', description='', handler='',
-                        command='', keywords='', shortcut='', wxId='')
+                        command='', keywords='', shortcut='', wxId='', icon='')
             self.model.AppendNode(parent=node, label='', data=data)
         elif item.tag == 'menuitem':
             origLabel = _(item.find('label').text)
@@ -100,6 +100,7 @@ class MenuTreeModelBuilder:
             keywords = item.find('keywords') # optional
             shortcut = item.find('shortcut') # optional
             wxId     = item.find('id')       # optional
+            icon     = item.find('icon')     # optional
             if gcmd != None:
                 gcmd = gcmd.text
             else:
@@ -120,6 +121,10 @@ class MenuTreeModelBuilder:
                 wxId = eval('wx.' + wxId.text)
             else:
                 wxId = wx.ID_ANY
+            if icon != None:
+                icon = icon.text
+            else:
+                icon = ''
             label = origLabel
             if gcmd:
                 if self.menustyle == 1:
@@ -127,7 +132,7 @@ class MenuTreeModelBuilder:
                 elif self.menustyle == 2:
                     label = '      [' + gcmd + ']'
             data = dict(label=origLabel, description=desc, handler=handler,
-                        command=gcmd, keywords=keywords, shortcut=shortcut, wxId=wxId)
+                        command=gcmd, keywords=keywords, shortcut=shortcut, wxId=wxId, icon=icon)
             self.model.AppendNode(parent=node, label=label, data=data)
         elif item.tag == 'menu':
             self._createMenu(item, node)

+ 9 - 3
gui/wxpython/gui_core/menu.py

@@ -7,7 +7,7 @@ Classes:
  - menu::Menu
  - menu::SearchModuleWindow
 
-(C) 2010-2012 by the GRASS Development Team
+(C) 2010-2013 by the GRASS Development Team
 
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -27,6 +27,7 @@ from core.gcmd         import EncodeString
 from core.utils import _
 from gui_core.widgets  import SearchModuleWidget
 from gui_core.treeview import CTreeView
+from icons.icon import MetaIcon
 
 from grass.pydispatch.signal import Signal
 
@@ -37,6 +38,7 @@ class Menu(wx.MenuBar):
         self.parent = parent
         self.model = model
         self.menucmd = dict()
+        self.bmpsize = (16, 16)
 
         for child in self.model.root.children:
             self.Append(self._createMenu(child), child.label)
@@ -52,6 +54,7 @@ class Menu(wx.MenuBar):
             else:
                 data = child.data.copy()
                 data.pop('label')
+                
                 self._createMenuItem(menu, label=child.label, **data)
         
         self.parent.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.OnMenuHighlight)
@@ -59,7 +62,7 @@ class Menu(wx.MenuBar):
         return menu
 
     def _createMenuItem(self, menu, label, description, handler, command, keywords,
-                        shortcut = '', wxId = wx.ID_ANY, kind = wx.ITEM_NORMAL):
+                        shortcut = '', icon = '', wxId = wx.ID_ANY, kind = wx.ITEM_NORMAL):
         """!Creates menu items
         There are three menu styles (menu item text styles).
         1 -- label only, 2 -- label and cmd name, 3 -- cmd name only
@@ -76,7 +79,10 @@ class Menu(wx.MenuBar):
         if shortcut:
             label += '\t' + shortcut
         
-        menuItem = menu.Append(wxId, label, helpString, kind)
+        menuItem = wx.MenuItem(menu, wxId, label, helpString, kind)
+        if icon:
+            menuItem.SetBitmap(MetaIcon(img = icon).GetBitmap(self.bmpsize))
+        menu.AppendItem(menuItem)
         
         self.menucmd[menuItem.GetId()] = command
         

+ 1 - 0
gui/wxpython/xml/menudata.README

@@ -27,4 +27,5 @@ menuitem breakdown:
 	     the <command> module's module->keywords.  [do not edit]
 	     (G_add_keyword() in GRASS 7+)
 
+<icon>      optional icon to be shown in the menu
 

+ 1 - 0
gui/wxpython/xml/wxgui_items.xml

@@ -13,6 +13,7 @@
     <related-module>g.gui.gmodeler</related-module>
     <description>Launch Graphical modeler</description>
     <keywords>general,gui,graphical modeler,workflow</keywords>
+    <icon>modeler-main</icon>
   </wxgui-item>
   <wxgui-item name="RunModel">
     <label>Run model</label>