[GRASS-SVN] r30708 - grass/trunk/gui/wxpython/support
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Mar 23 17:59:17 EDT 2008
Author: martinl
Date: 2008-03-23 17:59:17 -0400 (Sun, 23 Mar 2008)
New Revision: 30708
Added:
grass/trunk/gui/wxpython/support/update_menu_desc.py
Log:
wxGUI: support script for automated update of module description in menudata (added)
Added: grass/trunk/gui/wxpython/support/update_menu_desc.py
===================================================================
--- grass/trunk/gui/wxpython/support/update_menu_desc.py (rev 0)
+++ grass/trunk/gui/wxpython/support/update_menu_desc.py 2008-03-23 21:59:17 UTC (rev 30708)
@@ -0,0 +1,96 @@
+"""
+ at brief Reads menu data from menudata.py and for each command updates
+its description (based on interface description).
+
+Updated menu data is printed to stdout.
+
+Support script for wxGUI.
+
+COPYRIGHT: (C) 2008 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.
+
+Usage: python update_menu_desc.py
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import os
+import sys
+### i18N
+import gettext
+gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+
+import xml.sax
+import xml.sax.handler
+HandlerBase=xml.sax.handler.ContentHandler
+from xml.sax import make_parser
+
+sys.path.append('../gui_modules')
+import menudata
+import menuform
+
+def read_menudata():
+ menu = menudata.Data() # get menu data
+ for mainItem in menu.GetMenu()[0]:
+ print ' (_("%s"), (' % mainItem[0]
+ for item1 in mainItem[1]:
+ if len(item1[0]) == 0: # separator
+ print ' ("","","", ""),'
+ continue
+ if len(item1) == 4:
+ desc = get_description(item1[1:])
+ print ' (_("%s"),' % item1[0]
+ if desc and desc != item1[1]:
+ print ' _("%s"),' % desc
+ else:
+ print ' _("%s"),' % item1[1]
+ print ' "%s",' % item1[2]
+ print ' "%s"),' % item1[3]
+ else: # submenu
+ print ' (_("%s"), (' % item1[0]
+ for item2 in item1[1]:
+ if len(item2[0]) == 0: # separator
+ print ' ("","","", ""),'
+ continue
+ desc = get_description(item2[1:])
+ print ' (_("%s"),' % item2[0]
+ if desc and desc != item2[1]:
+ print ' _("%s"),' % desc
+ else:
+ print ' _("%s"),' % item2[1]
+ print ' "%s",' % item2[2]
+ print ' "%s"),' % item2[3]
+ print ' )'
+ print ' ),'
+ print ' )'
+ print ' ),'
+
+def get_description(item):
+ """Return command desctiption based on interface
+ description"""
+ print
+ desc, type, cmd = item
+ if type in ("self.OnMenuCmd", "self.RunMenuCmd"):
+ module = cmd.split(' ')[0]
+ grass_task = menuform.grassTask()
+ handler = menuform.processTask(grass_task)
+ xml.sax.parseString(menuform.getInterfaceDescription(module), handler )
+
+ return grass_task.description.replace('"', '\\"')
+
+ return None
+
+def main(argv=None):
+ if argv is None:
+ argv = sys.argv
+
+ if len(argv) != 1:
+ print >> sys.stderr, __doc__
+ sys.exit()
+
+ read_menudata()
+
+if __name__ == '__main__':
+ main()
More information about the grass-commit
mailing list