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"""
35 ver = wx.version().
split(
' ')[0]
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]
47 unsupportedVersion = [2, 9, 0, 0]
51 except ImportError, e:
54 wxversion.ensureMinimal(str(minVersion[0]) +
'.' + str(minVersion[1]))
56 version = wx.version().
split(
' ')[0]
58 if map(int, version.split(
'.')) < minVersion:
59 raise ValueError(
'Your wxPython version is %s.%s.%s.%s' % tuple(version.split(
'.')))
60 if map(int, version.split(
'.')) >= unsupportedVersion:
61 print >> sys.stderr,
'ERROR: wxGUI does not support wxPython %s yet.' % version
63 except ImportError, e:
64 print >> sys.stderr,
'ERROR: wxGUI requires wxPython. %s' % str(e)
66 except (ValueError, wxversion.VersionError), e:
67 print >> sys.stderr,
'ERROR: wxGUI requires wxPython >= %d.%d.%d.%d. ' % tuple(minVersion) + \
70 except locale.Error, e:
71 print >> sys.stderr,
"Unable to set locale:", e
72 os.environ[
'LC_ALL'] =
''
74 if not os.getenv(
"GRASS_WXBUNDLED"):
77 import wx.lib.flatnotebook
as FN
80 Query layer (generated for example by selecting item in the Attribute Table Manager)
81 Deleted automatically on re-render action
86 """!Style definition for FlatNotebook pages"""
87 FNPageStyle = FN.FNB_VC8 | \
88 FN.FNB_BACKGROUND_GRADIENT | \
90 FN.FNB_TABS_BORDER_SIMPLE
92 FNPageDStyle = FN.FNB_FANCY_TABS | \
94 FN.FNB_NO_NAV_BUTTONS | \
97 FNPageColor = wx.Colour(125,200,175)
99 """!Dialog widget dimension"""
100 DIALOG_SPIN_SIZE = (150, -1)
101 DIALOG_COMBOBOX_SIZE = (300, -1)
102 DIALOG_GSELECT_SIZE = (400, -1)
103 DIALOG_TEXTCTRL_SIZE = (400, -1)
104 DIALOG_LAYER_SIZE = (100, -1)
105 DIALOG_COLOR_SIZE = (30, 30)
107 MAP_WINDOW_SIZE = (800, 600)
108 GM_WINDOW_SIZE = (500, 600)
110 if sys.platform ==
'win32':
114 BIN_EXT = SCT_EXT =
''
117 """!Create list of available GRASS commands to use when parsing
118 string from the command line
120 @return list of commands (set) and directory of scripts (collected
121 by extension - MS Windows only)
123 gisbase = os.environ[
'GISBASE']
125 if sys.platform ==
'win32':
126 scripts = { SCT_EXT : list() }
131 if os.path.exists(os.path.join(gisbase,
'bin')):
132 for fname
in os.listdir(os.path.join(gisbase,
'bin')):
134 name, ext = os.path.splitext(fname)
135 if ext !=
'.manifest':
137 if ext
in scripts.keys():
138 scripts[ext].append(name)
143 if not scripts
and os.path.exists(os.path.join(gisbase,
'scripts')):
144 for fname
in os.listdir(os.path.join(gisbase,
'scripts')):
148 if os.path.exists(os.path.join(gisbase,
'etc',
'gui',
'scripts')):
149 os.environ[
"PATH"] = os.getenv(
"PATH") + os.pathsep + os.path.join(gisbase,
'etc',
'gui',
'scripts')
150 os.environ[
"PATH"] = os.getenv(
"PATH") + os.pathsep + os.path.join(gisbase,
'etc',
'wxpython',
'scripts')
153 for script
in os.listdir(os.path.join(gisbase,
'etc',
'gui',
'scripts')):
154 if script[-len(pattern):] != pattern:
157 return set(cmd), scripts
160 """!Update list of available GRASS AddOns commands to use when
161 parsing string from the command line
163 @param eList list of AddOns commands to remove
165 global grassCmd, grassScripts
168 if not os.getenv(
'GRASS_ADDON_PATH'):
176 Debug.msg(1,
"Number of removed AddOn commands: %d", len(eList))
179 for path
in os.getenv(
'GRASS_ADDON_PATH').
split(os.pathsep):
180 if not os.path.exists(path)
or not os.path.isdir(path):
182 for fname
in os.listdir(path):
183 if fname
in [
'docs',
'modules.xml']:
186 name, ext = os.path.splitext(fname)
187 if ext
not in [BIN_EXT, SCT_EXT]:
189 if name
not in grassCmd:
191 Debug.msg(3,
"AddOn commands: %s", name)
193 if ext == SCT_EXT
and \
194 ext
in grassScripts.keys()
and \
195 name
not in grassScripts[ext]:
196 grassScripts[ext].append(name)
198 if fname
not in grassCmd:
200 Debug.msg(3,
"AddOn commands: %s", fname)
203 Debug.msg(1,
"Number of new AddOn commands: %d", nCmd)
208 language = os.getenv(
'LANG')
212 language = language.split(
'.')[0]
213 orig_language = language
215 locale.setlocale(locale.LC_ALL, language)
216 except locale.Error, e:
217 if sys.platform !=
'win32':
224 language = locale.normalize(
'%s.UTF-8' % (language))
225 locale.setlocale(locale.LC_ALL, language)
226 except locale.Error, e:
229 sys.stderr.write(
"Failed to set LC_ALL to %s (%s)\n" % (language, e))
241 for lc
in (
'LC_CTYPE',
'LC_MESSAGES',
'LC_TIME',
'LC_COLLATE',
'LC_MONETARY',
'LC_PAPER',
242 'LC_NAME',
'LC_ADDRESS',
'LC_TELEPHONE',
'LC_MEASUREMENT',
'LC_IDENTIFICATION'):
243 os.environ[lc] = language
245 Debug.msg(1,
"Language setttings: (WX) %s / (GRASS) %s", language, orig_language)
249 locale.setlocale(locale.LC_NUMERIC,
'C')
250 os.environ[
'LC_NUMERIC'] =
'C'
251 if os.getenv(
'LC_ALL'):
252 del os.environ[
'LC_ALL']
258 os.environ[
'LANGUAGE'] = orig_language
259 os.environ[
'LANG'] = orig_language
261 """@brief Collected GRASS-relared binaries/scripts"""
263 Debug.msg(1,
"Number of GRASS commands: %d", len(grassCmd))
266 """@Toolbar icon size"""
267 toolbarSize = (24, 24)
269 """@Is g.mlist available?"""
270 if 'g.mlist' in grassCmd:
275 """@Check version of wxPython, use agwStyle for 2.8.11+"""