globalvar.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. import wx
  47. version = wx.version().split(' ')[0]
  48. if map(int, version.split('.')) < minVersion:
  49. raise ValueError('Your wxPython version is %s.%s.%s.%s' % tuple(version.split('.')))
  50. except ImportError, e:
  51. print >> sys.stderr, 'ERROR: wxGUI requires wxPython. %s' % str(e)
  52. sys.exit(1)
  53. except (ValueError, wxversion.VersionError), e:
  54. print >> sys.stderr, 'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \
  55. '%s.' % (str(e))
  56. sys.exit(1)
  57. except locale.Error, e:
  58. print >> sys.stderr, "Unable to set locale:", e
  59. os.environ['LC_ALL'] = ''
  60. check = False
  61. if not os.getenv("GRASS_WXBUNDLED"):
  62. CheckForWx()
  63. import wx
  64. import wx.lib.flatnotebook as FN
  65. """
  66. Query layer (generated for example by selecting item in the Attribute Table Manager)
  67. Deleted automatically on re-render action
  68. """
  69. # temporal query layer (removed on re-render action)
  70. QUERYLAYER = 'qlayer'
  71. """!Style definition for FlatNotebook pages"""
  72. FNPageStyle = FN.FNB_VC8 | \
  73. FN.FNB_BACKGROUND_GRADIENT | \
  74. FN.FNB_NODRAG | \
  75. FN.FNB_TABS_BORDER_SIMPLE
  76. FNPageDStyle = FN.FNB_FANCY_TABS | \
  77. FN.FNB_BOTTOM | \
  78. FN.FNB_NO_NAV_BUTTONS | \
  79. FN.FNB_NO_X_BUTTON
  80. FNPageColor = wx.Colour(125,200,175)
  81. """!Dialog widget dimension"""
  82. DIALOG_SPIN_SIZE = (150, -1)
  83. DIALOG_COMBOBOX_SIZE = (300, -1)
  84. DIALOG_GSELECT_SIZE = (400, -1)
  85. DIALOG_TEXTCTRL_SIZE = (400, -1)
  86. DIALOG_LAYER_SIZE = (100, -1)
  87. DIALOG_COLOR_SIZE = (30, 30)
  88. MAP_WINDOW_SIZE = (800, 600)
  89. HIST_WINDOW_SIZE = (500, 350)
  90. GM_WINDOW_SIZE = (575, 600)
  91. MAP_DISPLAY_STATUSBAR_MODE = [_("Coordinates"),
  92. _("Extent"),
  93. _("Comp. region"),
  94. _("Show comp. extent"),
  95. _("Display mode"),
  96. _("Display geometry"),
  97. _("Map scale"),
  98. _("Go to"),
  99. _("Projection"),]
  100. """!File name extension binaries/scripts"""
  101. if sys.platform == 'win32':
  102. EXT_BIN = '.exe'
  103. EXT_SCT = '.py'
  104. else:
  105. EXT_BIN = ''
  106. EXT_SCT = ''
  107. def GetGRASSCmds(bin = True, scripts = True, gui_scripts = True):
  108. """!Create list of available GRASS commands to use when parsing
  109. string from the command line
  110. @param bin True to include executable into list
  111. @param scripts True to include scripts into list
  112. @param gui_scripts True to include GUI scripts into list
  113. """
  114. gisbase = os.environ['GISBASE']
  115. cmd = list()
  116. if bin:
  117. for executable in os.listdir(os.path.join(gisbase, 'bin')):
  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. # add special call for setting vector colors
  123. cmd.append('vcolors')
  124. if scripts:
  125. cmd = cmd + os.listdir(os.path.join(gisbase, 'scripts'))
  126. if gui_scripts:
  127. os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'gui', 'scripts')
  128. cmd = cmd + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts'))
  129. if sys.platform == 'win32':
  130. for idx in range(len(cmd)):
  131. name, ext = os.path.splitext(cmd[idx])
  132. if ext in (EXT_BIN, EXT_SCT):
  133. cmd[idx] = name
  134. return cmd
  135. """@brief Collected GRASS-relared binaries/scripts"""
  136. grassCmd = {}
  137. grassCmd['all'] = GetGRASSCmds()
  138. grassCmd['script'] = GetGRASSCmds(bin = False, gui_scripts = 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()