menudata.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """!
  2. @package lmgr.menudata
  3. @brief wxGUI Layer Manager - menu data
  4. Classes:
  5. - menudata::LayerManagerMenuData
  6. (C) 2007-2012 by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. @author Martin Landa <landa.martin gmail.com>
  10. """
  11. import os
  12. import sys
  13. from core.globalvar import ETCWXDIR
  14. from core.menudata import MenuData
  15. class LayerManagerMenuData(MenuData):
  16. def __init__(self, filename = None):
  17. if not filename:
  18. gisbase = os.getenv('GISBASE')
  19. global etcwxdir
  20. filename = os.path.join(ETCWXDIR, 'xml', 'menudata.xml')
  21. MenuData.__init__(self, filename)
  22. def GetModules(self):
  23. """!Create dictionary of modules used to search module by
  24. keywords, description, etc."""
  25. modules = dict()
  26. for node in self.tree.getiterator():
  27. if node.tag == 'menuitem':
  28. module = description = ''
  29. keywords = []
  30. for child in node.getchildren():
  31. if child.tag == 'help':
  32. description = child.text
  33. if child.tag == 'command':
  34. module = child.text
  35. if child.tag == 'keywords':
  36. if child.text:
  37. keywords = child.text.split(',')
  38. if module:
  39. modules[module] = { 'desc': description,
  40. 'keywords' : keywords }
  41. if len(keywords) < 1:
  42. print >> sys.stderr, "WARNING: Module <%s> has no keywords" % module
  43. return modules