5 The validator used in this example shows how the validator
6 can be used to transfer data to and from each text control
7 automatically when the dialog is shown and dismissed."""
10 class DataXferValidator(wx
.PyValidator
):
11 def __init__(self
, data
, key
):
12 wx
.PyValidator
.__init
__(self
)
18 Note that every validator must implement the Clone() method.
20 return DataXferValidator(self
.data
, self
.key
)
22 def Validate(self
, win
):
25 def TransferToWindow(self
):
26 textCtrl
= self
.GetWindow()
27 textCtrl
.SetValue(self
.data
.get(self
.key
, ""))
30 def TransferFromWindow(self
):
31 textCtrl
= self
.GetWindow()
32 self
.data
[self
.key
] = textCtrl
.GetValue()
37 class MyDialog(wx
.Dialog
):
38 def __init__(self
, data
):
39 wx
.Dialog
.__init
__(self
, None, -1, "Validators: data transfer")
41 # Create the text controls
42 about
= wx
.StaticText(self
, -1, about_txt
)
43 name_l
= wx
.StaticText(self
, -1, "Name:")
44 email_l
= wx
.StaticText(self
, -1, "Email:")
45 phone_l
= wx
.StaticText(self
, -1, "Phone:")
47 name_t
= wx
.TextCtrl(self
, validator
=DataXferValidator(data
, "name"))
48 email_t
= wx
.TextCtrl(self
, validator
=DataXferValidator(data
, "email"))
49 phone_t
= wx
.TextCtrl(self
, validator
=DataXferValidator(data
, "phone"))
51 # Use standard button IDs
52 okay
= wx
.Button(self
, wx
.ID_OK
)
54 cancel
= wx
.Button(self
, wx
.ID_CANCEL
)
57 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
58 sizer
.Add(about
, 0, wx
.ALL
, 5)
59 sizer
.Add(wx
.StaticLine(self
), 0, wx
.EXPAND|wx
.ALL
, 5)
61 fgs
= wx
.FlexGridSizer(3, 2, 5, 5)
62 fgs
.Add(name_l
, 0, wx
.ALIGN_RIGHT
)
63 fgs
.Add(name_t
, 0, wx
.EXPAND
)
64 fgs
.Add(email_l
, 0, wx
.ALIGN_RIGHT
)
65 fgs
.Add(email_t
, 0, wx
.EXPAND
)
66 fgs
.Add(phone_l
, 0, wx
.ALIGN_RIGHT
)
67 fgs
.Add(phone_t
, 0, wx
.EXPAND
)
69 sizer
.Add(fgs
, 0, wx
.EXPAND|wx
.ALL
, 5)
71 btns
= wx
.StdDialogButtonSizer()
73 btns
.AddButton(cancel
)
75 sizer
.Add(btns
, 0, wx
.EXPAND|wx
.ALL
, 5)
81 app
= wx
.PySimpleApp()
83 data
= { "name" : "Jordyn Dunn" }
88 wx
.MessageBox("You entered these values:\n\n" +