"""! @package global.py @brief Global variables This module provide the space for global variables used in the code. (C) 2007-2010 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details. @author Martin Landa """ import os import sys import locale ### i18N import gettext gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True) # path to python scripts ETCDIR = os.path.join(os.getenv("GISBASE"), "etc") ETCICONDIR = os.path.join(os.getenv("GISBASE"), "etc", "gui", "icons") ETCWXDIR = os.path.join(ETCDIR, "wxpython") sys.path.append(os.path.join(ETCDIR, "python")) import grass.script as grass # wxversion.select() called once at the beginning check = True def CheckForWx(): """!Try to import wx module and check its version""" global check if not check: return minVersion = [2, 8, 1, 1] try: try: import wxversion except ImportError, e: raise ImportError(e) wxversion.select(str(minVersion[0]) + '.' + str(minVersion[1])) import wx version = wx.version().split(' ')[0] if map(int, version.split('.')) < minVersion: raise ValueError('Your wxPython version is %s.%s.%s.%s' % tuple(version.split('.'))) except ImportError, e: print >> sys.stderr, 'ERROR: wxGUI requires wxPython. %s' % str(e) sys.exit(1) except (ValueError, wxversion.VersionError), e: print >> sys.stderr, 'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \ '%s.' % (str(e)) sys.exit(1) except locale.Error, e: print >> sys.stderr, "Unable to set locale:", e os.environ['LC_ALL'] = '' check = False if not os.getenv("GRASS_WXBUNDLED"): CheckForWx() import wx import wx.lib.flatnotebook as FN try: import subprocess except: compatPath = os.path.join(globalvar.ETCWXDIR, "compat") sys.path.append(compatPath) import subprocess """ Query layer (generated for example by selecting item in the Attribute Table Manager) Deleted automatically on re-render action """ # temporal query layer (removed on re-render action) QUERYLAYER = 'qlayer' """!Style definition for FlatNotebook pages""" FNPageStyle = FN.FNB_VC8 | \ FN.FNB_BACKGROUND_GRADIENT | \ FN.FNB_NODRAG | \ FN.FNB_TABS_BORDER_SIMPLE FNPageColor = wx.Colour(125,200,175) """!Dialog widget dimension""" DIALOG_SPIN_SIZE = (150, -1) DIALOG_COMBOBOX_SIZE = (300, -1) DIALOG_GSELECT_SIZE = (400, -1) DIALOG_TEXTCTRL_SIZE = (400, -1) DIALOG_LAYER_SIZE = (100, -1) DIALOG_COLOR_SIZE = (30, 30) MAP_WINDOW_SIZE = (770, 570) HIST_WINDOW_SIZE = (500, 350) MAP_DISPLAY_STATUSBAR_MODE = [_("Coordinates"), _("Extent"), _("Comp. region"), _("Show comp. extent"), _("Display mode"), _("Display geometry"), _("Map scale"), _("Go to"), _("Projection"),] """!File name extension binaries/scripts""" if subprocess.mswindows: EXT_BIN = '.exe' EXT_SCT = '.py' else: EXT_BIN = '' EXT_SCT = '' def GetGRASSCmds(bin=True, scripts=True, gui_scripts=True): """!Create list of all available GRASS commands to use when parsing string from the command line """ gisbase = os.environ['GISBASE'] cmd = list() if bin is True: for file in os.listdir(os.path.join(gisbase, 'bin')): if not EXT_BIN or file[-4:] == EXT_BIN: cmd.append(file) # add special call for setting vector colors cmd.append('vcolors') if scripts is True: cmd = cmd + os.listdir(os.path.join(gisbase, 'scripts')) if gui_scripts is True: os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'gui', 'scripts') cmd = cmd + os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts')) if subprocess.mswindows: for idx in range(len(cmd)): cmd[idx] = cmd[idx].replace(EXT_BIN, '') cmd[idx] = cmd[idx].replace(EXT_SCT, '') return cmd """@brief Collected GRASS-relared binaries/scripts""" grassCmd = {} grassCmd['all'] = GetGRASSCmds() grassCmd['script'] = GetGRASSCmds(bin=False) """@Toolbar icon size""" toolbarSize = (24, 24) """@Is g.mlist available?""" if 'g.mlist' in grassCmd['all']: have_mlist = True else: have_mlist = False def _getGDALFormats(): """!Get dictionary of avaialble GDAL drivers""" if not grass.find_program('r.in.gdal'): return _parseFormats(None) ret = grass.read_command('r.in.gdal', quiet = True, flags = 'f') return _parseFormats(ret) def _getOGRFormats(): """!Get dictionary of avaialble OGR drivers""" if not grass.find_program('v.in.ogr'): return _parseFormats(None) ret = grass.read_command('v.in.ogr', quiet = True, flags = 'f') return _parseFormats(ret) def _parseFormats(output): """!Parse r.in.gdal/v.in.ogr -f output""" formats = { 'file' : list(), 'database' : list(), 'protocol' : list() } if not output: return formats for line in output.splitlines(): format = line.strip().rsplit(':', -1)[1].strip() if format in ('Memory', 'Virtual Raster', 'In Memory Raster'): continue if format in ('PostgreSQL', 'SQLite', 'ODBC', 'ESRI Personal GeoDatabase', 'Rasterlite', 'PostGIS WKT Raster driver'): formats['database'].append(format) elif format in ('GeoJSON', 'OGC Web Coverage Service', 'OGC Web Map Service', 'HTTP Fetching Wrapper'): formats['protocol'].append(format) else: formats['file'].append(format) return formats formats = { 'gdal' : _getGDALFormats(), 'ogr' : _getOGRFormats() }