globalvar.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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-2009 by the GRASS Development Team
  7. This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. @author Martin Landa <landa.martin gmail.com>
  11. """
  12. import os
  13. import sys
  14. import locale
  15. ### i18N
  16. import gettext
  17. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
  18. # wxversion.select() called once at the beginning
  19. check = True
  20. def CheckForWx():
  21. """!Try to import wx module and check its version"""
  22. global check
  23. if not check:
  24. return
  25. minVersion = [2, 8, 1, 1]
  26. try:
  27. try:
  28. import wxversion
  29. except ImportError, e:
  30. raise ImportError(e)
  31. wxversion.select(str(minVersion[0]) + '.' + str(minVersion[1]))
  32. import wx
  33. version = wx.version().split(' ')[0]
  34. if map(int, version.split('.')) < minVersion:
  35. raise ValueError('Your wxPython version is %s.%s.%s.%s' % tuple(version.split('.')))
  36. except ImportError, e:
  37. print >> sys.stderr, 'ERROR: wxGUI requires wxPython. %s' % str(e)
  38. sys.exit(1)
  39. except (ValueError, wxversion.VersionError), e:
  40. print >> sys.stderr, 'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \
  41. '%s.' % (str(e))
  42. sys.exit(1)
  43. except locale.Error, e:
  44. print >> sys.stderr, "Unable to set locale:", e
  45. os.environ['LC_ALL'] = ''
  46. check = False
  47. if not os.getenv("GRASS_WXBUNDLED"):
  48. CheckForWx()
  49. import wx
  50. import wx.lib.flatnotebook as FN
  51. try:
  52. import subprocess
  53. except:
  54. compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
  55. sys.path.append(compatPath)
  56. import subprocess
  57. """
  58. Query layer (generated for example by selecting item in the Attribute Table Manager)
  59. Deleted automatically on re-render action
  60. """
  61. # temporal query layer (removed on re-render action)
  62. QUERYLAYER = 'qlayer'
  63. # path to python scripts
  64. ETCDIR = os.path.join(os.getenv("GISBASE"), "etc")
  65. ETCICONDIR = os.path.join(os.getenv("GISBASE"), "etc", "gui", "icons")
  66. ETCWXDIR = os.path.join(ETCDIR, "gui", "wxpython")
  67. """!Style definition for FlatNotebook pages"""
  68. FNPageStyle = FN.FNB_VC8 | \
  69. FN.FNB_BACKGROUND_GRADIENT | \
  70. FN.FNB_NODRAG | \
  71. FN.FNB_TABS_BORDER_SIMPLE
  72. FNPageColor = wx.Colour(125,200,175)
  73. """!Dialog widget dimension"""
  74. DIALOG_SPIN_SIZE = (150, -1)
  75. DIALOG_COMBOBOX_SIZE = (300, -1)
  76. DIALOG_GSELECT_SIZE = (400, -1)
  77. DIALOG_TEXTCTRL_SIZE = (400, -1)
  78. DIALOG_LAYER_SIZE = (100, -1)
  79. MAP_WINDOW_SIZE = (770, 570)
  80. HIST_WINDOW_SIZE = (500, 350)
  81. MAP_DISPLAY_STATUSBAR_MODE = [_("Coordinates"),
  82. _("Extent"),
  83. _("Comp. region"),
  84. _("Show comp. extent"),
  85. _("Display mode"),
  86. _("Display geometry"),
  87. _("Map scale"),
  88. _("Go to"),
  89. _("Projection"),]
  90. """!File name extension binaries/scripts"""
  91. if subprocess.mswindows:
  92. EXT_BIN = '.exe'
  93. EXT_SCT = '.bat'
  94. else:
  95. EXT_BIN = ''
  96. EXT_SCT = ''
  97. def GetGRASSCmds(bin=True, scripts=True, gui_scripts=True):
  98. """!Create list of all available GRASS commands to use when
  99. parsing string from the command line
  100. """
  101. gisbase = os.environ['GISBASE']
  102. cmd = list()
  103. if bin is True:
  104. for file in os.listdir(os.path.join(gisbase, 'bin')):
  105. if not EXT_BIN or file[-4:] == EXT_BIN:
  106. cmd.append(file)
  107. # add special call for setting vector colors
  108. cmd.append('vcolors')
  109. if scripts is True:
  110. cmd = cmd + os.listdir(os.path.join(gisbase, 'scripts'))
  111. if gui_scripts is True:
  112. os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'gui', 'scripts')
  113. cmd = cmd + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts'))
  114. if subprocess.mswindows:
  115. for idx in range(len(cmd)):
  116. cmd[idx] = cmd[idx].replace(EXT_BIN, '')
  117. cmd[idx] = cmd[idx].replace(EXT_SCT, '')
  118. return cmd
  119. """@brief Collected GRASS-relared binaries/scripts"""
  120. grassCmd = {}
  121. grassCmd['all'] = GetGRASSCmds()
  122. grassCmd['script'] = GetGRASSCmds(bin=False)
  123. """@Toolbar icon size"""
  124. toolbarSize = (24, 24)
  125. """@Is g.mlist available?"""
  126. if 'g.mlist' in grassCmd['all']:
  127. have_mlist = True
  128. else:
  129. have_mlist = False