|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 """! 00002 @package core.globalvar 00003 00004 @brief Global variables used by wxGUI 00005 00006 (C) 2007-2011 by the GRASS Development Team 00007 00008 This program is free software under the GNU General Public License 00009 (>=v2). Read the file COPYING that comes with GRASS for details. 00010 00011 @author Martin Landa <landa.martin gmail.com> 00012 """ 00013 00014 import os 00015 import sys 00016 import locale 00017 00018 if not os.getenv("GISBASE"): 00019 sys.exit("GRASS is not running. Exiting...") 00020 00021 # path to python scripts 00022 ETCDIR = os.path.join(os.getenv("GISBASE"), "etc") 00023 ETCICONDIR = os.path.join(os.getenv("GISBASE"), "etc", "gui", "icons") 00024 ETCWXDIR = os.path.join(ETCDIR, "wxpython") 00025 ETCIMGDIR = os.path.join(ETCDIR, "gui", "images") 00026 ETCSYMBOLDIR = os.path.join(ETCDIR, "gui", "images", "symbols") 00027 00028 sys.path.append(os.path.join(ETCDIR, "python")) 00029 import grass.script as grass 00030 00031 def CheckWxVersion(version = [2, 8, 11, 0]): 00032 """!Check wx version""" 00033 ver = wx.version().split(' ')[0] 00034 if map(int, ver.split('.')) < version: 00035 return False 00036 00037 return True 00038 00039 def CheckForWx(): 00040 """!Try to import wx module and check its version""" 00041 if 'wx' in sys.modules.keys(): 00042 return 00043 00044 minVersion = [2, 8, 1, 1] 00045 try: 00046 try: 00047 import wxversion 00048 except ImportError, e: 00049 raise ImportError(e) 00050 # wxversion.select(str(minVersion[0]) + '.' + str(minVersion[1])) 00051 wxversion.ensureMinimal(str(minVersion[0]) + '.' + str(minVersion[1])) 00052 import wx 00053 version = wx.version().split(' ')[0] 00054 00055 if map(int, version.split('.')) < minVersion: 00056 raise ValueError('Your wxPython version is %s.%s.%s.%s' % tuple(version.split('.'))) 00057 00058 except ImportError, e: 00059 print >> sys.stderr, 'ERROR: wxGUI requires wxPython. %s' % str(e) 00060 sys.exit(1) 00061 except (ValueError, wxversion.VersionError), e: 00062 print >> sys.stderr, 'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \ 00063 '%s.' % (str(e)) 00064 sys.exit(1) 00065 except locale.Error, e: 00066 print >> sys.stderr, "Unable to set locale:", e 00067 os.environ['LC_ALL'] = '' 00068 00069 if not os.getenv("GRASS_WXBUNDLED"): 00070 CheckForWx() 00071 import wx 00072 import wx.lib.flatnotebook as FN 00073 00074 """ 00075 Query layer (generated for example by selecting item in the Attribute Table Manager) 00076 Deleted automatically on re-render action 00077 """ 00078 # temporal query layer (removed on re-render action) 00079 QUERYLAYER = 'qlayer' 00080 00081 """!Style definition for FlatNotebook pages""" 00082 FNPageStyle = FN.FNB_VC8 | \ 00083 FN.FNB_BACKGROUND_GRADIENT | \ 00084 FN.FNB_NODRAG | \ 00085 FN.FNB_TABS_BORDER_SIMPLE 00086 00087 FNPageDStyle = FN.FNB_FANCY_TABS | \ 00088 FN.FNB_BOTTOM | \ 00089 FN.FNB_NO_NAV_BUTTONS | \ 00090 FN.FNB_NO_X_BUTTON 00091 00092 FNPageColor = wx.Colour(125,200,175) 00093 00094 """!Dialog widget dimension""" 00095 DIALOG_SPIN_SIZE = (150, -1) 00096 DIALOG_COMBOBOX_SIZE = (300, -1) 00097 DIALOG_GSELECT_SIZE = (400, -1) 00098 DIALOG_TEXTCTRL_SIZE = (400, -1) 00099 DIALOG_LAYER_SIZE = (100, -1) 00100 DIALOG_COLOR_SIZE = (30, 30) 00101 00102 MAP_WINDOW_SIZE = (800, 600) 00103 GM_WINDOW_SIZE = (500, 600) 00104 00105 def GetGRASSCommands(): 00106 """!Create list of available GRASS commands to use when parsing 00107 string from the command line 00108 00109 @return list of commands (set) and directory of scripts (collected 00110 by extension - MS Windows only) 00111 """ 00112 gisbase = os.environ['GISBASE'] 00113 cmd = list() 00114 if sys.platform == 'win32': 00115 scripts = { '.bat' : list(), 00116 '.py' : list() 00117 } 00118 else: 00119 scripts = {} 00120 00121 # scan bin/ 00122 if os.path.exists(os.path.join(gisbase, 'bin')): 00123 for fname in os.listdir(os.path.join(gisbase, 'bin')): 00124 if scripts: # win32 00125 name, ext = os.path.splitext(fname) 00126 if ext != '.manifest': 00127 cmd.append(name) 00128 if ext in scripts.keys(): 00129 scripts[ext].append(name) 00130 else: 00131 cmd.append(fname) 00132 00133 # scan scripts/ (not on MS Windows) 00134 if not scripts and os.path.exists(os.path.join(gisbase, 'scripts')): 00135 for fname in os.listdir(os.path.join(gisbase, 'scripts')): 00136 cmd.append(fname) 00137 00138 # scan gui/scripts/ 00139 if os.path.exists(os.path.join(gisbase, 'etc', 'gui', 'scripts')): 00140 os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'gui', 'scripts') 00141 os.environ["PATH"] = os.getenv("PATH") + os.pathsep + os.path.join(gisbase, 'etc', 'wxpython', 'scripts') 00142 00143 pattern = "_wrapper" 00144 for script in os.listdir(os.path.join(gisbase, 'etc', 'gui', 'scripts')): 00145 if script[-len(pattern):] != pattern: # ignore wrappers 00146 cmd.append(script) 00147 00148 # scan addons (path) 00149 if os.getenv('GRASS_ADDON_PATH'): 00150 for path in os.getenv('GRASS_ADDON_PATH').split(os.pathsep): 00151 if not os.path.exists(path) or not os.path.isdir(path): 00152 continue 00153 for fname in os.listdir(path): 00154 if scripts: # win32 00155 name, ext = os.path.splitext(fname) 00156 cmd.append(name) 00157 if ext in scripts.keys(): 00158 scripts[ext].append(name) 00159 else: 00160 cmd.append(fname) 00161 00162 return set(cmd), scripts 00163 00164 """@brief Collected GRASS-relared binaries/scripts""" 00165 grassCmd, grassScripts = GetGRASSCommands() 00166 00167 """@Toolbar icon size""" 00168 toolbarSize = (24, 24) 00169 00170 """@Is g.mlist available?""" 00171 if 'g.mlist' in grassCmd: 00172 have_mlist = True 00173 else: 00174 have_mlist = False 00175 00176 """@Check version of wxPython, use agwStyle for 2.8.11+""" 00177 hasAgw = CheckWxVersion()