[GRASS-SVN] r31137 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 27 07:17:29 EDT 2008


Author: martinl
Date: 2008-04-27 07:17:29 -0400 (Sun, 27 Apr 2008)
New Revision: 31137

Modified:
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/profile.py
Log:
wxGUI (profile): fixes related to r31103 (save profile settings to file)

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-04-27 08:19:09 UTC (rev 31136)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-04-27 11:17:29 UTC (rev 31137)
@@ -166,7 +166,7 @@
                        'legendSize' : 10,
                        },
             'marker' : { 'color' : wx.Colour(0, 0, 0),
-                         'fill' : wx.TRANSPARENT,
+                         'fill' : 'transparent',
                          'size' : 2,
                          'type' : 'triangle',
                          'legend' : _('Segment break'),
@@ -260,7 +260,7 @@
             self.filePath = gisdbase_file
         
         if self.filePath:
-            self.__ReadFile(self.filePath)
+            self.__ReadFile(self.filePath, settings)
             
     def __ReadFile(self, filename, settings=None):
         """Read settings from file to dict"""
@@ -278,7 +278,7 @@
                     subkey = kv[idx]
                     value = kv[idx+1]
                     if len(value) == 0:
-                        self.Set(group=group, key=key, subkey=subkey, value='')
+                        self.Append(settings, group, key, subkey, '')
                     else:
                         # casting
                         if value == 'True':
@@ -298,9 +298,8 @@
                                 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)
+
+                        self.Append(settings, group, key, subkey, value)
                     idx += 2
         finally:
             file.close()
@@ -345,7 +344,7 @@
 
         return filePath
 
-    def Get(self, group, key, subkey=None, internal=False):
+    def Get(self, group, key=None, subkey=None, internal=False):
         """Get value by key/subkey
 
         Raise KeyError if key is not found
@@ -364,7 +363,10 @@
             
         try:
             if subkey is None:
-                return settings[group][key]
+                if key is None:
+                    return settings[group]
+                else:
+                    return settings[group][key]
             else:
                 return settings[group][key][subkey]
         except KeyError:
@@ -372,14 +374,14 @@
                                                        group, key, subkey))
         
     def Set(self, group, key, subkey, value, internal=False):
-        """Set value by key/subkey
+        """Set value of key/subkey
 
-        Raise KeyError if key is not found
+        Raise KeyError if group/key is not found
         
         @param group settings group
-        @param key
-        @param subkey
-        @param value 
+        @param key key
+        @param subkey subkey
+        @param value value
         """
         if internal is True:
             settings = self.internalSettings
@@ -393,6 +395,29 @@
         except KeyError:
             raise gcmd.SettingsError("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
 
+    def Append(self, dict, group, key, subkey, value):
+        """Set value of key/subkey
+
+        Create group/key/subkey if not exists
+        
+        @param dict settings dictionary to use
+        @param group settings group
+        @param key key
+        @param subkey subkey
+        @param value value
+        """
+        if not dict.has_key(group):
+            dict[group] = {}
+
+        if not dict[group].has_key(key):
+            dict[group][key] = {}
+
+        dict[group][key][subkey] = value
+
+    def GetDefaultSettings(self):
+        """Get default user settings"""
+        return self.defaultSettings
+
 globalSettings = Settings()
 
 class PreferencesDialog(wx.Dialog):
@@ -999,7 +1024,7 @@
         """Button 'Save' pressed"""
         self.__UpdateSettings()
         file = self.settings.SaveToFile()
-        self.parent.goutput.cmd_stdout.write(_('Settings saved to file \'%s\'.') % file)
+        self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % file)
         self.Close()
 
     def OnApply(self, event):

Modified: grass/trunk/gui/wxpython/gui_modules/profile.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/profile.py	2008-04-27 08:19:09 UTC (rev 31136)
+++ grass/trunk/gui/wxpython/gui_modules/profile.py	2008-04-27 11:17:29 UTC (rev 31137)
@@ -68,7 +68,7 @@
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
                  style=wx.DEFAULT_FRAME_STYLE):
 
-        self.parent = parent
+        self.parent = parent # MapFrame
         self.mapwin = self.parent.MapWindow
         self.Map = render.Map()  # instance of render.Map to be associated with display
 
@@ -78,6 +78,8 @@
                             'short-dash' : wx.SHORT_DASH,
                             'dot-dash' : wx.DOT_DASH }
 
+        self.ptfilldict = { 'transparent' : wx.TRANSPARENT,
+                            'solid' : wx.SOLID }
 
         wx.Frame.__init__(self, parent, id, title, pos, size, style)
 
@@ -254,6 +256,9 @@
         if self.raster[0]['name'] == '':
             return
 
+        # title of window
+        self.ptitle = _('Profile of')
+
         #
         # create datalist for each raster map
         #
@@ -331,6 +336,9 @@
         self.client.SetEnableZoom(self.zoom)
         self.client.SetEnableDrag(self.drag)
         
+        #
+        # axis settings
+        #
         if self.properties['x-axis']['prop']['type'] == 'custom':
             self.client.SetXSpec('min')
         else:
@@ -342,14 +350,14 @@
             self.client.SetYSpec(self.properties['y-axis']['prop']['type'])
 
         if self.properties['x-axis']['prop']['type'] == 'custom' and \
-               self.properties['x-axis']['prop']['min'] != self.properties['x-axis']['prop']['max']:
-            self.properties['x-axis']['prop']['axis'] = (self.properties['x-axis']['prop']['min'],
-                                                         self.properties['x-axis']['prop']['max'])
+               self.properties['x-axis']['prop']['min'] < self.properties['x-axis']['prop']['max']:
+            self.properties['x-axis']['axis'] = (self.properties['x-axis']['prop']['min'],
+                                                 self.properties['x-axis']['prop']['max'])
         else:
             self.properties['x-axis']['axis'] = None
 
         if self.properties['y-axis']['prop']['type'] == 'custom' and \
-                self.properties['y-axis']['prop']['min'] != self.properties['y-axis']['prop']['max']:
+                self.properties['y-axis']['prop']['min'] < self.properties['y-axis']['prop']['max']:
             self.properties['y-axis']['axis'] = (self.properties['y-axis']['prop']['min'],
                                                  self.properties['y-axis']['prop']['max'])
         else:
@@ -450,11 +458,15 @@
                 self.plotlist.append(r['pline'])
 
         if len(self.seglist) > 0 :
-            self.ppoints = plot.PolyMarker(self.seglist, legend=' '+self.ptlegend,
-                                           colour=self.ptcolor,
-                                           size=self.ptsize,
-                                           fillstyle = self.ptfill,
-                                           marker=self.pttype)
+            self.ppoints = plot.PolyMarker(self.seglist,
+                                           legend=' ' + self.properties['marker']['legend'],
+                                           colour=wx.Color(self.properties['marker']['color'][0],
+                                                           self.properties['marker']['color'][1],
+                                                           self.properties['marker']['color'][2],
+                                                           255),
+                                           size=self.properties['marker']['size'],
+                                           fillstyle=self.ptfilldict[self.properties['marker']['fill']],
+                                           marker=self.properties['marker']['type'])
             self.plotlist.append(self.ppoints)
 
         self.profile = plot.PlotGraphics(self.plotlist,
@@ -626,9 +638,10 @@
             self.client.SetFontSizeTitle(self.properties['font']['prop']['titleSize'])
             self.client.SetFontSizeAxis(self.properties['font']['prop']['axisSize'])
 
-            self.profile.setTitle(dlg.ptitle)
-            self.profile.setXLabel(dlg.xlabel)
-            self.profile.setYLabel(dlg.ylabel)
+            if self.profile:
+                self.profile.setTitle(dlg.ptitle)
+                self.profile.setXLabel(dlg.xlabel)
+                self.profile.setYLabel(dlg.ylabel)
 
         dlg.Destroy()
 
@@ -645,6 +658,10 @@
         if dlg.ShowModal() == wx.ID_OK:
             dlg.UpdateSettings()
 
+            self.SetGraphStyle()
+            if self.profile:
+                self.DrawPlot()
+
         dlg.Destroy()
 
     def PrintMenu(self, event):
@@ -688,12 +705,14 @@
         Close profile window and clean up
         """
         self.mapwin.ClearLines()
-        self.mapwin.mouse['begin'] = self.mapwin.mouse['end'] = (0.0,0.0)
+        self.mapwin.mouse['begin'] = self.mapwin.mouse['end'] = (0.0, 0.0)
         self.mapwin.mouse['use'] = 'pointer'
         self.mapwin.mouse['box'] = 'point'
         self.mapwin.polycoords = []
         self.mapwin.SetCursor(self.Parent.cursors["default"])
 
+        self.mapwin.UpdateMap(render=False, renderVector=False)
+
         self.Destroy()
 
 class SetRasterDialog(wx.Dialog):
@@ -946,18 +965,32 @@
         sizer.Add(item=line, proportion=0,
                   flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=3)
 
-        btnsizer = wx.StdDialogButtonSizer()
+        #
+        # buttons
+        #
+        btnSave = wx.Button(self, wx.ID_SAVE)
+        btnApply = wx.Button(self, wx.ID_APPLY)
+        btnCancel = wx.Button(self, wx.ID_CANCEL)
+        btnSave.SetDefault()
 
-        btn = wx.Button(self, wx.ID_OK)
-        btn.SetDefault()
-        btnsizer.AddButton(btn)
+        # bindigs
+        btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
+        btnApply.SetToolTipString(_("Apply changes for the current session"))
+        btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
+        btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
+        btnSave.SetDefault()
+        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
+        btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
 
-        btn = wx.Button(self, wx.ID_CANCEL)
-        btnsizer.AddButton(btn)
-        btnsizer.Realize()
+        # sizers
+        btnStdSizer = wx.StdDialogButtonSizer()
+        btnStdSizer.AddButton(btnCancel)
+        btnStdSizer.AddButton(btnSave)
+        btnStdSizer.AddButton(btnApply)
+        btnStdSizer.Realize()
+        
+        sizer.Add(item=btnStdSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
 
-        sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
-
         #
         # bindings
         #
@@ -987,6 +1020,25 @@
         self.properties['font']['wxfont'].SetStyle(style)
         weight = self.fwtdict[self.fwtcb.GetStringSelection()]
         self.properties['font']['wxfont'].SetWeight(weight)
+
+    def OnSave(self, event):
+        """Button 'Save' pressed"""
+        self.UpdateSettings()
+        fileSettings = {}
+        UserSettings.ReadSettingsFile(settings=fileSettings)
+        fileSettings['profile'] = UserSettings.Get(group='profile')
+        file = UserSettings.SaveToFile(fileSettings)
+        self.parent.parent.gismanager.goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file)
+        self.Close()
+
+    def OnApply(self, event):
+        """Button 'Apply' pressed"""
+        self.UpdateSettings()
+        self.Close()
+
+    def OnCancel(self, event):
+        """Button 'Cancel' pressed"""
+        self.Close()
         
 class OptDialog(wx.Dialog):
     def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
@@ -998,6 +1050,7 @@
         """
         # init variables
         self.pstyledict = parent.pstyledict
+        self.ptfilldict = parent.ptfilldict
 
         self.pttypelist = ['circle',
                            'dot',
@@ -1007,9 +1060,6 @@
                            'cross',
                            'plus']
         
-        self.ptfilldict = { 'transparent' : wx.TRANSPARENT,
-                            'solid' : wx.SOLID }
-
         self.axislist = ['min',
                          'auto',
                          'custom']
@@ -1123,18 +1173,9 @@
         gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
         ptfill = wx.ComboBox(parent=self, id=wx.ID_ANY,
                              size=(120, -1), choices=self.ptfilldict.keys(), style=wx.CB_DROPDOWN)
-        for item in self.ptfilldict.items():
-            if self.properties['marker']['fill'] == item[1]:
-                ptfill.SetStringSelection(item[0])
-                break
+        ptfill.SetStringSelection(self.properties['marker']['fill'])
         self.wxId['marker']['fill'] = ptfill.GetId()
         gridSizer.Add(item=ptfill, pos=(2, 1))
-        #        self.ptfillkey = item[0]
-        # for item in self.pstyledict.items():
-        #    if self.pstyle1 == item[1]:
-        #        self.pstylekey1 = item[0]
-
-
         
         label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend"))
         gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
@@ -1167,7 +1208,7 @@
         for axis, atype in [(_("X-Axis"), 'x-axis'),
                      (_("Y-Axis"), 'y-axis')]:
             box = wx.StaticBox(parent=self, id=wx.ID_ANY,
-                               label=" %s " % _("X-Axis"))
+                               label=" %s " % axis)
             boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
             gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
 
@@ -1269,18 +1310,32 @@
         sizer.Add(item=line, proportion=0,
                   flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=3)
 
-        btnsizer = wx.StdDialogButtonSizer()
+        #
+        # buttons
+        #
+        btnSave = wx.Button(self, wx.ID_SAVE)
+        btnApply = wx.Button(self, wx.ID_APPLY)
+        btnCancel = wx.Button(self, wx.ID_CANCEL)
+        btnSave.SetDefault()
 
-        btn = wx.Button(self, wx.ID_OK)
-        btn.SetDefault()
-        btnsizer.AddButton(btn)
+        # bindigs
+        btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
+        btnApply.SetToolTipString(_("Apply changes for the current session"))
+        btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
+        btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
+        btnSave.SetDefault()
+        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
+        btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
 
-        btn = wx.Button(self, wx.ID_CANCEL)
-        btnsizer.AddButton(btn)
-        btnsizer.Realize()
+        # sizers
+        btnStdSizer = wx.StdDialogButtonSizer()
+        btnStdSizer.AddButton(btnCancel)
+        btnStdSizer.AddButton(btnSave)
+        btnStdSizer.AddButton(btnApply)
+        btnStdSizer.Realize()
+        
+        sizer.Add(item=btnStdSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
 
-        sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
-
         self.SetSizer(sizer)
         sizer.Fit(self)
 
@@ -1289,7 +1344,7 @@
         for r in self.raster.itervalues():
             r['prop']['pcolor'] = self.FindWindowById(self.wxId['pcolor'][idx]).GetColour()
             r['prop']['pwidth'] = int(self.FindWindowById(self.wxId['pwidth'][idx]).GetValue())
-            r['prop']['pstyle'] = self.pstyledict[self.FindWindowById(self.wxId['pstyle'][idx]).GetStringSelection()]
+            r['prop']['pstyle'] = self.FindWindowById(self.wxId['pstyle'][idx]).GetStringSelection()
             r['plegend'] = self.FindWindowById(self.wxId['plegend'][idx]).GetValue()
             idx +=1
 
@@ -1301,8 +1356,8 @@
 
         for axis in ('x-axis', 'y-axis'):
             self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetValue()
-            self.properties[axis]['prop']['min'] = self.FindWindowById(self.wxId[axis]['min']).GetValue()
-            self.properties[axis]['prop']['max'] = self.FindWindowById(self.wxId[axis]['max']).GetValue()
+            self.properties[axis]['prop']['min'] = float(self.FindWindowById(self.wxId[axis]['min']).GetValue())
+            self.properties[axis]['prop']['max'] = float(self.FindWindowById(self.wxId[axis]['max']).GetValue())
             self.properties[axis]['prop']['log'] = self.FindWindowById(self.wxId[axis]['log']).IsChecked()
 
         self.properties['grid']['color'] = self.FindWindowById(self.wxId['grid']['color']).GetColour()
@@ -1311,5 +1366,21 @@
         self.properties['font']['prop']['legendSize'] = self.FindWindowById(self.wxId['font']['legendSize']).GetValue()
         self.properties['legend']['enabled'] = self.FindWindowById(self.wxId['legend']['enabled']).IsChecked()
 
+    def OnSave(self, event):
+        """Button 'Save' pressed"""
+        self.UpdateSettings()
+        fileSettings = {}
+        UserSettings.ReadSettingsFile(settings=fileSettings)
+        fileSettings['profile'] = UserSettings.Get(group='profile')
+        file = UserSettings.SaveToFile(fileSettings)
+        self.parent.parent.gismanager.goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file)
+        self.Close()
 
+    def OnApply(self, event):
+        """Button 'Apply' pressed"""
+        self.UpdateSettings()
+        self.Close()
 
+    def OnCancel(self, event):
+        """Button 'Cancel' pressed"""
+        self.Close()



More information about the grass-commit mailing list