-
Notifications
You must be signed in to change notification settings - Fork 2
/
validators.py
55 lines (45 loc) · 1.71 KB
/
validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import wx
class NumericTextCtrlValidator(wx.Validator):
def __init__(self):
wx.Validator.__init__(self)
def Clone(self):
return NumericTextCtrlValidator()
def Validate(self, parent):
text_ctrl = self.GetWindow()
value = text_ctrl.GetValue()
if value.isdigit():
text_ctrl.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
text_ctrl.Refresh()
return True
else:
text_ctrl.SetBackgroundColour(wx.Colour(255, 128, 128))
text_ctrl.Refresh()
return False
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True
class FloatTextCtrlValidator(wx.Validator):
def __init__(self):
wx.Validator.__init__(self)
def Clone(self):
return FloatTextCtrlValidator()
def Validate(self, parent):
text_ctrl = self.GetWindow()
value = text_ctrl.GetValue()
if value.isdigit():
text_ctrl.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
text_ctrl.Refresh()
return True
elif value.replace('.','',1).isdigit() and value.count('.') < 2:
text_ctrl.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
text_ctrl.Refresh()
return True
else:
text_ctrl.SetBackgroundColour(wx.Colour(255, 128, 128))
text_ctrl.Refresh()
return False
def TransferToWindow(self):
return True
def TransferFromWindow(self):
return True