globalvar.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. CheckForWx()
  42. import wx
  43. import wx.lib.flatnotebook as FN
  44. try:
  45. import subprocess
  46. except:
  47. compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
  48. sys.path.append(compatPath)
  49. import subprocess
  50. """
  51. Query layer (generated for example by selecting item in the Attribute Table Manager)
  52. Deleted automatically on re-render action
  53. """
  54. # temporal query layer (removed on re-render action)
  55. QUERYLAYER = 'qlayer'
  56. # path to python scripts
  57. ETCDIR = os.path.join(os.getenv("GISBASE"), "etc")
  58. ETCWXDIR = os.path.join(ETCDIR, "wxpython")
  59. """Style definition for FlatNotebook pages"""
  60. FNPageStyle = FN.FNB_VC8 | \
  61. FN.FNB_BACKGROUND_GRADIENT | \
  62. FN.FNB_NODRAG | \
  63. FN.FNB_TABS_BORDER_SIMPLE
  64. FNPageColor = wx.Colour(125,200,175)
  65. """Dialog widget dimension"""
  66. DIALOG_SPIN_SIZE = (150, -1)
  67. DIALOG_COMBOBOX_SIZE = (300, -1)
  68. DIALOG_GSELECT_SIZE = (400, -1)
  69. DIALOG_TEXTCTRL_SIZE = (400, -1)
  70. MAP_WINDOW_SIZE = (680, 520)
  71. HIST_WINDOW_SIZE = (500, 350)
  72. MAP_DISPLAY_STATUSBAR_MODE = [_("Coordinates"),
  73. _("Extent"),
  74. _("Comp. region"),
  75. _("Show comp. extent"),
  76. _("Display mode"),
  77. _("Display geometry"),
  78. _("Map scale")]
  79. """File name extension binaries/scripts"""
  80. if subprocess.mswindows:
  81. EXT_BIN = '.exe'
  82. EXT_SCT = '.bat'
  83. else:
  84. EXT_BIN = ''
  85. EXT_SCT = ''
  86. def GetGRASSCmds(bin=True, scripts=True, gui_scripts=True):
  87. """
  88. Create list of all available GRASS commands to use when
  89. parsing string from the command line
  90. """
  91. gisbase = os.environ['GISBASE']
  92. list = []
  93. if bin is True:
  94. list = os.listdir(os.path.join(gisbase, 'bin'))
  95. if scripts is True:
  96. list = list + os.listdir(os.path.join(gisbase, 'scripts'))
  97. if gui_scripts is True:
  98. os.environ["PATH"] = os.getenv("PATH") + ':%s' % os.path.join(gisbase, 'etc', 'gui', 'scripts')
  99. list = list + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts'))
  100. if subprocess.mswindows:
  101. for idx in range(len(list)):
  102. list[idx] = list[idx].replace(EXT_BIN, '')
  103. list[idx] = list[idx].replace(EXT_SCT, '')
  104. return list
  105. """@brief Collected GRASS-relared binaries/scripts"""
  106. grassCmd = {}
  107. grassCmd['all'] = GetGRASSCmds()
  108. grassCmd['script'] = GetGRASSCmds(bin=False)
  109. """@Toolbar icon size"""
  110. toolbarSize = (24, 24)