2 @package core.globalvar
4 @brief Global variables used by wxGUI
6 (C) 2007-2012 by the GRASS Development Team
8 This program is free software under the GNU General Public License
9 (>=v2). Read the file COPYING that comes with GRASS for details.
11 @author Martin Landa <landa.martin gmail.com>
18 if not os.getenv(
"GISBASE"):
19 sys.exit(
"GRASS is not running. Exiting...")
22 ETCDIR = os.path.join(os.getenv(
"GISBASE"),
"etc")
23 ETCICONDIR = os.path.join(os.getenv(
"GISBASE"),
"etc",
"gui",
"icons")
24 ETCWXDIR = os.path.join(ETCDIR,
"wxpython")
25 ETCIMGDIR = os.path.join(ETCDIR,
"gui",
"images")
26 ETCSYMBOLDIR = os.path.join(ETCDIR,
"gui",
"images",
"symbols")
30 sys.path.append(os.path.join(ETCDIR,
"python"))
34 """!Check wx version"""
36 if map(int, ver.split(
'.')) < version:
42 """!Try to import wx module and check its version"""
43 if 'wx' in sys.modules.keys():
46 minVersion = [2, 8, 1, 1]
51 except ImportError, e:
54 wxversion.ensureMinimal(str(minVersion[0]) +
'.' + str(minVersion[1]))
56 version = wx.__version__
58 if map(int, version.split(
'.')) < minVersion:
59 raise ValueError(
'Your wxPython version is %s.%s.%s.%s' % tuple(version.split(
'.')))
61 except ImportError, e:
62 print >> sys.stderr,
'ERROR: wxGUI requires wxPython. %s' % str(e)
64 except (ValueError, wxversion.VersionError), e:
65 print >> sys.stderr,
'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \
68 except locale.Error, e:
69 print >> sys.stderr,
"Unable to set locale:", e
70 os.environ[
'LC_ALL'] =
''
72 if not os.getenv(
"GRASS_WXBUNDLED"):
75 import wx.lib.flatnotebook
as FN
78 Query layer (generated for example by selecting item in the Attribute Table Manager)
79 Deleted automatically on re-render action
84 """!Style definition for FlatNotebook pages"""
85 FNPageStyle = FN.FNB_VC8 | \
86 FN.FNB_BACKGROUND_GRADIENT | \
88 FN.FNB_TABS_BORDER_SIMPLE
90 FNPageDStyle = FN.FNB_FANCY_TABS | \
92 FN.FNB_NO_NAV_BUTTONS | \
95 FNPageColor = wx.Colour(125,200,175)
97 """!Dialog widget dimension"""
98 DIALOG_SPIN_SIZE = (150, -1)
99 DIALOG_COMBOBOX_SIZE = (300, -1)
100 DIALOG_GSELECT_SIZE = (400, -1)
101 DIALOG_TEXTCTRL_SIZE = (400, -1)
102 DIALOG_LAYER_SIZE = (100, -1)
103 DIALOG_COLOR_SIZE = (30, 30)
105 MAP_WINDOW_SIZE = (800, 600)
106 GM_WINDOW_SIZE = (500, 600)
108 if sys.platform ==
'win32':
112 BIN_EXT = SCT_EXT =
''
115 """!Create list of available GRASS commands to use when parsing
116 string from the command line
118 @return list of commands (set) and directory of scripts (collected
119 by extension - MS Windows only)
121 gisbase = os.environ[
'GISBASE']
123 if sys.platform ==
'win32':
124 scripts = { SCT_EXT : list() }
129 if os.path.exists(os.path.join(gisbase,
'bin')):
130 for fname
in os.listdir(os.path.join(gisbase,
'bin')):
132 name, ext = os.path.splitext(fname)
133 if ext !=
'.manifest':
135 if ext
in scripts.keys():
136 scripts[ext].append(name)
141 if not scripts
and os.path.exists(os.path.join(gisbase,
'scripts')):
142 for fname
in os.listdir(os.path.join(gisbase,
'scripts')):
146 if os.path.exists(os.path.join(gisbase,
'etc',
'gui',
'scripts')):
147 os.environ[
"PATH"] = os.getenv(
"PATH") + os.pathsep + os.path.join(gisbase,
'etc',
'gui',
'scripts')
148 os.environ[
"PATH"] = os.getenv(
"PATH") + os.pathsep + os.path.join(gisbase,
'etc',
'wxpython',
'scripts')
151 for script
in os.listdir(os.path.join(gisbase,
'etc',
'gui',
'scripts')):
152 if script[-len(pattern):] != pattern:
155 return set(cmd), scripts
158 """!Update list of available GRASS AddOns commands to use when
159 parsing string from the command line
161 @param eList list of AddOns commands to remove
163 global grassCmd, grassScripts
166 if not os.getenv(
'GRASS_ADDON_PATH'):
174 Debug.msg(1,
"Number of removed AddOn commands: %d", len(eList))
177 for path
in os.getenv(
'GRASS_ADDON_PATH').
split(os.pathsep):
178 if not os.path.exists(path)
or not os.path.isdir(path):
180 for fname
in os.listdir(path):
181 if fname
in [
'docs',
'modules.xml']:
184 name, ext = os.path.splitext(fname)
185 if ext
not in [BIN_EXT, SCT_EXT]:
187 if name
not in grassCmd:
189 Debug.msg(3,
"AddOn commands: %s", name)
191 if ext == SCT_EXT
and \
192 ext
in grassScripts.keys()
and \
193 name
not in grassScripts[ext]:
194 grassScripts[ext].append(name)
196 if fname
not in grassCmd:
198 Debug.msg(3,
"AddOn commands: %s", fname)
201 Debug.msg(1,
"Number of new AddOn commands: %d", nCmd)
206 language = os.getenv(
'LANG')
210 language = language.split(
'.')[0]
211 orig_language = language
213 locale.setlocale(locale.LC_ALL, language)
214 except locale.Error, e:
215 if sys.platform !=
'win32':
222 language = locale.normalize(
'%s.UTF-8' % (language))
223 locale.setlocale(locale.LC_ALL, language)
224 except locale.Error, e:
227 sys.stderr.write(
"Failed to set LC_ALL to %s (%s)\n" % (language, e))
239 for lc
in (
'LC_CTYPE',
'LC_MESSAGES',
'LC_TIME',
'LC_COLLATE',
'LC_MONETARY',
'LC_PAPER',
240 'LC_NAME',
'LC_ADDRESS',
'LC_TELEPHONE',
'LC_MEASUREMENT',
'LC_IDENTIFICATION'):
241 os.environ[lc] = language
243 Debug.msg(1,
"Language setttings: (WX) %s / (GRASS) %s", language, orig_language)
247 locale.setlocale(locale.LC_NUMERIC,
'C')
248 os.environ[
'LC_NUMERIC'] =
'C'
249 if os.getenv(
'LC_ALL'):
250 del os.environ[
'LC_ALL']
256 os.environ[
'LANGUAGE'] = orig_language
257 os.environ[
'LANG'] = orig_language
259 """@brief Collected GRASS-relared binaries/scripts"""
261 Debug.msg(1,
"Number of GRASS commands: %d", len(grassCmd))
264 """@Toolbar icon size"""
265 toolbarSize = (24, 24)
267 """@Is g.mlist available?"""
268 if 'g.mlist' in grassCmd:
273 """@Check version of wxPython, use agwStyle for 2.8.11+"""
def CheckForWx()
Try to import wx module and check its version.
def split(s)
Platform spefic shlex.split.
def CheckWxVersion(version=[2)
Check wx version.
def GetGRASSCommands()
Create list of available GRASS commands to use when parsing string from the command line...
def UpdateGRASSAddOnCommands
Update list of available GRASS AddOns commands to use when parsing string from the command line...