globalvar.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. """
  65. Query layer (generated for example by selecting item in the Attribute Table Manager)
  66. Deleted automatically on re-render action
  67. """
  68. # temporal query layer (removed on re-render action)
  69. QUERYLAYER = 'qlayer'
  70. """!Style definition for FlatNotebook pages"""
  71. FNPageStyle = FN.FNB_VC8 | \
  72. FN.FNB_BACKGROUND_GRADIENT | \
  73. FN.FNB_NODRAG | \
  74. FN.FNB_TABS_BORDER_SIMPLE
  75. FNPageDStyle = FN.FNB_FANCY_TABS | \
  76. FN.FNB_BOTTOM | \
  77. FN.FNB_NO_NAV_BUTTONS | \
  78. FN.FNB_NO_X_BUTTON
  79. FNPageColor = wx.Colour(125,200,175)
  80. """!Dialog widget dimension"""
  81. DIALOG_SPIN_SIZE = (150, -1)
  82. DIALOG_COMBOBOX_SIZE = (300, -1)
  83. DIALOG_GSELECT_SIZE = (400, -1)
  84. DIALOG_TEXTCTRL_SIZE = (400, -1)
  85. DIALOG_LAYER_SIZE = (100, -1)
  86. DIALOG_COLOR_SIZE = (30, 30)
  87. MAP_WINDOW_SIZE = (800, 600)
  88. HIST_WINDOW_SIZE = (500, 350)
  89. GM_WINDOW_SIZE = (575, 600)
  90. MAP_DISPLAY_STATUSBAR_MODE = [_("Coordinates"),
  91. _("Extent"),
  92. _("Comp. region"),
  93. _("Show comp. extent"),
  94. _("Display mode"),
  95. _("Display geometry"),
  96. _("Map scale"),
  97. _("Go to"),
  98. _("Projection"),]
  99. """!File name extension binaries/scripts"""
  100. if sys.platform == 'win32':
  101. EXT_BIN = '.exe'
  102. EXT_SCT = '.py'
  103. else:
  104. EXT_BIN = ''
  105. EXT_SCT = ''
  106. def GetGRASSCmds(bin = True, scripts = True, gui_scripts = True):
  107. """!Create list of available GRASS commands to use when parsing
  108. string from the command line
  109. @param bin True to include executable into list
  110. @param scripts True to include scripts into list
  111. @param gui_scripts True to include GUI scripts into list
  112. """
  113. gisbase = os.environ['GISBASE']
  114. cmd = list()
  115. if bin:
  116. for executable in os.listdir(os.path.join(gisbase, 'bin')):
  117. ext = os.path.splitext(executable)[1]
  118. if not EXT_BIN or \
  119. ext in (EXT_BIN, EXT_SCT):
  120. cmd.append(executable)
  121. # add special call for setting vector colors
  122. cmd.append('vcolors')
  123. if scripts:
  124. cmd = cmd + os.listdir(os.path.join(gisbase, 'scripts'))
  125. if gui_scripts:
  126. os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'gui', 'scripts')
  127. cmd = cmd + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts'))
  128. if sys.platform == 'win32':
  129. for idx in range(len(cmd)):
  130. name, ext = os.path.splitext(cmd[idx])
  131. if ext in (EXT_BIN, EXT_SCT):
  132. cmd[idx] = name
  133. return cmd
  134. """@brief Collected GRASS-relared binaries/scripts"""
  135. grassCmd = {}
  136. grassCmd['all'] = GetGRASSCmds()
  137. grassCmd['script'] = GetGRASSCmds(bin = False, gui_scripts = False)
  138. """@Toolbar icon size"""
  139. toolbarSize = (24, 24)
  140. """@Is g.mlist available?"""
  141. if 'g.mlist' in grassCmd['all']:
  142. have_mlist = True
  143. else:
  144. have_mlist = False
  145. """@Check version of wxPython, use agwStyle for 2.8.11+"""
  146. hasAgw = CheckWxVersion()