[GRASS-SVN] r53025 - grass/branches/releasebranch_6_4/gui/wxpython/wxplot

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 31 09:56:02 PDT 2012


Author: cmbarton
Date: 2012-08-31 09:56:02 -0700 (Fri, 31 Aug 2012)
New Revision: 53025

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/wxplot/base.py
   grass/branches/releasebranch_6_4/gui/wxpython/wxplot/dialogs.py
   grass/branches/releasebranch_6_4/gui/wxpython/wxplot/profile.py
Log:
Fix for broken profiling modules

Modified: grass/branches/releasebranch_6_4/gui/wxpython/wxplot/base.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/wxplot/base.py	2012-08-31 12:13:47 UTC (rev 53024)
+++ grass/branches/releasebranch_6_4/gui/wxpython/wxplot/base.py	2012-08-31 16:56:02 UTC (rev 53025)
@@ -51,7 +51,7 @@
 
         wx.Frame.__init__(self, parent, id, size = size, style = style, **kwargs)
         
-        self.parent = parent            # MapFrame
+        self.parent = parent            # MapFrame for a plot type
         self.mapwin = self.parent.MapWindow
         self.Map    = Map()             # instance of render.Map to be associated with display
         self.rasterList = rasterList    #list of rasters to plot
@@ -123,9 +123,8 @@
 
     def InitPlotOpts(self, plottype):
         """!Initialize options for entire plot
-        """
-        
-        self.plottype = plottype                # histogram, profile, or scatter
+        """        
+        self.plottype = plottype                # profile
 
         self.properties = {}                    # plot properties
         self.properties['font'] = {}
@@ -134,11 +133,17 @@
                                                     wx.FONTSTYLE_NORMAL,
                                                     wx.FONTWEIGHT_NORMAL)
         
+        self.properties['raster'] = {}
+        self.properties['raster'] = UserSettings.Get(group = self.plottype, key = 'raster')
+        colstr = str(self.properties['raster']['pcolor'])
+        self.properties['raster']['pcolor'] = tuple(int(colval) for colval in colstr.strip('()').split(','))
+
         if self.plottype == 'profile':
             self.properties['marker'] = UserSettings.Get(group = self.plottype, key = 'marker')
             # changing color string to tuple for markers/points
             colstr = str(self.properties['marker']['color'])
             self.properties['marker']['color'] = tuple(int(colval) for colval in colstr.strip('()').split(','))
+ 
 
         self.properties['grid'] = UserSettings.Get(group = self.plottype, key = 'grid')        
         colstr = str(self.properties['grid']['color']) # changing color string to tuple        
@@ -176,6 +181,8 @@
 
         rdict = {} # initialize a dictionary
 
+        self.properties['raster'] = UserSettings.Get(group = self.plottype, key = 'raster')
+
         for r in rasterList:
             idx = rasterList.index(r)
             
@@ -185,23 +192,41 @@
                 continue
                 # if r.info cannot parse map, skip it
                
-            self.raster[r] = UserSettings.Get(group = plottype, key = 'raster') # some default settings
+            self.raster[r] = self.properties['raster'] # some default settings
             rdict[r] = {} # initialize sub-dictionaries for each raster in the list
-
             
             rdict[r]['units'] = ''
             if ret['units'] not in ('(none)', '"none"', '', None):
                 rdict[r]['units'] = ret['units']
             
             rdict[r]['plegend'] = r.split('@')[0]
-            rdict[r]['datalist'] = [] # list of cell value,frequency pairs for plotting histogram
+            rdict[r]['datalist'] = [] # list of cell value,frequency pairs for plotting
             rdict[r]['pline'] = None
             rdict[r]['datatype'] = ret['datatype']
-            rdict[r]['pwidth'] = 1
-            rdict[r]['pstyle'] = 'solid'
-            
+
+            #    
+            #initialize with saved values
+            #
+            if self.properties['raster']['pwidth'] != None:
+                rdict[r]['pwidth'] = self.properties['raster']['pwidth']
+            else:
+                rdict[r]['pwidth'] = 1
+                
+            if self.properties['raster']['pstyle'] != None and \
+                self.properties['raster']['pstyle'] != '':
+                rdict[r]['pstyle'] = self.properties['raster']['pstyle']
+            else:
+                rdict[r]['pstyle'] = 'solid'
+                        
             if idx <= len(self.colorList):
-                rdict[r]['pcolor'] = self.colorDict[self.colorList[idx]]
+                if idx == 0:
+                    # use saved color for first plot
+                    if self.properties['raster']['pcolor'] != None:
+                        rdict[r]['pcolor'] = self.properties['raster']['pcolor'] 
+                    else:
+                        rdict[r]['pcolor'] = self.colorDict[self.colorList[idx]]
+                else:
+                    rdict[r]['pcolor'] = self.colorDict[self.colorList[idx]]
             else:
                 r = randint(0, 255)
                 b = randint(0, 255)
@@ -209,56 +234,7 @@
                 rdict[r]['pcolor'] = ((r,g,b,255))
         
         return rdict
-            
-    def InitRasterPairs(self, rasterList, plottype):
-        """!Initialize or update raster dictionary with raster pairs for
-            bivariate scatterplots
-        """
-        
-        if len(rasterList) == 0: return
 
-        rdict = {} # initialize a dictionary
-        for rpair in rasterList:
-            idx = rasterList.index(rpair)
-            
-            try:
-                ret0 = grass.raster_info(rpair[0])
-                ret1 = grass.raster_info(rpair[1])
-
-            except:
-                continue
-                # if r.info cannot parse map, skip it
-
-            self.raster[rpair] = UserSettings.Get(group = plottype, key = 'rasters') # some default settings
-            rdict[rpair] = {} # initialize sub-dictionaries for each raster in the list
-            rdict[rpair][0] = {}
-            rdict[rpair][1] = {}
-            rdict[rpair][0]['units'] = ''
-            rdict[rpair][1]['units'] = ''
-
-            if ret0['units'] not in ('(none)', '"none"', '', None):
-                rdict[rpair][0]['units'] = ret0['units']
-            if ret1['units'] not in ('(none)', '"none"', '', None):
-                rdict[rpair][1]['units'] = ret1['units']
-                
-            rdict[rpair]['plegend'] = rpair[0].split('@')[0] + ' vs ' + rpair[1].split('@')[0]
-            rdict[rpair]['datalist'] = [] # list of cell value,frequency pairs for plotting histogram
-            rdict[rpair]['ptype'] = 'dot'
-            rdict[rpair][0]['datatype'] = ret0['datatype']
-            rdict[rpair][1]['datatype'] = ret1['datatype']
-            rdict[rpair]['psize'] = 1
-            rdict[rpair]['pfill'] = 'solid'
-            
-            if idx <= len(self.colorList):
-                rdict[rpair]['pcolor'] = self.colorDict[self.colorList[idx]]
-            else:
-                r = randint(0, 255)
-                b = randint(0, 255)
-                g = randint(0, 255)
-                rdict[rpair]['pcolor'] = ((r,g,b,255))
-            
-        return rdict
-
     def SetGraphStyle(self):
         """!Set plot and text options
         """
@@ -295,26 +271,32 @@
                                                  self.properties['y-axis']['prop']['max'])
         else:
             self.properties['y-axis']['axis'] = None
-
-        self.client.SetEnableGrid(self.properties['grid']['enabled'])
-        
-        self.client.SetGridColour(wx.Color(self.properties['grid']['color'][0],
-                                           self.properties['grid']['color'][1],
-                                           self.properties['grid']['color'][2],
-                                           255))
-
-        self.client.SetFontSizeLegend(self.properties['font']['prop']['legendSize'])
-        self.client.SetEnableLegend(self.properties['legend']['enabled'])
-
+            
         if self.properties['x-axis']['prop']['log'] == True:
             self.properties['x-axis']['axis'] = None
             self.client.SetXSpec('min')
         if self.properties['y-axis']['prop']['log'] == True:
             self.properties['y-axis']['axis'] = None
             self.client.SetYSpec('min')
-            
+                        
         self.client.setLogScale((self.properties['x-axis']['prop']['log'],
                                  self.properties['y-axis']['prop']['log']))
+        
+        #
+        # grid settings
+        #
+        self.client.SetEnableGrid(self.properties['grid']['enabled'])
+                
+        self.client.SetGridColour(wx.Color(self.properties['grid']['color'][0],
+                                           self.properties['grid']['color'][1],
+                                           self.properties['grid']['color'][2],
+                                           255))
+        
+        #
+        # legend settings
+        #
+        self.client.SetFontSizeLegend(self.properties['font']['prop']['legendSize'])
+        self.client.SetEnableLegend(self.properties['legend']['enabled'])
 
     def DrawPlot(self, plotlist):
         """!Draw line and point plot from list plot elements.
@@ -424,6 +406,7 @@
         """
         point = wx.GetMousePosition()
         popt = wx.Menu()
+
         # Add items to the menu
         settext = wx.MenuItem(popt, wx.ID_ANY, _('Text settings'))
         popt.AppendItem(settext)
@@ -449,12 +432,11 @@
         dlg.Destroy()
 
     def OnPlotText(self, dlg):
-        """!Custom text settings for histogram plot.
+        """!Custom text settings.
         """
         self.ptitle = dlg.ptitle
         self.xlabel = dlg.xlabel
         self.ylabel = dlg.ylabel
-        dlg.UpdateSettings()
 
         self.client.SetFont(self.properties['font']['wxfont'])
         self.client.SetFontSizeTitle(self.properties['font']['prop']['titleSize'])
@@ -464,7 +446,7 @@
             self.plot.setTitle(dlg.ptitle)
             self.plot.setXLabel(dlg.xlabel)
             self.plot.setYLabel(dlg.ylabel)
-        
+
         self.OnRedraw(event = None)
     
     def PlotText(self, event):
@@ -474,27 +456,25 @@
                                  plottype = self.plottype, 
                                  title = _('Histogram text settings'))
 
-        if dlg.ShowModal() == wx.ID_OK:
-            self.OnPlotText(dlg)
+        btnval = dlg.ShowModal()
+        if btnval == wx.ID_SAVE or btnval == wx.ID_OK or btnval == wx.ID_CANCEL:
+            dlg.Destroy()            
 
-        dlg.Destroy()
 
     def PlotOptions(self, event):
         """!Set various profile options, including: line width, color,
         style; marker size, color, fill, and style; grid and legend
         options.  Calls OptDialog class.
         """
+       
         dlg = OptDialog(parent = self, id = wx.ID_ANY, 
                         plottype = self.plottype, 
                         title = _('Plot settings'))
+
         btnval = dlg.ShowModal()
 
-        if btnval == wx.ID_SAVE:
-            dlg.UpdateSettings()            
-            self.SetGraphStyle()            
+        if btnval == wx.ID_SAVE or btnval == wx.ID_OK or btnval == wx.ID_CANCEL:
             dlg.Destroy()            
-        elif btnval == wx.ID_CANCEL:
-            dlg.Destroy()
 
     def PrintMenu(self, event):
         """!Print options and output menu

Modified: grass/branches/releasebranch_6_4/gui/wxpython/wxplot/dialogs.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/wxplot/dialogs.py	2012-08-31 12:13:47 UTC (rev 53024)
+++ grass/branches/releasebranch_6_4/gui/wxpython/wxplot/dialogs.py	2012-08-31 16:56:02 UTC (rev 53025)
@@ -5,7 +5,9 @@
 
 Classes:
  - dialogs::ProfileRasterDialog
+ - dialogs::ScatterRasterDialog
  - dialogs::PlotStatsFrame
+ - dialogs::HistRasterDialog
  - dialogs::TextDialog
  - dialogs::OptDialog
 
@@ -98,7 +100,7 @@
         """
         self.rasterList = []
         self.rasterList = event.GetString().split(',')
-   
+        
 class PlotStatsFrame(wx.Frame):
     def __init__(self, parent, id, message = '', title = '',
                  style = wx.DEFAULT_FRAME_STYLE, **kwargs):
@@ -194,9 +196,9 @@
         self.Close(True)
 
 class TextDialog(wx.Dialog):
-    def __init__(self, parent, id, title, 
+    def __init__(self, parent, id, title, plottype = '', 
                  style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
-        """!Dialog to set profile text options: font, title
+        """!Dialog to set plot text options: font, title
         and font size, axis labels and font size
         """
         wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
@@ -221,6 +223,7 @@
                          'bold' : wx.FONTWEIGHT_BOLD }
 
         self.parent = parent
+        self.plottype = plottype
 
         self.ptitle = self.parent.ptitle
         self.xlabel = self.parent.xlabel
@@ -234,7 +237,7 @@
         self.fontweight = self.properties['font']['wxfont'].GetWeight()
 
         self._do_layout()
-        
+                
     def _do_layout(self):
         """!Do layout"""
         # dialog layout
@@ -315,7 +318,7 @@
         label1 = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Font family:"))
         gridSizer.Add(item = label1, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
         self.ffamilycb = wx.ComboBox(parent = self, id = wx.ID_ANY, size = (250, -1),
-                                     choices = self.ffamilydict.keys(), style = wx.CB_DROPDOWN)
+                                choices = self.ffamilydict.keys(), style = wx.CB_DROPDOWN)
         self.ffamilycb.SetStringSelection('swiss')
         for item in self.ffamilydict.items():
             if self.fontfamily == item[1]:
@@ -368,7 +371,7 @@
         btnCancel = wx.Button(self, wx.ID_CANCEL)
         btnOk.SetDefault()
 
-        # bindigs
+        # bindings
         btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
         btnApply.SetToolTipString(_("Apply changes for the current session"))
         btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
@@ -423,22 +426,22 @@
 
     def OnSave(self, event):
         """!Button 'Save' pressed"""
-        self.UpdateSettings()
+        self.OnApply(None)
         fileSettings = {}
         UserSettings.ReadSettingsFile(settings = fileSettings)
-        fileSettings['profile']  =  UserSettings.Get(group = 'profile')
-        file = UserSettings.SaveToFile(fileSettings)
-        self.parent.parent.GetLayerManager().goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file)
+        fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
+        UserSettings.SaveToFile(fileSettings)
+        self.parent.parent.GetLayerManager().goutput.WriteLog(_('Plot text sizes saved to file \'%s\'.') % UserSettings.filePath)
         self.EndModal(wx.ID_OK)
 
     def OnApply(self, event):
         """!Button 'Apply' pressed"""
         self.UpdateSettings()
-        self.parent.OnPText(self)
+        self.parent.OnPlotText(self)
         
     def OnOk(self, event):
         """!Button 'OK' pressed"""
-        self.UpdateSettings()
+        self.OnApply(None)
         self.EndModal(wx.ID_OK)
 
     def OnCancel(self, event):
@@ -446,17 +449,21 @@
         self.EndModal(wx.ID_CANCEL)
         
 class OptDialog(wx.Dialog):
-    def __init__(self, parent, id, title, 
-                 style = wx.DEFAULT_DIALOG_STYLE, **kwargs):
-        """!Dialog to set various profile options, including: line
+    def __init__(self, parent, id, title, plottype = '', 
+                 style = wx.DEFAULT_DIALOG_STYLE, **kwargs): 
+        """!Dialog to set various options for data plotted, including: line
         width, color, style; marker size, color, fill, and style; grid
         and legend options.
         """
         wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
+
         # init variables
-        self.pstyledict = parent.pstyledict
+        self.parent = parent
+        self.linestyledict = parent.linestyledict
         self.ptfilldict = parent.ptfilldict
-
+        self.parent = parent
+        self.plottype = plottype
+        
         self.pttypelist = ['circle',
                            'dot',
                            'square',
@@ -476,139 +483,166 @@
 
         # read-only
         self.raster = self.parent.raster
+        self.rasterList = self.parent.rasterList
         self.properties = self.parent.properties
+        self.map = ''
         
+        if len(self.rasterList) == 0:
+            wx.MessageBox(parent = self,
+                              message = _("No map or image group selected to plot."),
+                              caption = _("Warning"), style = wx.OK | wx.ICON_ERROR)
+            
         self._do_layout()
-
+        
     def _do_layout(self):
-        """!Do layout"""
-        # dialog layout
+        """!Options dialog layout
+        """
         sizer = wx.BoxSizer(wx.VERTICAL)
 
+        box = wx.StaticBox(parent = self, id = wx.ID_ANY,
+                           label = " %s " % _("Plot settings")) 
+        boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
+
+        self.wxId['pcolor']  = 0
+        self.wxId['pwidth']  = 0
+        self.wxId['pstyle']  = 0
+        self.wxId['psize'] = 0
+        self.wxId['ptype'] = 0
+        self.wxId['pfill'] = 0
+        self.wxId['plegend'] = 0
+        self.wxId['marker'] = {}
+        self.wxId['x-axis'] = {}
+        self.wxId['y-axis'] = {}
+        
         #
-        # profile line settings
+        # plot line settings and point settings
         #
+        if len(self.rasterList) == 0: return
+        
         box = wx.StaticBox(parent = self, id = wx.ID_ANY,
-                           label = " %s " % _("Profile line settings"))
-        boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
+                           label = _("Map/image plotted"))
+        boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+        
+        gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
+        
+        row = 0
+        choicelist = []
+        for i in self.rasterList:
+            choicelist.append(str(i))
 
-        idx = 1
-        self.wxId['pcolor'] = []
-        self.wxId['pwidth'] = []
-        self.wxId['pstyle'] = []
-        self.wxId['plegend'] = []
-        for r in self.raster.itervalues():
+        self.mapchoice = wx.Choice(parent = self, id = wx.ID_ANY, size = (300, -1),
+                                   choices = choicelist)
+        if not self.map:
+            self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
+        else:
+            self.mapchoice.SetStringSelection(str(self.map))
+            
+                
+        gridSizer.Add(item = self.mapchoice, flag = wx.ALIGN_CENTER_VERTICAL, 
+                      pos = (row, 0), span = (1, 2))
+        
+        #
+        # options for profile
+        #
+        row +=1            
+        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line color"))
+        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
+        color = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.raster[self.map]['pcolor'])
+        self.wxId['pcolor'] = color.GetId()
+        gridSizer.Add(item = color, pos = (row, 1))
+
+        row += 1
+        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line width"))
+        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
+        width = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
+                             size = (50,-1), style = wx.SP_ARROW_KEYS)
+        width.SetRange(1, 10)
+        width.SetValue(self.raster[self.map]['pwidth'])
+        self.wxId['pwidth'] = width.GetId()
+        gridSizer.Add(item = width, pos = (row, 1))
+
+        row +=1
+        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line style"))
+        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
+        style = wx.Choice(parent = self, id = wx.ID_ANY, 
+                             size = (120, -1), choices = self.linestyledict.keys(), style = wx.CB_DROPDOWN)
+        style.SetStringSelection(self.raster[self.map]['pstyle'])
+        self.wxId['pstyle'] = style.GetId()
+        gridSizer.Add(item = style, pos = (row, 1))
+
+        row += 1
+        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
+        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
+        legend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
+        legend.SetValue(self.raster[self.map]['plegend'])
+        gridSizer.Add(item = legend, pos = (row, 1))
+        self.wxId['plegend'] = legend.GetId()
+        
+        boxSizer.Add(item = gridSizer)
+        boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
+
+        #
+        # segment marker settings for profiles only
+        #       
+        if self.plottype == 'profile':
             box = wx.StaticBox(parent = self, id = wx.ID_ANY,
-                               label = " %s %d " % (_("Profile"), idx))
+                               label = " %s " % _("Transect segment marker settings"))
+            
             boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
             
             gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
-            row = 0            
-            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line color"))
-            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
-            pcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = r['prop']['pcolor'])
-            self.wxId['pcolor'].append(pcolor.GetId())
-            gridSizer.Add(item = pcolor, pos = (row, 1))
+            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Color"))
+            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
+            ptcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['marker']['color'])
+            self.wxId['marker']['color'] = ptcolor.GetId()
+            gridSizer.Add(item = ptcolor, pos = (0, 1))
 
-            row += 1
-            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line width"))
-            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
-            pwidth = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
-                                 size = (50,-1), style = wx.SP_ARROW_KEYS)
-            pwidth.SetRange(1, 10)
-            pwidth.SetValue(r['prop']['pwidth'])
-            self.wxId['pwidth'].append(pwidth.GetId())
-            gridSizer.Add(item = pwidth, pos = (row, 1))
+            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Size"))
+            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
+            ptsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
+                                 size = (50, -1), style = wx.SP_ARROW_KEYS)
+            ptsize.SetRange(1, 10)
+            ptsize.SetValue(self.properties['marker']['size'])
+            self.wxId['marker']['size'] = ptsize.GetId()
+            gridSizer.Add(item = ptsize, pos = (1, 1))
+            
+            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style"))
+            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)
+            ptfill.SetStringSelection(self.properties['marker']['fill'])
+            self.wxId['marker']['fill'] = ptfill.GetId()
+            gridSizer.Add(item = ptfill, pos = (2, 1))
+            
+            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
+            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
+            ptlegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
+            ptlegend.SetValue(self.properties['marker']['legend'])
+            self.wxId['marker']['legend'] = ptlegend.GetId()
+            gridSizer.Add(item = ptlegend, pos = (3, 1))
+                    
+            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Type"))
+            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
+            pttype = wx.ComboBox(parent = self, 
+                                 size = (200, -1), choices = self.pttypelist, style = wx.CB_DROPDOWN)
+            pttype.SetStringSelection(self.properties['marker']['type'])
+            self.wxId['marker']['type'] = pttype.GetId()
+            gridSizer.Add(item = pttype, pos = (4, 1))
 
-            row +=1
-            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Line style"))
-            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
-            pstyle = wx.ComboBox(parent = self, id = wx.ID_ANY, 
-                                 size = (120, -1), choices = self.pstyledict.keys(), style = wx.CB_DROPDOWN)
-            pstyle.SetStringSelection(r['prop']['pstyle'])
-            self.wxId['pstyle'].append(pstyle.GetId())
-            gridSizer.Add(item = pstyle, pos = (row, 1))
-
-            row += 1
-            label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
-            gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
-            plegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
-            plegend.SetValue(r['plegend'])
-            gridSizer.Add(item = plegend, pos = (row, 1))
-            self.wxId['plegend'].append(plegend.GetId())
             boxSizer.Add(item = gridSizer)
-
-            if idx == 0:
-                flag = wx.ALL
-            else:
-                flag = wx.TOP | wx.BOTTOM | wx.RIGHT
-            boxMainSizer.Add(item = boxSizer, flag = flag, border = 3)
-
-            idx += 1
-            
+            boxMainSizer.Add(item = boxSizer, flag = wx.ALL, border = 3)
+                        
         sizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
 
-        middleSizer = wx.BoxSizer(wx.HORIZONTAL)
-        
         #
-        # segment marker settings
+        # axis options for all plots
         #
         box = wx.StaticBox(parent = self, id = wx.ID_ANY,
-                           label = " %s " % _("Transect segment marker settings"))
+                           label = " %s " % _("Axis settings"))
         boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
 
-        self.wxId['marker'] = {}
-        gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
-        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Color"))
-        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
-        ptcolor = csel.ColourSelect(parent = self, id = wx.ID_ANY, colour = self.properties['marker']['color'])
-        self.wxId['marker']['color'] = ptcolor.GetId()
-        gridSizer.Add(item = ptcolor, pos = (0, 1))
+        middleSizer = wx.BoxSizer(wx.HORIZONTAL)
 
-        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Size"))
-        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
-        ptsize = wx.SpinCtrl(parent = self, id = wx.ID_ANY, value = "",
-                             size = (50, -1), style = wx.SP_ARROW_KEYS)
-        ptsize.SetRange(1, 10)
-        ptsize.SetValue(self.properties['marker']['size'])
-        self.wxId['marker']['size'] = ptsize.GetId()
-        gridSizer.Add(item = ptsize, pos = (1, 1))
-        
-        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style"))
-        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)
-        ptfill.SetStringSelection(self.properties['marker']['fill'])
-        self.wxId['marker']['fill'] = ptfill.GetId()
-        gridSizer.Add(item = ptfill, pos = (2, 1))
-        
-        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Legend"))
-        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (3, 0))
-        ptlegend = wx.TextCtrl(parent = self, id = wx.ID_ANY, value = "", size = (200,-1))
-        ptlegend.SetValue(self.properties['marker']['legend'])
-        self.wxId['marker']['legend'] = ptlegend.GetId()
-        gridSizer.Add(item = ptlegend, pos = (3, 1))
-                
-        label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Type"))
-        gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (4, 0))
-        pttype = wx.ComboBox(parent = self, 
-                             size = (200, -1), choices = self.pttypelist, style = wx.CB_DROPDOWN)
-        pttype.SetStringSelection(self.properties['marker']['type'])
-        self.wxId['marker']['type'] = pttype.GetId()
-        gridSizer.Add(item = pttype, pos = (4, 1))
-
-        boxMainSizer.Add(item = gridSizer, flag = wx.ALL, border = 3)
-        middleSizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
-
-        #
-        # axis options
-        #
-        box = wx.StaticBox(parent = self, id = wx.ID_ANY,
-                           label = " %s " % _("Axis settings"))
-        boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
-
-        self.wxId['x-axis'] = {}
-        self.wxId['y-axis'] = {}
         idx = 0
         for axis, atype in [(_("X-Axis"), 'x-axis'),
                      (_("Y-Axis"), 'y-axis')]:
@@ -622,12 +656,12 @@
             row = 0
             label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Style"))
             gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
-            type = wx.ComboBox(parent = self, id = wx.ID_ANY,
+            type = wx.Choice(parent = self, id = wx.ID_ANY,
                                size = (100, -1), choices = self.axislist, style = wx.CB_DROPDOWN)
             type.SetStringSelection(prop['type']) 
             self.wxId[atype]['type'] = type.GetId()
             gridSizer.Add(item = type, pos = (row, 1))
-            
+                        
             row += 1
             label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("Custom min"))
             gridSizer.Add(item = label, flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
@@ -663,12 +697,12 @@
         middleSizer.Add(item = boxMainSizer, flag = wx.ALL | wx.EXPAND, border = 3)
 
         #
-        # grid & legend options
+        # grid & legend options for all plots
         #
         self.wxId['grid'] = {}
         self.wxId['legend'] = {}
         self.wxId['font'] = {}
-        box  =  wx.StaticBox(parent = self, id = wx.ID_ANY,
+        box = wx.StaticBox(parent = self, id = wx.ID_ANY,
                            label = " %s " % _("Grid and Legend settings"))
         boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
@@ -697,7 +731,7 @@
         gridSizer.Add(item = legendfontsize, pos = (row, 1))
 
         row += 1
-        legendshow  =  wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show legend"))
+        legendshow = wx.CheckBox(parent = self, id = wx.ID_ANY, label = _("Show legend"))
         legendshow.SetValue(self.properties['legend']['enabled'])
         self.wxId['legend']['enabled'] = legendshow.GetId()
         gridSizer.Add(item = legendshow, pos = (row, 0), span = (1, 2))
@@ -720,77 +754,121 @@
         #
         btnSave = wx.Button(self, wx.ID_SAVE)
         btnApply = wx.Button(self, wx.ID_APPLY)
+        btnOk = wx.Button(self, wx.ID_OK)
         btnCancel = wx.Button(self, wx.ID_CANCEL)
-        btnSave.SetDefault()
+        btnOk.SetDefault()
 
-        # bindigs
-        btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
+        # tooltips for buttons
         btnApply.SetToolTipString(_("Apply changes for the current session"))
-        btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
+        btnOk.SetToolTipString(_("Apply changes for the current session and close dialog"))
         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"))
 
         # sizers
         btnStdSizer = wx.StdDialogButtonSizer()
+        btnStdSizer.AddButton(btnOk)
+        btnStdSizer.AddButton(btnApply)
         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)
+        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+        btnSizer.Add(item = btnSave, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
+        btnSizer.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 for buttons and map plot settings controls
+        #
+        self.mapchoice.Bind(wx.EVT_CHOICE, self.OnSetMap)
+
+        # bindings
+        btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
+        btnOk.Bind(wx.EVT_BUTTON, self.OnOk)
+        btnOk.SetDefault()
+        btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
+        btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
+
         self.SetSizer(sizer)
         sizer.Fit(self)
 
+    def OnSetMap(self, event):
+        """!Handler for changing map selection"""
+        idx = event.GetSelection()
+        self.map = self.rasterList[idx]
+        
+        # update settings controls for all plots
+        self.FindWindowById(self.wxId['pcolor']).SetColour(self.raster[self.map]['pcolor'])
+        self.FindWindowById(self.wxId['plegend']).SetValue(self.raster[self.map]['plegend'])
+        self.FindWindowById(self.wxId['pwidth']).SetValue(self.raster[self.map]['pwidth'])
+        self.FindWindowById(self.wxId['pstyle']).SetStringSelection(self.raster[self.map]['pstyle'])
+            
+        self.Refresh()
+        
+    def OnSetOpt(self, event):
+        """!Handler for changing any other option"""
+        self.map = self.rasterList[self.mapchoice.GetCurrentSelection()]
+        self.UpdateSettings()
+        self.parent.SetGraphStyle()
+        p = self.parent.CreatePlotList()
+        self.parent.DrawPlot(p)
+
     def UpdateSettings(self):
-        idx = 0
-        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.FindWindowById(self.wxId['pstyle'][idx]).GetStringSelection()
-            r['plegend'] = self.FindWindowById(self.wxId['plegend'][idx]).GetValue()
-            idx +=1
-
-        self.properties['marker']['color'] = self.FindWindowById(self.wxId['marker']['color']).GetColour()
-        self.properties['marker']['fill'] = self.FindWindowById(self.wxId['marker']['fill']).GetStringSelection()
-        self.properties['marker']['size'] = self.FindWindowById(self.wxId['marker']['size']).GetValue()
-        self.properties['marker']['type'] = self.FindWindowById(self.wxId['marker']['type']).GetValue()
-        self.properties['marker']['legend'] = self.FindWindowById(self.wxId['marker']['legend']).GetValue()
-
+        """!Apply settings to each map and to entire plot"""
+        self.raster[self.map]['pcolor'] = self.FindWindowById(self.wxId['pcolor']).GetColour()
+        self.properties['raster']['pcolor'] = self.raster[self.map]['pcolor']
+        
+        self.raster[self.map]['plegend'] = self.FindWindowById(self.wxId['plegend']).GetValue()
+        
+        self.raster[self.map]['pwidth'] = int(self.FindWindowById(self.wxId['pwidth']).GetValue())
+        self.properties['raster']['pwidth'] = self.raster[self.map]['pwidth']
+        self.raster[self.map]['pstyle'] = self.FindWindowById(self.wxId['pstyle']).GetStringSelection()
+        self.properties['raster']['pstyle'] = self.raster[self.map]['pstyle']
+            
+        # update settings for entire plot
         for axis in ('x-axis', 'y-axis'):
-            self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetValue()
+            self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetStringSelection()
             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()
 
+        if self.plottype == 'profile':
+            self.properties['marker']['color'] = self.FindWindowById(self.wxId['marker']['color']).GetColour()
+            self.properties['marker']['fill'] = self.FindWindowById(self.wxId['marker']['fill']).GetStringSelection()
+            self.properties['marker']['size'] = self.FindWindowById(self.wxId['marker']['size']).GetValue()
+            self.properties['marker']['type'] = self.FindWindowById(self.wxId['marker']['type']).GetValue()
+            self.properties['marker']['legend'] = self.FindWindowById(self.wxId['marker']['legend']).GetValue()
+
         self.properties['grid']['color'] = self.FindWindowById(self.wxId['grid']['color']).GetColour()
         self.properties['grid']['enabled'] = self.FindWindowById(self.wxId['grid']['enabled']).IsChecked()
 
+        # this makes more sense in the text properties, including for settings update. But will need to change
+        # layout for controls to text dialog too.
         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()
+        self.OnApply(None)
         fileSettings = {}
         UserSettings.ReadSettingsFile(settings = fileSettings)
-        fileSettings['profile'] = UserSettings.Get(group = 'profile')
-        file = UserSettings.SaveToFile(fileSettings)
-        self.parent.parent.GetLayerManager().goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file)
-        self.parent.SetGraphStyle()
-        if self.parent.profile:
-            self.parent.DrawPlot()
+        fileSettings[self.plottype] = UserSettings.Get(group = self.plottype)
+        UserSettings.SaveToFile(fileSettings)
+        self.parent.parent.GetLayerManager().goutput.WriteLog(_('Plot settings saved to file \'%s\'.') % UserSettings.filePath)
         self.Close()
 
     def OnApply(self, event):
         """!Button 'Apply' pressed. Does not close dialog"""
         self.UpdateSettings()
         self.parent.SetGraphStyle()
-        if self.parent.profile:
-            self.parent.DrawPlot()
+        p = self.parent.CreatePlotList()
+        self.parent.DrawPlot(p)
+
+    def OnOk(self, event):
+        """!Button 'OK' pressed"""
+        self.OnApply(None)
+        self.EndModal(wx.ID_OK)
         
     def OnCancel(self, event):
         """!Button 'Cancel' pressed"""
         self.Close()
+     

Modified: grass/branches/releasebranch_6_4/gui/wxpython/wxplot/profile.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/wxplot/profile.py	2012-08-31 12:13:47 UTC (rev 53024)
+++ grass/branches/releasebranch_6_4/gui/wxpython/wxplot/profile.py	2012-08-31 16:56:02 UTC (rev 53025)
@@ -65,14 +65,14 @@
         self.colorList =  ["blue", "red", "green", "yellow", "magenta", "cyan",
                            "aqua", "black", "grey", "orange", "brown", "purple", "violet",
                            "indigo"]
+
+        self._initOpts()
         
         if len(self.rasterList) > 0: # set raster name(s) from layer manager if a map is selected
             self.raster = self.InitRasterOpts(self.rasterList, self.plottype)
         else:
             self.raster = {}
-        
-        self._initOpts()
-        
+                
         # determine units (axis labels)
         if self.parent.Map.projinfo['units'] != '':
             self.xlabel = _('Distance (%s)') % self.parent.Map.projinfo['units']



More information about the grass-commit mailing list