[GRASS-SVN] r30471 - in grass/trunk/gui/wxpython: gui_modules icons

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 4 17:32:54 EST 2008


Author: martinl
Date: 2008-03-04 17:32:53 -0500 (Tue, 04 Mar 2008)
New Revision: 30471

Modified:
   grass/trunk/gui/wxpython/gui_modules/dbm.py
   grass/trunk/gui/wxpython/gui_modules/digit.py
   grass/trunk/gui/wxpython/gui_modules/gcmd.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/icons/icon.py
Log:
wxGUI (preferences) use internal dict for window ids, cosmetics in variable names, fix atm settings group

Modified: grass/trunk/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/dbm.py	2008-03-04 21:31:39 UTC (rev 30470)
+++ grass/trunk/gui/wxpython/gui_modules/dbm.py	2008-03-04 22:32:53 UTC (rev 30471)
@@ -526,8 +526,13 @@
             win.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnDataItemActivated)
             win.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnDataRightUp) #wxMSW
             win.Bind(wx.EVT_RIGHT_UP,            self.OnDataRightUp) #wxGTK
-            win.Bind(wx.EVT_LEFT_DCLICK, self.OnDataItemEdit)
-            win.Bind(wx.EVT_COMMAND_LEFT_DCLICK, self.OnDataItemEdit)
+            if UserSettings.Get(group='atm', key='leftDbClick', subkey='selection') == 0:
+                win.Bind(wx.EVT_LEFT_DCLICK, self.OnDataItemEdit)
+                win.Bind(wx.EVT_COMMAND_LEFT_DCLICK, self.OnDataItemEdit)
+            else:
+                win.Bind(wx.EVT_LEFT_DCLICK, self.OnDataDrawSelected)
+                win.Bind(wx.EVT_COMMAND_LEFT_DCLICK, self.OnDataDrawSelected)
+                
             
             listSizer.Add(item=win, proportion=1,
                           flag=wx.EXPAND | wx.ALL,

Modified: grass/trunk/gui/wxpython/gui_modules/digit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/digit.py	2008-03-04 21:31:39 UTC (rev 30470)
+++ grass/trunk/gui/wxpython/gui_modules/digit.py	2008-03-04 22:32:53 UTC (rev 30471)
@@ -61,7 +61,7 @@
     #          (os.linesep, err)
 
 # which interface to use?
-if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') == 'vedit' and GV_LINES is not None:
+if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit' and GV_LINES is not None:
     print >> sys.stderr, "%sWARNING: Digitization tool uses v.edit interface. " \
         "This can significantly slow down some operations especially for " \
         "middle-large vector maps. "\
@@ -98,7 +98,7 @@
         UserSettings.Set(group='vdigit', key='category', subkey='value', value=1)
 
         if self.map:
-            if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') == 'vedit':
+            if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
                 categoryCmd = gcmd.Command(cmd=["v.category", "-g", "--q",
                                                 "input=%s" % self.map, 
                                                 "option=report"])
@@ -153,7 +153,7 @@
                                     'Data are probably corrupted, '
                                     'try to run v.build for rebuilding the topology.') % map)
             
-        if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') != 'v.edit':
+        if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') != 'v.edit':
             try:
                 self.digit.InitCats()
             except:
@@ -1019,7 +1019,7 @@
 
         return (snap, thresh)
 
-if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') == 'vedit':
+if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
     class Digit(VEdit):
         """Default digit class"""
         def __init__(self, mapwindow):
@@ -1122,7 +1122,7 @@
         if map:
             name, mapset = map.split('@')
             try:
-                if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') == 'vedit':
+                if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
                     ret = self.__display.OpenMap(str(name), str(mapset), False)
                 else:
                     ret = self.__display.OpenMap(str(name), str(mapset), True)
@@ -2181,7 +2181,7 @@
                             cat not in cats[1][layer]:
                         catList.append(cat)
                 if catList != []:
-                    if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') == 'vedit':
+                    if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
                         vEditCmd = ['v.edit', '--q',
                                     'map=%s' % self.map,
                                     'layer=%d' % layer,
@@ -2200,7 +2200,7 @@
                         if self.line < 0:
                             wx.MessageBox(parent=self, message=_("Unable to update vector map."),
                                           caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
-        if UserSettings.Get(group='advanced', key='digitInterface', subkey='value') == 'vedit':           
+        if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':           
             # reload map (needed for v.edit)
             self.parent.parent.digit.driver.ReloadMap()
 

Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-03-04 21:31:39 UTC (rev 30470)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-03-04 22:32:53 UTC (rev 30471)
@@ -74,25 +74,33 @@
 
     See Command class (command exits with EXIT_FAILURE,
     G_fatal_error() is called)."""
-    def __init__(self, cmd, message):
+    def __init__(self, cmd, message, parent=None):
         self.cmd = cmd
-        GException.__init__(self, message, title=_("Error in command execution %s" % self.cmd[0]))
+        GException.__init__(self, message,
+                            title=_("Error in command execution %s" % self.cmd[0]),
+                            parent=parent)
 
 class SettingsError(GException):
     """Exception used for GRASS settings, see
     gui_modules/preferences.py."""
-    def __init__(self, message):
-        GException.__init__(self, message, title=_("Preferences error"))
+    def __init__(self, message, parent=None):
+        GException.__init__(self, message,
+                            title=_("Preferences error"),
+                            parent=parent)
 
 class DigitError(GException):
     """Exception raised during digitization session"""
-    def __init__(self, message):
-        GException.__init__(self, message, title=_("Error in digitization tool"))
+    def __init__(self, message, parent=None):
+        GException.__init__(self, message,
+                            title=_("Error in digitization tool"),
+                            parent=parent)
 
 class DBMError(GException):
     """Exception raised for Attribute Table Manager"""
     def __init__(self, message):
-        GException.__init__(self, message, title=_("Error in Attribute Table Manager"))
+        GException.__init__(self, message,
+                            title=_("Error in Attribute Table Manager"),
+                            parent=parent)
 
 class Popen(subprocess.Popen):
     """Subclass subprocess.Popen"""

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-03-04 21:31:39 UTC (rev 30470)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-03-04 22:32:53 UTC (rev 30471)
@@ -63,9 +63,9 @@
             # advanced
             #
             'advanced' : {
-                'settingsFile'   : { 'value' : 'gisdbase' }, # gisdbase, location, mapset
-                'digitInterface' : { 'value' : 'vdigit' }, # vedit, vdigit
-                'iconTheme'      : { 'value' : 'silk' }, # grass, silk
+                'settingsFile'   : { 'type' : 'gisdbase' }, # gisdbase, location, mapset
+                'digitInterface' : { 'type' : 'vdigit' }, # vedit, vdigit
+                'iconTheme'      : { 'type' : 'silk' }, # grass, silk
                 },
             #
             # Attribute Table Manager
@@ -136,8 +136,7 @@
             self.internalSettings[group] = {}
             for key in self.userSettings[group].keys():
                 self.internalSettings[group][key] = {}
-                self.internalSettings[group][key]['subkey'] = None # subkey in userSettings dict
-                self.internalSettings[group][key]['winId'] = None  # widget ID
+
         self.internalSettings['general']["mapsetPath"]['value'] = self.GetMapsetPath()
         self.internalSettings['general']['mapsetPath']['choices'] = [_('Mapset search path'),
                                                                      _('All available mapsets')]
@@ -235,7 +234,7 @@
         if settings is None:
             settings = self.userSettings
         
-        loc = self.Get(group='advanced', key='settingsFile', subkey='value')
+        loc = self.Get(group='advanced', key='settingsFile', subkey='type')
         gisdbase = grassenv.GetGRASSVariable("GISDBASE")
         location_name = grassenv.GetGRASSVariable("LOCATION_NAME")
         mapset_name = grassenv.GetGRASSVariable("MAPSET")
@@ -248,7 +247,7 @@
             filePath = os.path.join(gisdbase, location_name, mapset_name, self.fileName)
         
         if filePath is None:
-            raise gcmd.SettingsError('Uknown file location.')
+            raise gcmd.SettingsError(_('Uknown settings file location.'))
 
         try:
             file = open(filePath, "w")
@@ -316,7 +315,7 @@
                 raise KeyError
             settings[group][key][subkey] = value
         except KeyError:
-            raise gcmd.SettingsError(_("Unable to set '%s:%s:%s'") % (group, key, subkey))
+            raise gcmd.SettingsError(_("Unable to set '%s:%s:%s'") % (group, key, subkey),)
 
 globalSettings = Settings()
 
@@ -334,6 +333,9 @@
         # notebook
         notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
 
+        # dict for window ids
+        self.winId = {}
+
         # create notebook pages
         self.__CreateGeneralPage(notebook)
         self.__CreateDisplayPage(notebook)
@@ -395,8 +397,7 @@
                                     choices=self.settings.Get(group='general', key='mapsetPath', subkey='choices', internal=True),
                                     name="GetSelection")
         mapsetPath.SetSelection(self.settings.Get(group='general', key='mapsetPath', subkey='selection'))
-        self.settings.Set(group='general', key='mapsetPath', subkey='winId', value=mapsetPath.GetId(), internal=True)
-        self.settings.Set(group='general', key='mapsetPath', subkey='subkey', value='selection', internal=True)
+        self.winId['general:mapsetPath:selection'] = mapsetPath.GetId()
         
         gridSizer.Add(item=mapsetPath,
                       flag=wx.ALIGN_RIGHT |
@@ -458,8 +459,7 @@
                                     label=_("Overlay raster map layers"),
                                     name='IsChecked')
         rasterOverlay.SetValue(self.settings.Get(group='display', key='rasterOverlay', subkey='enabled'))
-        self.settings.Set(group='display', key='rasterOverlay', subkey='winId', value=rasterOverlay.GetId(), internal=True)
-        self.settings.Set(group='display', key='rasterOverlay', subkey='subkey', value='enabled', internal=True)
+        self.winId['display:rasterOverlay:enabled'] = rasterOverlay.GetId()
 
         gridSizer.Add(item=rasterOverlay,
                       pos=(row, 0), span=(1, 2))
@@ -493,20 +493,21 @@
         label = wx.StaticText(parent=panel, id=wx.ID_ANY, label="Color")
         hlColor = csel.ColourSelect(parent=panel, id=wx.ID_ANY,
                                     colour=self.settings.Get(group='atm', key='highlight', subkey='color'),
-                                    size=(25, 25),
-                                    name="GetValue")
-        
+                                    size=(25, 25))
+        self.winId['atm:highlight:color'] = hlColor.GetId()
+
         flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
-        flexSizer.Add(self.hlColor, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
+        flexSizer.Add(hlColor, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
 
         label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Line width (in pixels)"))
-        self.hlWidth = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(50, -1),
-                                   initial=self.settings.Get(group='atm', key='highlight',subkey='width'),
-                                   min=1, max=1e6)
+        hlWidth = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(50, -1),
+                              initial=self.settings.Get(group='atm', key='highlight',subkey='width'),
+                              min=1, max=1e6)
+        self.winId['atm:highlight:width'] = hlWidth.GetId()
+
         flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
-        flexSizer.Add(self.hlWidth, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
+        flexSizer.Add(hlWidth, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
 
-
         highlightSizer.Add(item=flexSizer,
                            proportion=0,
                            flag=wx.ALL | wx.EXPAND,
@@ -526,13 +527,13 @@
 
         flexSizer = wx.FlexGridSizer (cols=2, hgap=5, vgap=5)
         flexSizer.AddGrowableCol(0)
-        label = wx.StaticText(parent=panel, id=wx.ID_ANY, label="Left double click")
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Left mouse double click"))
         leftDbClick = wx.Choice(parent=panel, id=wx.ID_ANY,
                                 choices=self.settings.Get(group='atm', key='leftDbClick', subkey='choices', internal=True),
                                 name="GetSelection")
         leftDbClick.SetSelection(self.settings.Get(group='atm', key='leftDbClick', subkey='selection'))
-        self.settings.Set(group='atm', key='leftDbClick', subkey='winId', value=leftDbClick.GetId(), internal=True)
-        self.settings.Set(group='atm', key='leftDbClick', subkey='subkey', value='selection', internal=True)
+        self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
+
         flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
         flexSizer.Add(leftDbClick, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
 
@@ -575,9 +576,8 @@
         settingsFile = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
                                  choices=self.settings.Get(group='advanced', key='settingsFile', subkey='choices', internal=True),
                                  name='GetStringSelection')
-        settingsFile.SetStringSelection(self.settings.Get(group='advanced', key='settingsFile', subkey='value'))
-        self.settings.Set(group='advanced', key='settingsFile', subkey='winId', value=settingsFile.GetId(), internal=True)
-        self.settings.Set(group='advanced', key='settingsFile', subkey='subkey', value='value', internal=True)
+        settingsFile.SetStringSelection(self.settings.Get(group='advanced', key='settingsFile', subkey='type'))
+        self.winId['advanced:settingsFile:type'] = settingsFile.GetId()
 
         gridSizer.Add(item=settingsFile,
                       flag=wx.ALIGN_RIGHT |
@@ -596,9 +596,8 @@
         iconTheme = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
                               choices=self.settings.Get(group='advanced', key='iconTheme', subkey='choices', internal=True),
                               name="GetStringSelection")
-        iconTheme.SetStringSelection(self.settings.Get(group='advanced', key='iconTheme', subkey='value'))
-        self.settings.Set(group='advanced', key='iconTheme', subkey='winId', value=iconTheme.GetId(), internal=True)
-        self.settings.Set(group='advanced', key='iconTheme', subkey='subkey', value='value', internal=True)
+        iconTheme.SetStringSelection(self.settings.Get(group='advanced', key='iconTheme', subkey='type'))
+        self.winId['advanced:iconTheme:type'] = iconTheme.GetId()
 
         gridSizer.Add(item=iconTheme,
                       flag=wx.ALIGN_RIGHT |
@@ -627,9 +626,8 @@
         digitInterface = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
                                    choices=self.settings.Get(group='advanced', key='digitInterface', subkey='choices', internal=True),
                                    name="GetStringSelection")
-        digitInterface.SetStringSelection(self.settings.Get(group='advanced', key='digitInterface', subkey='value'))
-        self.settings.Set(group='advanced', key='digitInterface', subkey='winId', value=digitInterface.GetId(), internal=True)
-        self.settings.Set(group='advanced', key='digitInterface', subkey='subkey', value='value', internal=True)
+        digitInterface.SetStringSelection(self.settings.Get(group='advanced', key='digitInterface', subkey='type'))
+        self.winId['advanced:digitInterface:type'] = digitInterface.GetId()
 
         gridSizer.Add(item=digitInterface,
                       flag=wx.ALIGN_RIGHT |
@@ -694,31 +692,29 @@
     def OnApply(self, event):
         """Button 'Apply' clicked"""
         self.__UpdateSettings()
-        
+        self.Close()
+
     def OnCancel(self, event):
         """Button 'Cancel' clicked"""
         self.Close()
 
     def __UpdateSettings(self):
         """Update user settings"""
-        for group in self.settings.internalSettings.keys():
-            for key in self.settings.internalSettings[group].keys():
-                id  = self.settings.internalSettings[group][key]['winId']
-                subkey = self.settings.internalSettings[group][key]['subkey']
-                if id is None or subkey is None:
-                    continue
-                win = self.FindWindowById(id)
-                if win.GetName() == 'GetValue':
-                    value = win.GetValue()
-                elif win.GetName() == 'GetSelection':
-                    value = win.GetSelection()
-                elif win.GetName() == 'IsChecked':
-                    value = win.IsChecked()
-                elif win.GetName() == 'GetStringSelection':
-                    value = win.GetStringSelection()
-                else:
-                    value = None
-                self.settings.Set(group, key, subkey, value)
+        for item in self.winId.keys():
+            group, key, subkey = item.split(':')
+            id = self.winId[item]
+            win = self.FindWindowById(id)
+            if win.GetName() == 'GetValue':
+                value = win.GetValue()
+            elif win.GetName() == 'GetSelection':
+                value = win.GetSelection()
+            elif win.GetName() == 'IsChecked':
+                value = win.IsChecked()
+            elif win.GetName() == 'GetStringSelection':
+                value = win.GetStringSelection()
+            else:
+                value = win.GetValue()
+            self.settings.Set(group, key, subkey, value)
 
 class SetDefaultFont(wx.Dialog):
     """

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2008-03-04 21:31:39 UTC (rev 30470)
+++ grass/trunk/gui/wxpython/icons/icon.py	2008-03-04 22:32:53 UTC (rev 30471)
@@ -32,7 +32,7 @@
 # iconpath = grassenv.GetGRASSVariable('GRASS_ICONPATH')
 # if not iconpath:
 #    iconpath = os.getenv("GRASS_ICONPATH")
-iconTheme = UserSettings.Get(group='advanced', key='iconTheme', subkey='value')
+iconTheme = UserSettings.Get(group='advanced', key='iconTheme', subkey='type')
 if iconTheme and iconTheme == 'silk':
     iconpath = os.path.join(globalvar.ETCWXDIR, "icons", "silk")
 else:



More information about the grass-commit mailing list