globalvar.py 5.1 KB

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