globalvar.py 5.3 KB

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