globalvar.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. def CheckForWx():
  17. """Try to import wx module and check its version"""
  18. majorVersion = 2.8
  19. minorVersion = 1.1
  20. try:
  21. import wxversion
  22. wxversion.select(str(majorVersion))
  23. import wx
  24. version = wx.__version__
  25. if float(version[:3]) < majorVersion:
  26. raise ValueError('You are using wxPython version %s' % str(version))
  27. if float(version[:3]) == 2.8 and \
  28. float(version[4:]) < minorVersion:
  29. raise ValueError('You are using wxPython version %s' % str(version))
  30. except (ImportError, ValueError, wxversion.VersionError), e:
  31. print >> sys.stderr, 'ERROR: ' + str(e) + \
  32. '. wxPython >= %s.%s is required. Detailed information in README file.' % \
  33. (str(majorVersion), str(minorVersion))
  34. sys.exit(1)
  35. except locale.Error, e:
  36. print >> sys.stderr, "Unable to set locale:", e
  37. os.environ['LC_ALL'] = ''
  38. CheckForWx()
  39. import wx
  40. import wx.lib.flatnotebook as FN
  41. try:
  42. import subprocess
  43. except:
  44. compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
  45. sys.path.append(compatPath)
  46. import subprocess
  47. """
  48. Query layer (generated for example by selecting item in the Attribute Table Manager)
  49. Deleted automatically on re-render action
  50. """
  51. # temporal query layer (removed on re-render action)
  52. QUERYLAYER = 'qlayer'
  53. # path to python scripts
  54. ETCDIR = os.path.join(os.getenv("GISBASE"), "etc")
  55. ETCWXDIR = os.path.join(ETCDIR, "wxpython")
  56. """Style definition for FlatNotebook pages"""
  57. FNPageStyle = FN.FNB_VC8 | \
  58. FN.FNB_BACKGROUND_GRADIENT | \
  59. FN.FNB_NODRAG | \
  60. FN.FNB_TABS_BORDER_SIMPLE
  61. FNPageColor = wx.Colour(125,200,175)
  62. """Dialog widget dimension"""
  63. DIALOG_SPIN_SIZE = (150, -1)
  64. DIALOG_COMBOBOX_SIZE = (300, -1)
  65. DIALOG_GSELECT_SIZE = (400, -1)
  66. DIALOG_TEXTCTRL_SIZE = (400, -1)
  67. MAP_WINDOW_SIZE = (680, 520)
  68. HIST_WINDOW_SIZE = (500, 350)
  69. """File name extension binaries/scripts"""
  70. if subprocess.mswindows:
  71. EXT_BIN = '.exe'
  72. EXT_SCT = '.bat'
  73. else:
  74. EXT_BIN = ''
  75. EXT_SCT = ''
  76. def GetGRASSCmds(bin=True, scripts=True, gui_scripts=True):
  77. """
  78. Create list of all available GRASS commands to use when
  79. parsing string from the command line
  80. """
  81. gisbase = os.environ['GISBASE']
  82. list = []
  83. if bin is True:
  84. list = os.listdir(os.path.join(gisbase, 'bin'))
  85. if scripts is True:
  86. list = list + os.listdir(os.path.join(gisbase, 'scripts'))
  87. if gui_scripts is True:
  88. os.environ["PATH"] = os.getenv("PATH") + ':%s' % os.path.join(gisbase, 'etc', 'gui', 'scripts')
  89. list = list + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts'))
  90. if subprocess.mswindows:
  91. for idx in range(len(list)):
  92. list[idx] = list[idx].replace(EXT_BIN, '')
  93. list[idx] = list[idx].replace(EXT_SCT, '')
  94. return list
  95. """@brief Collected GRASS-relared binaries/scripts"""
  96. grassCmd = {}
  97. grassCmd['all'] = GetGRASSCmds()
  98. grassCmd['script'] = GetGRASSCmds(bin=False)
  99. """@Toolbar icon size"""
  100. toolbarSize = (24, 24)