[GRASS-SVN] r39047 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 6 13:00:08 EDT 2009
Author: martinl
Date: 2009-09-06 13:00:07 -0400 (Sun, 06 Sep 2009)
New Revision: 39047
Modified:
grass/trunk/gui/wxpython/gui_modules/menudata.py
Log:
print list of commands
Modified: grass/trunk/gui/wxpython/gui_modules/menudata.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menudata.py 2009-09-06 16:20:55 UTC (rev 39046)
+++ grass/trunk/gui/wxpython/gui_modules/menudata.py 2009-09-06 17:00:07 UTC (rev 39047)
@@ -7,6 +7,16 @@
- Data
- MenuTree
+Usage:
+ at code
+python menudata.py action [file]
+ at 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 @@
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,12 +113,51 @@
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
keywords, description, etc."""
@@ -138,12 +187,25 @@
# 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)
More information about the grass-commit
mailing list