Kaynağa Gözat

print list of commands

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@39047 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 yıl önce
ebeveyn
işleme
cb75058842
1 değiştirilmiş dosya ile 69 ekleme ve 7 silme
  1. 69 7
      gui/wxpython/gui_modules/menudata.py

+ 69 - 7
gui/wxpython/gui_modules/menudata.py

@@ -7,6 +7,16 @@ Classes:
  - Data
  - MenuTree
 
+Usage:
+@code
+python menudata.py action [file]
+@endcode
+
+where <i>action</i>:
+ - strings (default)
+ - tree
+ - commands
+
 (C) 2007-2009 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
@@ -91,7 +101,7 @@ class Data:
         level = 0
         for eachMenuData in self.GetMenu():
             for label, items in eachMenuData:
-                print >> fh, '-', label
+                fh.write('- %s\n' % label)
                 self.__PrintTreeItems(fh, level + 1, items)
 
     def __PrintTreeItems(self, fh, level, menuData):
@@ -103,11 +113,50 @@ class Data:
         for eachItem in menuData:
             if len(eachItem) == 2:
                 if eachItem[0]:
-                    print >> fh, ' ' * level, '-', eachItem[0]
+                    fh.write('%s - %s\n' % (' ' * level, eachItem[0]))
                 self.__PrintTreeItems(fh, level + 1, eachItem[1])
             else:
                 if eachItem[0]:
-                    print >> fh, ' ' * level, '-', eachItem[0]
+                    fh.write('%s - %s\n' % (' ' * level, eachItem[0]))
+    
+    def PrintCommands(self, fh, itemSep = ' | ', menuSep = ' > '):
+        """!Print commands list (command | menu item > menu item)
+
+        @param fh file descriptor
+        """
+        level = 0
+        for eachMenuData in self.GetMenu():
+            for label, items in eachMenuData:
+                menuItems = [label, ]
+                self.__PrintCommandsItems(fh, level + 1, items,
+                                          menuItems, itemSep, menuSep)
+        
+    def __PrintCommandsItems(self, fh, level, menuData,
+                             menuItems, itemSep, menuSep):
+        """!Print commands item (used by PrintCommands)
+
+        @param fh file descriptor
+        @param menuItems list of menu items
+        """
+        for eachItem in menuData:
+            if len(eachItem) == 2:
+                if eachItem[0]:
+                    try:
+                        menuItems[level] = eachItem[0]
+                    except IndexError:
+                        menuItems.append(eachItem[0])
+                self.__PrintCommandsItems(fh, level + 1, eachItem[1],
+                                          menuItems, itemSep, menuSep)
+            else:
+                try:
+                    del menuItems[level]
+                except IndexError:
+                    pass
+                
+                if eachItem[3]:
+                    fh.write('%s%s' % (eachItem[3], itemSep))
+                    fh.write(menuSep.join(menuItems))
+                    fh.write('\n')
         
     def GetModules(self):
         """!Create dictionary of modules used to search module by
@@ -138,12 +187,25 @@ if __name__ == "__main__":
     # i18N
     import gettext
     gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
-    
-    if len(sys.argv) > 1:
-        data = Data(sys.argv[1])
+
+    file = None
+    if len(sys.argv) == 1:
+        action = 'strings'
+    elif len(sys.argv) > 1:
+        action = sys.argv[1]
+    if len(sys.argv) > 2:
+        file = sys.argv[2]
+
+    if file:
+        data = Data(file)
     else:
         data = Data()
     
-    data.PrintTree(sys.stdout)
+    if action == 'strings':
+        data.PrintStrings(sys.stdout)
+    elif action == 'tree':
+        data.PrintTree(sys.stdout)
+    elif action == 'commands':
+        data.PrintCommands(sys.stdout)
     
     sys.exit(0)