globalvar.py 5.3 KB

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