[GRASS-SVN] r42324 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 21 03:08:20 EDT 2010


Author: martinl
Date: 2010-05-21 03:08:11 -0400 (Fri, 21 May 2010)
New Revision: 42324

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
Log:
#1070 - don't use FloatSpin, validate input instead
(merge r42323 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-05-21 06:59:08 UTC (rev 42323)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-05-21 07:08:11 UTC (rev 42324)
@@ -11,6 +11,7 @@
  - cmdPanel
  - GrassGUIApp
  - GUI
+ - FloatValidator
 
  Copyright (C) 2000-2009 by the GRASS Development Team
 
@@ -74,11 +75,6 @@
 from wx.lib.newevent import NewEvent
 
 try:
-    import wx.lib.agw.floatspin as FS
-except ImportError:
-    FS = None
-
-try:
     import xml.etree.ElementTree as etree
 except ImportError:
     import elementtree.ElementTree as etree # Python <= 2.4
@@ -794,10 +790,12 @@
         if self.goutput:
             self.goutput.SetSashPosition(int(self.GetSize()[1] * .75))
 
-    def updateValuesHook(self):
+    def updateValuesHook(self, event = None):
         """!Update status bar data"""
-        self.SetStatusText(' '.join(self.notebookpanel.createCmd(ignoreErrors = True)) )
-
+        self.SetStatusText(' '.join(self.notebookpanel.createCmd(ignoreErrors = True)))
+        if event:
+            event.Skip()
+        
     def OnKeyUp(self, event):
         """!Key released (check hot-keys)"""
         try:
@@ -1241,19 +1239,9 @@
                             txt3.SetValue(int(p['value'])) # parameter previously set
                         
                         txt3.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
-                    elif FS:
-                        txt3 = FS.FloatSpin(parent = which_panel, id = wx.ID_ANY,
-                                            size = globalvar.DIALOG_SPIN_SIZE,
-                                            min_val = minValue, max_val = maxValue)
-                        txt3.SetDigits(3)
-                        style = wx.BOTTOM | wx.LEFT | wx.RIGHT
-                        
-                        if p.get('value', '') != '':
-                            txt3.SetValue(float(p['value'])) # parameter previously set
-                        
-                        txt3.Bind(FS.EVT_FLOATSPIN, self.OnSetValue)
                     else:
-                        txt3 = wx.TextCtrl(parent=which_panel, value = p.get('default',''))
+                        txt3 = wx.TextCtrl(parent=which_panel, value = p.get('default',''),
+                                           validator = FloatValidator())
                         style = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
                         
                         if p.get('value', '') != '':
@@ -1618,12 +1606,13 @@
                     p[ 'value' ] = colorchooser.GetLabel()
         self.OnUpdateValues()
 
-    def OnUpdateValues(self):
-        """
-        If we were part of a richer interface, report back the current command being built.
+    def OnUpdateValues(self, event = None):
+        """!If we were part of a richer interface, report back the
+        current command being built.
 
-        This method should be set by the parent of this panel if needed. It's a hook, actually.
-        Beware of what is 'self' in the method def, though. It will be called with no arguments.
+        This method should be set by the parent of this panel if
+        needed. It's a hook, actually.  Beware of what is 'self' in
+        the method def, though. It will be called with no arguments.
         """
         pass
 
@@ -1690,7 +1679,7 @@
                 else:
                     porf['value'] = me.GetValue()
         
-        self.OnUpdateValues()
+        self.OnUpdateValues(event)
         
         event.Skip()
         
@@ -1925,6 +1914,47 @@
                         return p.get('name', None)
         return None
 
+class FloatValidator(wx.PyValidator):
+    """!Validator for floating-point input"""
+    def __init__(self):
+        wx.PyValidator.__init__(self)
+        
+        self.Bind(wx.EVT_TEXT, self.OnText) 
+        
+    def Clone(self):
+        """!Clone validator"""
+        return FloatValidator()
+
+    def Validate(self):
+        """Validate input"""
+        textCtrl = self.GetWindow()
+        text = textCtrl.GetValue()
+        try:
+            float(text)
+        except ValueError:
+            textCtrl.SetBackgroundColour("grey")
+            textCtrl.SetFocus()
+            textCtrl.Refresh()
+            return False
+        
+        textCtrl.SetBackgroundColour(
+            wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
+        textCtrl.Refresh()
+        
+        return True
+
+    def OnText(self, event):
+        """!Do validation"""
+        self.Validate()
+        
+        event.Skip()
+        
+    def TransferToWindow(self):
+        return True # Prevent wxDialog from complaining.
+    
+    def TransferFromWindow(self):
+        return True # Prevent wxDialog from complaining.
+     
 if __name__ == "__main__":
 
     if len(sys.argv) == 1:



More information about the grass-commit mailing list