GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
lmgr/menudata.py
Go to the documentation of this file.
1 """!
2 @package lmrg.menudata
3 
4 @brief Complex list for menu entries for wxGUI
5 
6 Classes:
7  - menudata::MenuData
8 
9 Usage:
10 @code
11 python menudata.py [action] [manager|modeler]
12 @endcode
13 
14 where <i>action</i>:
15  - strings (default)
16  - tree
17  - commands
18  - dump
19 
20 (C) 2007-2011 by the GRASS Development Team
21 
22 This program is free software under the GNU General Public License
23 (>=v2). Read the file COPYING that comes with GRASS for details.
24 
25 @author Michael Barton (Arizona State University)
26 @author Yann Chemin <yann.chemin gmail.com>
27 @author Martin Landa <landa.martin gmail.com>
28 @author Glynn Clements
29 @author Anna Kratochvilova <kratochanna gmail.com>
30 """
31 
32 import os
33 import sys
34 
35 from core.globalvar import ETCWXDIR
36 from core.menudata import MenuData
37 
39  def __init__(self, filename = None):
40  if not filename:
41  gisbase = os.getenv('GISBASE')
42  filename = os.path.join(ETCWXDIR, 'xml', 'menudata.xml')
43 
44  MenuData.__init__(self, filename)
45 
46  def GetModules(self):
47  """!Create dictionary of modules used to search module by
48  keywords, description, etc."""
49  modules = dict()
50 
51  for node in self.tree.getiterator():
52  if node.tag == 'menuitem':
53  module = description = ''
54  keywords = []
55  for child in node.getchildren():
56  if child.tag == 'help':
57  description = child.text
58  if child.tag == 'command':
59  module = child.text
60  if child.tag == 'keywords':
61  if child.text:
62  keywords = child.text.split(',')
63 
64  if module:
65  modules[module] = { 'desc': description,
66  'keywords' : keywords }
67  if len(keywords) < 1:
68  print >> sys.stderr, "WARNING: Module <%s> has no keywords" % module
69 
70  return modules