[GRASS-SVN] r44317 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 15 05:16:37 EST 2010


Author: martinl
Date: 2010-11-15 02:16:37 -0800 (Mon, 15 Nov 2010)
New Revision: 44317

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI: _GetValue() added
(merge r44315 from devbr6)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py	2010-11-15 10:15:27 UTC (rev 44316)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py	2010-11-15 10:16:37 UTC (rev 44317)
@@ -1274,17 +1274,13 @@
                             txt2.SetName("TextCtrl")
                             style = wx.EXPAND | wx.BOTTOM | wx.LEFT
                         
-                        if p.get('value', '') != '':
-                            # parameter previously set
+                        value = self._GetValue(p)
+                        # parameter previously set
+                        if value:
                             if txt2.GetName() == "SpinCtrl":
-                                txt2.SetValue(int(p['value']))
+                                txt2.SetValue(value)
                             else:
-                                txt2.SetValue(p['value'])
-                        elif p.get('default', '') != '':
-                            if txt2.GetName() == "SpinCtrl":
-                                txt2.SetValue(int(p['default']))
-                            else:
-                                txt2.SetValue(p['default'])
+                                txt2.SetValue(value)
                         
                         which_sizer.Add(item=txt2, proportion=0,
                                         flag=style, border=5)
@@ -1297,8 +1293,9 @@
                         cb = wx.ComboBox(parent = which_panel, id = wx.ID_ANY, value = p.get('default',''),
                                          size = globalvar.DIALOG_COMBOBOX_SIZE,
                                          choices = valuelist, style = wx.CB_DROPDOWN)
-                        if p.get('value', '') != '':
-                            cb.SetValue(p['value']) # parameter previously set
+                        value = self._GetValue(p)
+                        if value:
+                            cb.SetValue(value) # parameter previously set
                         which_sizer.Add( item=cb, proportion=0,
                                          flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border=5)
                         p['wxId'] = [ cb.GetId(), ]
@@ -1317,9 +1314,11 @@
                         len(p.get('key_desc', [])) > 1:
                     txt3 = wx.TextCtrl(parent=which_panel, value = p.get('default',''))
                     
-                    if p.get('value','') != '':
-                        txt3.SetValue(str(p['value'])) # parameter previously set
-
+                    value = self._GetValue(p)
+                    if value:
+                        # parameter previously set
+                        txt3.SetValue(str(value))
+                    
                     txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
                     style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
                 else:
@@ -1331,10 +1330,9 @@
                                            min=minValue, max=maxValue)
                         style = wx.BOTTOM | wx.LEFT | wx.RIGHT
                         
-                        if p.get('value', '') != '':
-                            txt3.SetValue(int(p['value'])) # parameter previously set
-                        elif p.get('default', '') != '':
-                            txt3.SetValue(int(p['default']))
+                        value = self._GetValue(p)
+                        if value:
+                            txt3.SetValue(int(value)) # parameter previously set
                         
                         txt3.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
                     else:
@@ -1342,8 +1340,9 @@
                                            validator = FloatValidator())
                         style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
                         
-                        if p.get('value', '') != '':
-                            txt3.SetValue(str(p['value'])) # parameter previously set
+                        value = self._GetValue(p)
+                        if value:
+                            txt3.SetValue(str(value)) # parameter previously set
                     
                 txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
                 
@@ -1401,10 +1400,11 @@
                         # we target the textctl here
                         p['wxId'] = [selection.GetChildren()[0].GetId(), ]
                         selection.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetValue)
-                    
-                    if p.get('value','') != '':
-                        selection.SetValue(p['value']) # parameter previously set
 
+                    value = self._GetValue(p)
+                    if value:
+                        selection.SetValue(value) # parameter previously set
+
                     which_sizer.Add(item=selection, proportion=0,
                                     flag=wx.ADJUST_MINSIZE| wx.BOTTOM | wx.LEFT | wx.RIGHT, border=5)
                     
@@ -1560,8 +1560,9 @@
                                                       buttonText=_('Browse'),
                                                       startDirectory=os.getcwd(), fileMode=0,
                                                       changeCallback=self.OnSetValue)
-                    if p.get('value','') != '':
-                        fbb.SetValue(p['value']) # parameter previously set
+                    value = self._GetValue(p)
+                    if value:
+                        fbb.SetValue(value) # parameter previously set
                     which_sizer.Add(item=fbb, proportion=0,
                                     flag=wx.EXPAND | wx.RIGHT, border=5)
                     
@@ -1725,6 +1726,15 @@
         panelsizer.Fit(self.notebook)
         
         self.Bind(EVT_DIALOG_UPDATE, self.OnUpdateDialog)
+
+    def _GetValue(self, p):
+        """!Get value or default value of given parameter
+
+        @param p parameter directory
+        """
+        if p.get('value', '') != '':
+            return p['value']
+        return p.get('default', '')
         
     def OnFileText(self, event):
         """File input interactively entered"""



More information about the grass-commit mailing list