Pārlūkot izejas kodu

wxGUI: fix validators (partial backport of #1069 and #1418) (#1427)

Anna Petrasova 4 gadi atpakaļ
vecāks
revīzija
18803e7221
1 mainītis faili ar 14 papildinājumiem un 15 dzēšanām
  1. 14 15
      gui/wxpython/gui_core/widgets.py

+ 14 - 15
gui/wxpython/gui_core/widgets.py

@@ -578,14 +578,18 @@ class BaseValidator(Validator):
 
 
     def OnText(self, event):
     def OnText(self, event):
         """Do validation"""
         """Do validation"""
-        self.Validate()
+        self._validate(win=event.GetEventObject())
 
 
         event.Skip()
         event.Skip()
 
 
-    def Validate(self):
+    def Validate(self, parent):
+        """Is called upon closing wx.Dialog"""
+        win = self.GetWindow()
+        return self._validate(win)
+
+    def _validate(self, win):
         """Validate input"""
         """Validate input"""
-        textCtrl = self.GetWindow()
-        text = textCtrl.GetValue()
+        text = win.GetValue()
 
 
         if text:
         if text:
             try:
             try:
@@ -601,7 +605,6 @@ class BaseValidator(Validator):
         textCtrl = self.GetWindow()
         textCtrl = self.GetWindow()
 
 
         textCtrl.SetBackgroundColour("grey")
         textCtrl.SetBackgroundColour("grey")
-        textCtrl.SetFocus()
         textCtrl.Refresh()
         textCtrl.Refresh()
 
 
     def _valid(self):
     def _valid(self):
@@ -626,11 +629,9 @@ class CoordinatesValidator(BaseValidator):
     def __init__(self):
     def __init__(self):
         BaseValidator.__init__(self)
         BaseValidator.__init__(self)
 
 
-    def Validate(self):
+    def _validate(self, win):
         """Validate input"""
         """Validate input"""
-
-        textCtrl = self.GetWindow()
-        text = textCtrl.GetValue()
+        text = win.GetValue()
         if text:
         if text:
             try:
             try:
                 text = text.split(',')
                 text = text.split(',')
@@ -683,10 +684,9 @@ class EmailValidator(BaseValidator):
     def __init__(self):
     def __init__(self):
         BaseValidator.__init__(self)
         BaseValidator.__init__(self)
 
 
-    def Validate(self):
+    def _validate(self, win):
         """Validate input"""
         """Validate input"""
-        textCtrl = self.GetWindow()
-        text = textCtrl.GetValue()
+        text = win.GetValue()
         if text:
         if text:
             if re.match(r'\b[\w.-]+@[\w.-]+.\w{2,4}\b', text) is None:
             if re.match(r'\b[\w.-]+@[\w.-]+.\w{2,4}\b', text) is None:
                 self._notvalid()
                 self._notvalid()
@@ -706,10 +706,9 @@ class TimeISOValidator(BaseValidator):
     def __init__(self):
     def __init__(self):
         BaseValidator.__init__(self)
         BaseValidator.__init__(self)
 
 
-    def Validate(self):
+    def _validate(self, win):
         """Validate input"""
         """Validate input"""
-        textCtrl = self.GetWindow()
-        text = textCtrl.GetValue()
+        text = win.GetValue()
         if text:
         if text:
             try:
             try:
                 datetime.strptime(text, '%Y-%m-%d')
                 datetime.strptime(text, '%Y-%m-%d')