globalvar.py 5.3 KB

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