]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/val.py
1 from wxPython
.wx
import *
4 class floatValidator(wxPyValidator
):
6 def __init__(self
, obj
=None, attrName
=""):
7 wxPyValidator
.__init
__(self
)
8 self
.numList
= ['1','2','3','4','5','6','7','8','9','0','.']
9 EVT_CHAR(self
, self
.OnChar
)
11 self
.attrName
= attrName
14 return floatValidator(self
.obj
, self
.attrName
)
16 def TransferToWindow(self
):
17 if self
.obj
and hasattr(self
.obj
, self
.attrName
):
18 tc
= wxPyTypeCast(self
.GetWindow(), "wxTextCtrl")
19 tc
.SetValue(str(getattr(self
.obj
, self
.attrName
)))
22 def TransferFromWindow(self
):
23 if self
.obj
and self
.attrName
:
24 tc
= wxPyTypeCast(self
.GetWindow(), "wxTextCtrl")
26 setattr(self
.obj
, self
.attrName
, float(text
))
30 def Validate(self
, win
):
31 tc
= wxPyTypeCast(self
.GetWindow(), "wxTextCtrl")
35 if x
not in self
.numList
:
40 def OnChar(self
, event
):
42 if key
< WXK_SPACE
or key
== WXK_DELETE
or key
> 255:
46 if chr(key
) in self
.numList
:
50 if not wxValidator_IsSilent():
53 # Returning without calling even.Skip eats the event before it
54 # gets to the text control
59 class MyDialog(wxDialog
):
60 def __init__(self
, parent
):
61 wxDialog
.__init
__(self
, parent
, -1, "hello")
63 self
.theValue
= 555.12
64 fltValidator
= floatValidator(self
, "theValue")
66 Vbox
= wxBoxSizer(wxVERTICAL
)
67 Tbox
= wxBoxSizer(wxHORIZONTAL
)
68 Tbox
.Add(wxStaticText(self
, -1, "Initial Balance"), 0, wxALL
,5)
69 Tbox
.Add(wxTextCtrl(self
, 13, "123.45", validator
= fltValidator
,
70 size
=(100, -1)), 0, wxALL
,5)
74 Tbox
= wxBoxSizer(wxHORIZONTAL
)
75 Tbox
.Add(wxButton(self
, wxID_OK
, "Ok"), 0, wxALL
,5)
76 Tbox
.Add(wxButton(self
, wxID_CANCEL
, "Cancel"), 0, wxALL
,5)
80 self
.SetAutoLayout(true
)
85 class TestFrame(wxFrame
):
86 def __init__(self
, parent
):
87 wxFrame
.__init
__(self
, parent
, -1, "Testing...", size
=(150,75))
88 wxButton(self
, 25, "Click Me")
89 EVT_BUTTON(self
, 25, self
.OnClick
)
92 def OnClick(self
, event
):
100 app
= wxPySimpleApp()
101 frame
= TestFrame(None)