menudata.py 2.0 KB

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