globalvar.py 4.2 KB

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