[GRASS-SVN] r51781 - in grass/branches/releasebranch_6_4:
gui/wxpython/core gui/wxpython/gui_core lib/init
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat May 26 09:41:57 EDT 2012
Author: neteler
Date: 2012-05-26 06:41:56 -0700 (Sat, 26 May 2012)
New Revision: 51781
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py
grass/branches/releasebranch_6_4/gui/wxpython/gui_core/preferences.py
grass/branches/releasebranch_6_4/lib/init/init.sh
Log:
backport of wxGUI language selector (bat update missing for Windows)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py 2012-05-26 12:58:28 UTC (rev 51780)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py 2012-05-26 13:41:56 UTC (rev 51781)
@@ -16,12 +16,14 @@
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Martin Landa <landa.martin gmail.com>
+ at author Luca Delucchi <lucadeluge gmail.com> (language choice)
"""
import os
import sys
import copy
import types
+import locale
from core import globalvar
from core.gcmd import GException, GError
@@ -48,7 +50,29 @@
# define internal settings
self._internalSettings() # -> self.internalSettings
+
+ def _generateLocale(self):
+ """!Generate locales
+ """
+ # collect available locales
+ self.locs = list(set(locale.locale_alias.values()))
+ self.locs.append('en_GB.UTF-8')
+ self.locs.sort()
+ try:
+ loc = list(locale.getdefaultlocale())
+ except ValueError, e:
+ sys.stderr.write(_('ERROR: %s\n') % str(e))
+ return 'C'
+
+ if loc[1] == 'UTF8':
+ loc[1] = 'UTF-8'
+ code_loc = "%s.%s" % (loc[0], loc[1])
+ if code_loc in self.locs:
+ return code_loc
+
+ return 'C'
+
def _defaultSettings(self):
"""!Define default settings
"""
@@ -57,6 +81,8 @@
except KeyError:
projFile = ''
+ id_loc = self._generateLocale()
+
self.defaultSettings = {
#
# general
@@ -127,6 +153,14 @@
}, # grass2, grass, silk
},
#
+ # language
+ #
+ 'language': {
+ 'locale': {
+ 'lc_all' : id_loc
+ }
+ },
+ #
# display
#
'display': {
@@ -675,6 +709,8 @@
_("Collapse all except current"),
_("Collapse all"),
_("Expand all"))
+
+ self.internalSettings['language']['locale']['choices'] = tuple(self.locs)
self.internalSettings['atm']['leftDbClick']['choices'] = (_('Edit selected record'),
_('Display selected'))
@@ -967,10 +1003,10 @@
"""
if group not in dict:
dict[group] = {}
-
+
if key not in dict[group]:
dict[group][key] = {}
-
+
if type(subkey) == types.ListType:
# TODO: len(subkey) > 2
if subkey[0] not in dict[group][key]:
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_core/preferences.py 2012-05-26 12:58:28 UTC (rev 51780)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_core/preferences.py 2012-05-26 13:41:56 UTC (rev 51781)
@@ -23,11 +23,13 @@
@author Michael Barton (Arizona State University)
@author Martin Landa <landa.martin gmail.com>
@author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
+ at author Luca Delucchi <lucadeluge gmail.com> (language choice)
"""
import os
import sys
import copy
+import locale
try:
import pwd
havePwd = True
@@ -44,7 +46,7 @@
from core import globalvar
from core.gcmd import RunCommand
-from core.utils import ListOfMapsets, GetColorTables, ReadEpsgCodes
+from core.utils import ListOfMapsets, GetColorTables, ReadEpsgCodes, GetSettingsPath
from core.settings import UserSettings
wxSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent()
@@ -127,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':
@@ -152,7 +155,7 @@
def OnCancel(self, event):
"""!Button 'Cancel' pressed"""
self.Close()
-
+
def OnSave(self, event):
"""!Button 'Save' pressed
Posts event EVT_SETTINGS_CHANGED.
@@ -160,6 +163,9 @@
if self._updateSettings():
self.settings.SaveToFile()
self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
+ lang = UserSettings.Get(group = 'language', key = 'locale', subkey = 'lc_all')
+ if lang:
+ RunCommand('g.gisenv', set = 'LANG=%s' % lang)
event = wxSettingsChanged()
wx.PostEvent(self, event)
self.Close()
@@ -408,6 +414,36 @@
pos = (row, 1))
#
+ # languages
+ #
+ box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Language settings"))
+ sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+ gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
+ gridSizer.AddGrowableCol(0)
+ sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
+ border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
+
+ row = 0
+ gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+ label = _("Choose language (requires to save and GRASS restart):")),
+ flag = wx.ALIGN_LEFT |
+ wx.ALIGN_CENTER_VERTICAL,
+ pos = (row, 0))
+ 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 = locales, name = "GetStringSelection")
+ if loc in locales:
+ elementList.SetStringSelection(loc)
+ self.winId['language:locale:lc_all'] = elementList.GetId()
+
+ gridSizer.Add(item = elementList,
+ flag = wx.ALIGN_RIGHT |
+ wx.ALIGN_CENTER_VERTICAL,
+ pos = (row, 1))
+ #
# appearence
#
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Appearance settings"))
@@ -443,7 +479,7 @@
#
row += 1
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Menu style (requires GUI restart):")),
+ label = _("Menu style (requires to save and GUI restart):")),
flag = wx.ALIGN_LEFT |
wx.ALIGN_CENTER_VERTICAL,
pos = (row, 0))
@@ -589,7 +625,6 @@
flag = wx.ALIGN_RIGHT,
pos = (row, 1))
-
#
# Statusbar mode
#
@@ -1195,7 +1230,6 @@
winCode.SetValue('')
win.SetValue('')
-
try:
win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
except KeyError:
@@ -1450,7 +1484,6 @@
title = _('Manage access to mapsets'),
size = (350, 400),
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
-
wx.Dialog.__init__(self, parent, id, title, size = size, style = style, **kwargs)
self.all_mapsets_ordered = ListOfMapsets(get = 'ordered')
Modified: grass/branches/releasebranch_6_4/lib/init/init.sh
===================================================================
--- grass/branches/releasebranch_6_4/lib/init/init.sh 2012-05-26 12:58:28 UTC (rev 51780)
+++ grass/branches/releasebranch_6_4/lib/init/init.sh 2012-05-26 13:41:56 UTC (rev 51781)
@@ -232,7 +232,12 @@
if [ -f "$GISRC" ] ; then
GRASS_GUI=`awk '/GRASS_GUI/ {print $2}' "$GISRC"`
fi
-
+
+ # Check for a reference to the language in the grassrc file
+ if [ -f "$GISRC" ] ; then
+ LANG=`awk '/LANG/ {print $2}' "$GISRC"`
+ fi
+
# Set the GRASS user interface to the default if needed
if [ ! "$GRASS_GUI" ] ; then
GRASS_GUI="$DEFAULT_GUI"
More information about the grass-commit
mailing list