menudata.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. global etcwxdir
  19. filename = os.path.join(ETCWXDIR, 'xml', 'menudata.xml')
  20. MenuData.__init__(self, filename)
  21. def GetModules(self):
  22. """!Create dictionary of modules used to search module by
  23. keywords, description, etc."""
  24. modules = dict()
  25. for node in self.tree.getiterator():
  26. if node.tag == 'menuitem':
  27. module = description = ''
  28. keywords = []
  29. for child in node.getchildren():
  30. if child.tag == 'help':
  31. description = child.text
  32. if child.tag == 'command':
  33. module = child.text
  34. if child.tag == 'keywords':
  35. if child.text:
  36. keywords = child.text.split(',')
  37. if module:
  38. modules[module] = { 'description': description,
  39. 'keywords' : keywords }
  40. if len(keywords) < 1:
  41. print >> sys.stderr, "WARNING: Module <%s> has no keywords" % module
  42. return modules