[GRASS-SVN] r49712 - in grass/trunk/gui/wxpython: core gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Dec 13 08:31:04 EST 2011
Author: martinl
Date: 2011-12-13 05:31:04 -0800 (Tue, 13 Dec 2011)
New Revision: 49712
Modified:
grass/trunk/gui/wxpython/core/settings.py
grass/trunk/gui/wxpython/gui_core/preferences.py
Log:
wxGUI/language settings: store alias not its index (which can change)
Modified: grass/trunk/gui/wxpython/core/settings.py
===================================================================
--- grass/trunk/gui/wxpython/core/settings.py 2011-12-13 13:02:36 UTC (rev 49711)
+++ grass/trunk/gui/wxpython/core/settings.py 2011-12-13 13:31:04 UTC (rev 49712)
@@ -61,12 +61,10 @@
self.locs = list(set(locale.locale_alias.values()))
self.locs.append('en_GB.UTF-8')
self.locs.sort()
- try:
- return locs.index(code_loc)
- except:
- pass
+ if code_loc in self.locs:
+ return code_loc
- return None
+ return 'C'
def _defaultSettings(self):
"""!Define default settings
Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py 2011-12-13 13:02:36 UTC (rev 49711)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py 2011-12-13 13:31:04 UTC (rev 49712)
@@ -129,6 +129,7 @@
group, key, subkey, subkey1 = gks.split(':')
value = self.settings.Get(group, key, [subkey, subkey1])
win = self.FindWindowById(self.winId[gks])
+
if win.GetName() in ('GetValue', 'IsChecked'):
value = win.SetValue(value)
elif win.GetName() == 'GetSelection':
@@ -154,7 +155,37 @@
def OnCancel(self, event):
"""!Button 'Cancel' pressed"""
self.Close()
+
+ def _saveEnv(self, lang):
+ """!Save environmental variables
+
+ @param lang locale code (eg. 'C')
+ """
+ envFile = os.path.join(GetSettingsPath(), 'bashrc')
+ # read variables
+ if os.path.exists(envFile):
+ rcfile = open(os.path.join(GetSettingsPath(), 'bashrc'), "r")
+ rclines = rcfile.readlines()
+ rcfile.close()
+ else:
+ rclines = []
+
+ rcfile = open(envFile, "w")
+
+ # save language settings
+ grasslang = False
+ for line in rclines:
+ if 'GRASS_LANG' in line:
+ rcfile.write('GRASS_LANG: %s\n' % lang)
+ grasslang = True
+ else:
+ rcfile.write(line)
+ if not grasslang:
+ rcfile.write('GRASS_LANG: %s\n' % lang)
+
+ rcfile.close()
+
def OnSave(self, event):
"""!Button 'Save' pressed
Posts event EVT_SETTINGS_CHANGED.
@@ -164,21 +195,9 @@
self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
fileSettings = {}
self.settings.ReadSettingsFile(settings = fileSettings)
- id_loc = fileSettings['language']['locale']['lc_all']
- rcfile = open(os.path.join(GetSettingsPath(), 'bashrc'),"r")
- rclines = rcfile.readlines()
- rcfile.close()
- rcfile = open(os.path.join(GetSettingsPath(), 'bashrc'),"w")
- grasslang = False
- for line in rclines:
- if 'GRASS_LANG' in line:
- rcfile.write('GRASS_LANG: %s\n' % self.locales[id_loc])
- grasslang = True
- else:
- rcfile.write('%s' % line)
- if not grasslang:
- rcfile.write('GRASS_LANG: %s\n' % self.locales[id_loc])
- rcfile.close()
+
+ self._saveEnv(lang = fileSettings['language']['locale']['lc_all'])
+
event = wxSettingsChanged()
wx.PostEvent(self, event)
self.Close()
@@ -443,14 +462,13 @@
flag = wx.ALIGN_LEFT |
wx.ALIGN_CENTER_VERTICAL,
pos = (row, 0))
- self.locales = self.settings.Get(group = 'language', key = 'locale',
- subkey = 'choices', internal = True)
+ locales = self.settings.Get(group = 'language', key = 'locale',
+ subkey = 'choices', internal = True)
+ loc = self.settings.Get(group = 'language', key = 'locale', subkey = 'lc_all')
elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
- choices = self.locales, name = "GetSelection")
- if self.settings.Get(group = 'language', key = 'locale',
- subkey = 'lc_all'):
- elementList.SetSelection(self.settings.Get(group = 'language',
- key = 'locale', subkey = 'lc_all'))
+ choices = locales, name = "GetStringSelection")
+ if loc in locales:
+ elementList.SetStringSelection(loc)
self.winId['language:locale:lc_all'] = elementList.GetId()
gridSizer.Add(item = elementList,
More information about the grass-commit
mailing list