globalvar.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. """!
  2. @package global.py
  3. @brief Global variables
  4. This module provide the space for global variables
  5. used in the code.
  6. (C) 2007-2010 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. import locale
  14. if not os.getenv("GISBASE"):
  15. sys.exit("GRASS is not running. Exiting...")
  16. ### i18N
  17. import gettext
  18. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
  19. # path to python scripts
  20. ETCDIR = os.path.join(os.getenv("GISBASE"), "etc")
  21. ETCICONDIR = os.path.join(os.getenv("GISBASE"), "etc", "gui", "icons")
  22. ETCWXDIR = os.path.join(ETCDIR, "gui", "wxpython")
  23. sys.path.append(os.path.join(ETCDIR, "python"))
  24. import grass.script as grass
  25. # wxversion.select() called once at the beginning
  26. check = True
  27. def CheckWxVersion(version = [2, 8, 11, 0]):
  28. """!Check wx version"""
  29. ver = wx.version().split(' ')[0]
  30. if map(int, ver.split('.')) < version:
  31. return False
  32. return True
  33. def CheckForWx():
  34. """!Try to import wx module and check its version"""
  35. global check
  36. if not check:
  37. return
  38. minVersion = [2, 8, 1, 1]
  39. try:
  40. try:
  41. import wxversion
  42. except ImportError, e:
  43. raise ImportError(e)
  44. wxversion.select(str(minVersion[0]) + '.' + str(minVersion[1]))
  45. import wx
  46. version = wx.version().split(' ')[0]
  47. if map(int, version.split('.')) < minVersion:
  48. raise ValueError('Your wxPython version is %s.%s.%s.%s' % tuple(version.split('.')))
  49. except ImportError, e:
  50. print >> sys.stderr, 'ERROR: wxGUI requires wxPython. %s' % str(e)
  51. sys.exit(1)
  52. except (ValueError, wxversion.VersionError), e:
  53. print >> sys.stderr, 'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \
  54. '%s.' % (str(e))
  55. sys.exit(1)
  56. except locale.Error, e:
  57. print >> sys.stderr, "Unable to set locale:", e
  58. os.environ['LC_ALL'] = ''
  59. check = False
  60. if not os.getenv("GRASS_WXBUNDLED"):
  61. CheckForWx()
  62. import wx
  63. import wx.lib.flatnotebook as FN
  64. try:
  65. import subprocess
  66. except:
  67. compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
  68. sys.path.append(compatPath)
  69. import subprocess
  70. """
  71. Query layer (generated for example by selecting item in the Attribute Table Manager)
  72. Deleted automatically on re-render action
  73. """
  74. # temporal query layer (removed on re-render action)
  75. QUERYLAYER = 'qlayer'
  76. """!Style definition for FlatNotebook pages"""
  77. FNPageStyle = FN.FNB_VC8 | \
  78. FN.FNB_BACKGROUND_GRADIENT | \
  79. FN.FNB_NODRAG | \
  80. FN.FNB_TABS_BORDER_SIMPLE
  81. FNPageDStyle = FN.FNB_FANCY_TABS | \
  82. FN.FNB_BOTTOM | \
  83. FN.FNB_NO_NAV_BUTTONS | \
  84. FN.FNB_NO_X_BUTTON
  85. FNPageColor = wx.Colour(125,200,175)
  86. """!Dialog widget dimension"""
  87. DIALOG_SPIN_SIZE = (150, -1)
  88. DIALOG_COMBOBOX_SIZE = (300, -1)
  89. DIALOG_GSELECT_SIZE = (400, -1)
  90. DIALOG_TEXTCTRL_SIZE = (400, -1)
  91. DIALOG_LAYER_SIZE = (100, -1)
  92. DIALOG_COLOR_SIZE = (30, 30)
  93. MAP_WINDOW_SIZE = (770, 570)
  94. HIST_WINDOW_SIZE = (500, 350)
  95. MAP_DISPLAY_STATUSBAR_MODE = [_("Coordinates"),
  96. _("Extent"),
  97. _("Comp. region"),
  98. _("Show comp. extent"),
  99. _("Display mode"),
  100. _("Display geometry"),
  101. _("Map scale"),
  102. _("Go to"),
  103. _("Projection"),]
  104. """!File name extension binaries/scripts"""
  105. if subprocess.mswindows:
  106. EXT_BIN = '.exe'
  107. EXT_SCT = '.py'
  108. else:
  109. EXT_BIN = ''
  110. EXT_SCT = ''
  111. def GetGRASSCmds(bin = True, scripts = True, gui_scripts = True):
  112. """!Create list of all available GRASS commands to use when
  113. parsing string from the command line
  114. """
  115. gisbase = os.environ['GISBASE']
  116. cmd = list()
  117. if bin is True:
  118. for file in os.listdir(os.path.join(gisbase, 'bin')):
  119. if not EXT_BIN or \
  120. file[-4:] == EXT_BIN or \
  121. file[-4:] == EXT_SCT:
  122. cmd.append(file)
  123. # add special call for setting vector colors
  124. cmd.append('vcolors')
  125. if scripts:
  126. cmd = cmd + os.listdir(os.path.join(gisbase, 'scripts'))
  127. if gui_scripts:
  128. os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'gui', 'scripts')
  129. cmd = cmd + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts'))
  130. if subprocess.mswindows:
  131. for idx in range(len(cmd)):
  132. if cmd[idx][-4:] in (EXT_BIN, EXT_SCT):
  133. cmd[idx] = cmd[idx][:-4]
  134. return cmd
  135. """@brief Collected GRASS-relared binaries/scripts"""
  136. grassCmd = {}
  137. grassCmd['all'] = GetGRASSCmds()
  138. grassCmd['script'] = GetGRASSCmds(bin = False)
  139. """@Toolbar icon size"""
  140. toolbarSize = (24, 24)
  141. """@Is g.mlist available?"""
  142. if 'g.mlist' in grassCmd['all']:
  143. have_mlist = True
  144. else:
  145. have_mlist = False
  146. """@Check version of wxPython, use agwStyle for 2.8.11+"""
  147. hasAgw = CheckWxVersion()
  148. """@List of commands for auto-rendering"""
  149. cmdAutoRender = [ 'r.colors', 'i.landsat.rgb' ]