globalvar.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. """!
  2. @package core.globalvar
  3. @brief Global variables used by wxGUI
  4. (C) 2007-2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. @author Martin Landa <landa.martin gmail.com>
  8. """
  9. import os
  10. import sys
  11. import locale
  12. if not os.getenv("GISBASE"):
  13. sys.exit("GRASS is not running. Exiting...")
  14. # path to python scripts
  15. ETCDIR = os.path.join(os.getenv("GISBASE"), "etc")
  16. ETCICONDIR = os.path.join(os.getenv("GISBASE"), "etc", "gui", "icons")
  17. ETCWXDIR = os.path.join(ETCDIR, "gui", "wxpython")
  18. ETCIMGDIR = os.path.join(ETCDIR, "gui", "images")
  19. ETCSYMBOLDIR = os.path.join(ETCDIR, "gui", "images", "symbols")
  20. from core.debug import Debug
  21. sys.path.append(os.path.join(ETCDIR, "python"))
  22. from grass.script.core import get_commands
  23. def CheckWxVersion(version = [2, 8, 11, 0]):
  24. """!Check wx version"""
  25. ver = wx.version().split(' ')[0]
  26. if map(int, ver.split('.')) < version:
  27. return False
  28. return True
  29. def CheckForWx():
  30. """!Try to import wx module and check its version"""
  31. if 'wx' in sys.modules.keys():
  32. return
  33. minVersion = [2, 8, 10, 1]
  34. try:
  35. try:
  36. import wxversion
  37. except ImportError, e:
  38. raise ImportError(e)
  39. # wxversion.select(str(minVersion[0]) + '.' + str(minVersion[1]))
  40. wxversion.ensureMinimal(str(minVersion[0]) + '.' + str(minVersion[1]))
  41. import wx
  42. version = wx.version().split(' ')[0]
  43. if map(int, version.split('.')) < minVersion:
  44. raise ValueError('Your wxPython version is %s.%s.%s.%s' % tuple(version.split('.')))
  45. except ImportError, e:
  46. print >> sys.stderr, 'ERROR: wxGUI requires wxPython. %s' % str(e)
  47. sys.exit(1)
  48. except (ValueError, wxversion.VersionError), e:
  49. print >> sys.stderr, 'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \
  50. '%s.' % (str(e))
  51. sys.exit(1)
  52. except locale.Error, e:
  53. print >> sys.stderr, "Unable to set locale:", e
  54. os.environ['LC_ALL'] = ''
  55. if not os.getenv("GRASS_WXBUNDLED"):
  56. CheckForWx()
  57. import wx
  58. import wx.lib.flatnotebook as FN
  59. """
  60. Query layer (generated for example by selecting item in the Attribute Table Manager)
  61. Deleted automatically on re-render action
  62. """
  63. # temporal query layer (removed on re-render action)
  64. QUERYLAYER = 'qlayer'
  65. """!Style definition for FlatNotebook pages"""
  66. FNPageStyle = FN.FNB_VC8 | \
  67. FN.FNB_BACKGROUND_GRADIENT | \
  68. FN.FNB_NODRAG | \
  69. FN.FNB_TABS_BORDER_SIMPLE
  70. FNPageDStyle = FN.FNB_FANCY_TABS | \
  71. FN.FNB_BOTTOM | \
  72. FN.FNB_NO_NAV_BUTTONS | \
  73. FN.FNB_NO_X_BUTTON
  74. FNPageColor = wx.Colour(125,200,175)
  75. """!Dialog widget dimension"""
  76. DIALOG_SPIN_SIZE = (150, -1)
  77. DIALOG_COMBOBOX_SIZE = (300, -1)
  78. DIALOG_GSELECT_SIZE = (400, -1)
  79. DIALOG_TEXTCTRL_SIZE = (400, -1)
  80. DIALOG_LAYER_SIZE = (100, -1)
  81. DIALOG_COLOR_SIZE = (30, 30)
  82. MAP_WINDOW_SIZE = (800, 600)
  83. GM_WINDOW_SIZE = (525, 600)
  84. if sys.platform == 'win32':
  85. BIN_EXT = '.exe'
  86. SCT_EXT = '.py'
  87. else:
  88. BIN_EXT = SCT_EXT = ''
  89. def UpdateGRASSAddOnCommands(eList = None):
  90. """!Update list of available GRASS AddOns commands to use when
  91. parsing string from the command line
  92. @param eList list of AddOns commands to remove
  93. """
  94. global grassCmd, grassScripts
  95. # scan addons (path)
  96. addonPath = os.getenv('GRASS_ADDON_PATH', '')
  97. addonBase = os.getenv('GRASS_ADDON_BASE')
  98. if addonBase:
  99. addonPath += os.pathsep + os.path.join(addonBase, 'bin') + os.pathsep + \
  100. os.path.join(addonBase, 'scripts')
  101. # remove commands first
  102. if eList:
  103. for ext in eList:
  104. if ext in grassCmd:
  105. grassCmd.remove(ext)
  106. Debug.msg(1, "Number of removed AddOn commands: %d", len(eList))
  107. nCmd = 0
  108. for path in addonPath.split(os.pathsep):
  109. if not os.path.exists(path) or not os.path.isdir(path):
  110. continue
  111. for fname in os.listdir(path):
  112. if fname in ['docs', 'modules.xml']:
  113. continue
  114. if grassScripts: # win32
  115. name, ext = os.path.splitext(fname)
  116. if name not in grassCmd:
  117. if ext not in [BIN_EXT, SCT_EXT]:
  118. continue
  119. if name not in grassCmd:
  120. grassCmd.add(name)
  121. Debug.msg(3, "AddOn commands: %s", name)
  122. nCmd += 1
  123. if ext == SCT_EXT and \
  124. ext in grassScripts.keys() and \
  125. name not in grassScripts[ext]:
  126. grassScripts[ext].append(name)
  127. else:
  128. if fname not in grassCmd:
  129. grassCmd.add(fname)
  130. Debug.msg(3, "AddOn commands: %s", fname)
  131. nCmd += 1
  132. Debug.msg(1, "Number of new AddOn commands: %d", nCmd)
  133. """@brief Collected GRASS-relared binaries/scripts"""
  134. grassCmd, grassScripts = get_commands()
  135. Debug.msg(1, "Number of GRASS commands: %d", len(grassCmd))
  136. UpdateGRASSAddOnCommands()
  137. """@Toolbar icon size"""
  138. toolbarSize = (24, 24)
  139. """@Is g.mlist available?"""
  140. if 'g.mlist' in grassCmd:
  141. have_mlist = True
  142. else:
  143. have_mlist = False
  144. """@Check version of wxPython, use agwStyle for 2.8.11+"""
  145. hasAgw = CheckWxVersion()