globalvar.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. """
  2. MODULE: global.py
  3. PURPOSE: Global variables
  4. This module provide the space for global variables
  5. used in the code.
  6. AUTHOR(S): GRASS Development Team
  7. Martin Landa <landa.martin gmail.com>
  8. COPYRIGHT: (C) 2007 by the GRASS Development Team
  9. This program is free software under the GNU General Public
  10. License (>=v2). Read the file COPYING that comes with GRASS
  11. for details.
  12. """
  13. import os
  14. import sys
  15. import locale
  16. ### i18N
  17. import gettext
  18. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
  19. def CheckForWx():
  20. """Try to import wx module and check its version"""
  21. majorVersion = 2.8
  22. minorVersion = 1.1
  23. try:
  24. import wxversion
  25. wxversion.select(str(majorVersion))
  26. import wx
  27. version = wx.__version__
  28. if float(version[:3]) < majorVersion:
  29. raise ValueError('You are using wxPython version %s' % str(version))
  30. if float(version[:3]) == 2.8 and \
  31. float(version[4:]) < minorVersion:
  32. raise ValueError('You are using wxPython version %s' % str(version))
  33. except (ImportError, ValueError, wxversion.VersionError), e:
  34. print >> sys.stderr, 'ERROR: ' + str(e) + \
  35. '. wxPython >= %s.%s is required. Detailed information in README file.' % \
  36. (str(majorVersion), str(minorVersion))
  37. sys.exit(1)
  38. except locale.Error, e:
  39. print >> sys.stderr, "Unable to set locale:", e
  40. os.environ['LC_ALL'] = ''
  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)