GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
lmgr/menudata.py
Go to the documentation of this file.
00001 """!
00002 @package lmrg.menudata
00003 
00004 @brief Complex list for menu entries for wxGUI
00005 
00006 Classes:
00007  - menudata::MenuData
00008 
00009 Usage:
00010 @code
00011 python menudata.py [action] [manager|modeler]
00012 @endcode
00013 
00014 where <i>action</i>:
00015  - strings (default)
00016  - tree
00017  - commands
00018  - dump
00019 
00020 (C) 2007-2011 by the GRASS Development Team
00021 
00022 This program is free software under the GNU General Public License
00023 (>=v2). Read the file COPYING that comes with GRASS for details.
00024 
00025 @author Michael Barton (Arizona State University)
00026 @author Yann Chemin <yann.chemin gmail.com>
00027 @author Martin Landa <landa.martin gmail.com>
00028 @author Glynn Clements
00029 @author Anna Kratochvilova <kratochanna gmail.com>
00030 """
00031 
00032 import os
00033 import sys
00034 
00035 from core.globalvar import ETCWXDIR
00036 from core.menudata  import MenuData
00037 
00038 class ManagerData(MenuData):
00039     def __init__(self, filename = None):
00040         if not filename:
00041             gisbase = os.getenv('GISBASE')
00042             filename = os.path.join(ETCWXDIR, 'xml', 'menudata.xml')
00043         
00044         MenuData.__init__(self, filename)
00045         
00046     def GetModules(self):
00047         """!Create dictionary of modules used to search module by
00048         keywords, description, etc."""
00049         modules = dict()
00050         
00051         for node in self.tree.getiterator():
00052             if node.tag == 'menuitem':
00053                 module = description = ''
00054                 keywords = []
00055                 for child in node.getchildren():
00056                     if child.tag == 'help':
00057                         description = child.text
00058                     if child.tag == 'command':
00059                         module = child.text
00060                     if child.tag == 'keywords':
00061                         if child.text:
00062                             keywords = child.text.split(',')
00063                     
00064                 if module:
00065                     modules[module] = { 'desc': description,
00066                                         'keywords' : keywords }
00067                     if len(keywords) < 1:
00068                         print >> sys.stderr, "WARNING: Module <%s> has no keywords" % module
00069                 
00070         return modules