]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/dynamicform.py
3 from wxPython
.wx
import *
6 def __init__(self
, name
, label
, shortHelp
="", defValue
="",
7 size
=(-1, -1), style
=0, ID
=-1):
10 self
.shortHelp
= shortHelp
11 self
.defValue
= defValue
17 class DynamicForm(wxPanel
):
18 def __init__(self
, parent
, ID
, fieldData
):
19 wxPanel
.__init
__(self
, parent
, ID
)
21 sizer
= wxFlexGridSizer(cols
=2, vgap
=5, hgap
=5)
22 for field
in fieldData
:
23 label
= wxStaticText(self
, -1, field
.label
)
24 sizer
.Add(label
, 0, wxALIGN_RIGHT
)
25 text
= wxTextCtrl(self
, field
.ID
, field
.defValue
,
26 size
=field
.size
, style
=field
.style
)
28 text
.SetToolTip(wxToolTip(field
.shortHelp
))
29 self
.__dict
__["get_"+field
.name
] = text
.GetValue
30 self
.__dict
__["set_"+field
.name
] = text
.SetValue
31 sizer
.Add(text
, 0, wxEXPAND
)
34 self
.SetAutoLayout(true
)
38 class TestFrame(wxFrame
):
40 FieldData("fname", "First name:", "Enter someone's first name"),
41 FieldData("lname", "Last name:", "Enter someone's last name"),
42 FieldData("email", "Email address:", "just figure it out..."),
45 wxFrame
.__init
__(self
, None, -1, "This is a test")
46 form
= DynamicForm(self
, -1, self
.testFields
)
47 form
.set_fname("Robin")
48 form
.set_lname("Dunn")
51 EVT_CLOSE(self
, self
.OnCloseWindow
)
53 def OnCloseWindow(self
, evt
):
54 print self
.form
.get_email()