[GRASS-SVN] r61510 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 4 03:10:22 PDT 2014
Author: martinl
Date: 2014-08-04 03:10:22 -0700 (Mon, 04 Aug 2014)
New Revision: 61510
Modified:
grass/trunk/gui/wxpython/gui_core/widgets.py
Log:
wxGUI: new validators (EmailValidator, TimeISOValidator) by krejcmat (GSoC 2014)
Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py 2014-08-04 09:48:30 UTC (rev 61509)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py 2014-08-04 10:10:22 UTC (rev 61510)
@@ -14,6 +14,8 @@
- widgets::CoordinatesValidator
- widgets::IntegerValidator
- widgets::FloatValidator
+ - widgets::EmailValidator
+ - widgets::TimeISOValidator
- widgets::GListCtrl
- widgets::SearchModuleWidget
- widgets::ManageSettingsWidget
@@ -22,6 +24,9 @@
- widgets::BarscalesComboBox
- widgets::NArrowsComboBox
+ at todo:
+ - move validators to a separate file gui_core/validators.py
+
(C) 2008-2014 by the GRASS Development Team
This program is free software under the GNU General Public License
@@ -31,6 +36,7 @@
@author Enhancements by Michael Barton <michael.barton asu.edu>
@author Anna Kratochvilova <kratochanna gmail.com> (Google SoC 2011)
@author Stepan Turek <stepan.turek seznam.cz> (ManageSettingsWidget - created from GdalSelect)
+ at author Matej Krejci <matejkrejci gmail.com> (Google GSoC 2014; EmailValidator, TimeISOValidator)
"""
import os
@@ -586,6 +592,50 @@
"""Clone validator"""
return FloatValidator()
+class EmailValidator(BaseValidator):
+ """Validator for email input"""
+ def __init__(self):
+ BaseValidator.__init__(self)
+
+ def Validate(self):
+ """Validate input"""
+ textCtrl = self.GetWindow()
+ text = textCtrl.GetValue()
+ if text:
+ if re.match(r'\b[\w.-]+@[\w.-]+.\w{2,4}\b', text) is None:
+ self._notvalid()
+ return False
+
+ self._valid()
+ return True
+
+ def Clone(self):
+ """Clone validator"""
+ return EmailValidator()
+
+class TimeISOValidator(BaseValidator):
+ """Validator for time ISO format (YYYY-MM-DD) input"""
+ def __init__(self):
+ BaseValidator.__init__(self)
+
+ def Validate(self):
+ """Validate input"""
+ textCtrl = self.GetWindow()
+ text = textCtrl.GetValue()
+ if text:
+ try:
+ datetime.strptime(text, '%Y-%m-%d')
+ except:
+ self._notvalid()
+ return False
+
+ self._valid()
+ return True
+
+ def Clone(self):
+ """Clone validator"""
+ return TimeISOValidator()
+
class NTCValidator(wx.PyValidator):
"""validates input in textctrls, taken from wxpython demo"""
def __init__(self, flag = None):
More information about the grass-commit
mailing list