X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7aa54cf7499777287f67288890c61493b9b5955a..1b62f00d8e3ec5437ab780cb3d73d299cc61e20c:/wxPython/tests/dynamicform.py diff --git a/wxPython/tests/dynamicform.py b/wxPython/tests/dynamicform.py new file mode 100644 index 0000000000..e65b3fddc5 --- /dev/null +++ b/wxPython/tests/dynamicform.py @@ -0,0 +1,62 @@ + + +from wxPython.wx import * + +class FieldData: + def __init__(self, name, label, shortHelp="", defValue="", + size=(-1, -1), style=0, ID=-1): + self.name = name + self.label = label + self.shortHelp = shortHelp + self.defValue = defValue + self.size = size + self.style = style + self.ID = ID + + +class DynamicForm(wxPanel): + def __init__(self, parent, ID, fieldData): + wxPanel.__init__(self, parent, ID) + + sizer = wxFlexGridSizer(cols=2, vgap=5, hgap=5) + for field in fieldData: + label = wxStaticText(self, -1, field.label) + sizer.Add(label, 0, wxALIGN_RIGHT) + text = wxTextCtrl(self, field.ID, field.defValue, + size=field.size, style=field.style) + if field.shortHelp: + text.SetToolTip(wxToolTip(field.shortHelp)) + self.__dict__["get_"+field.name] = text.GetValue + self.__dict__["set_"+field.name] = text.SetValue + sizer.Add(text, 0, wxEXPAND) + + sizer.Fit(self) + self.SetAutoLayout(true) + self.SetSizer(sizer) + + +class TestFrame(wxFrame): + testFields = [ + FieldData("fname", "First name:", "Enter someone's first name"), + FieldData("lname", "Last name:", "Enter someone's last name"), + FieldData("email", "Email address:", "just figure it out..."), + ] + def __init__(self): + wxFrame.__init__(self, None, -1, "This is a test") + form = DynamicForm(self, -1, self.testFields) + form.set_fname("Robin") + form.set_lname("Dunn") + self.form = form + self.Fit() + EVT_CLOSE(self, self.OnCloseWindow) + + def OnCloseWindow(self, evt): + print self.form.get_email() + self.Destroy() + + +app = wxPySimpleApp() +frame = TestFrame() +frame.Show(true) +app.MainLoop() +