[GRASS-SVN] r30398 - in grass/trunk/gui/wxpython: . gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Feb 29 06:55:29 EST 2008
Author: martinl
Date: 2008-02-29 06:55:28 -0500 (Fri, 29 Feb 2008)
New Revision: 30398
Modified:
grass/trunk/gui/wxpython/gui_modules/preferences.py
grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: fix reading/writing user settings from/to file (group settings introduced)
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-02-28 23:33:29 UTC (rev 30397)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-02-29 11:55:28 UTC (rev 30398)
@@ -30,13 +30,15 @@
import gcmd
import grassenv
import utils
+from debug import Debug as Debug
class Settings:
"""Generic class where to store settings"""
def __init__(self):
# filename for settings
self.fileName = ".grasswx"
-
+ self.filePath = None
+
# default settings
self.defaultSettings = {
#
@@ -101,10 +103,8 @@
self.userSettings = copy.deepcopy(self.defaultSettings)
try:
self.ReadSettingsFile()
- except IOError, e:
- raise gcmd.SettingsError(e)
- except:
- gcmd.SettingsError('Reading settings failed.')
+ except gcmd.GException, e:
+ raise gcmd.SettingsError(_('Reading settings failed\n\n%s.'), e)
# internal settings (based on user settings)
self.internalSettings = {}
@@ -139,19 +139,21 @@
gisdbase_file = os.path.join(gisdbase, self.fileName)
if os.path.isfile(mapset_file):
- self.__ReadFile(mapset_file)
+ self.filePath = mapset_file
elif os.path.isfile(location_file):
- self.__ReadFile(location_file)
+ self.filePath = location_file
elif os.path.isfile(gisdbase_file):
- self.__ReadFile(gisdbase_file)
-
+ self.filePath = gisdbase_file
+
+ if self.filePath:
+ self.__ReadFile(self.filePath)
+
def __ReadFile(self, filename, settings=None):
"""Read settings from file to dict"""
if settings is None:
settings = self.userSettings
try:
- # print '#', filename
file = open(filename, "r")
for line in file.readlines():
line = line.rstrip('%s' % os.linesep)
@@ -159,16 +161,36 @@
kv = line.split(':')[2:]
idx = 0
while idx < len(kv):
- # print group, key, kv[idx], kv[idx+1]
- # settings.Set(grou=group, key=key, subkey=kv[idx], value=kv[idx+1])
+ subkey = kv[idx]
+ value = kv[idx+1]
+ if len(value) == 0:
+ self.Set(group=group, key=key, subkey=subkey, value='')
+ else:
+ # casting
+ if value == 'True':
+ value = True
+ elif value == 'False':
+ value = False
+ elif value == 'None':
+ value = None
+ elif value[0] == '(':
+ tmp = value.replace('(','').replace(')', '').split(',')
+ try:
+ value = tuple(map(int, tmp))
+ except:
+ value = tuple(tmp)
+ else:
+ try:
+ value = int(value)
+ except:
+ pass
+ Debug.msg(3, 'Settings(): group=%s, key=%s, subkey=%s, value=%s' %
+ (group, key, subkey, value))
+ self.Set(group=group, key=key, subkey=subkey, value=value)
idx += 2
- except IOError, e:
- raise gcmd.SettingsError(e)
- except:
- raise gcmd.SettingsError(_('Reading settings from file <%s> failed.') % filename)
+ finally:
+ file.close()
- file.close()
-
def SaveToFile(self, settings=None):
"""Save settings to the file"""
if settings is None:
Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py 2008-02-28 23:33:29 UTC (rev 30397)
+++ grass/trunk/gui/wxpython/wxgui.py 2008-02-29 11:55:28 UTC (rev 30398)
@@ -70,12 +70,12 @@
except:
import compat.subprocess as subprocess
+import gui_modules.preferences as preferences
import gui_modules.wxgui_utils as wxgui_utils
import gui_modules.mapdisp as mapdisp
import gui_modules.menudata as menudata
import gui_modules.menuform as menuform
import gui_modules.grassenv as grassenv
-import gui_modules.preferences as preferences
import gui_modules.histogram as histogram
import gui_modules.profile as profile
import gui_modules.rules as rules
@@ -86,8 +86,9 @@
import gui_modules.globalvar as globalvar
from gui_modules.debug import Debug as Debug
from icons.icon import Icons as Icons
-from gui_modules.preferences import globalSettings as UserSettings
+UserSettings = preferences.globalSettings
+
class GMFrame(wx.Frame):
"""
GIS Manager frame with notebook widget for controlling
More information about the grass-commit
mailing list