globalvar.py 5.3 KB

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