''' SimpleFormWithControls.py This demo shows a subclass of dForm populated by dControl instances. Since this demo isn't connected to any data, we only need to import the ui layer. A good amount of the 'bulk' in this code has to do with setting up the vertical and horizontal sizers. This sample does not connect to a dApp object at all, so certain features, such as the form remembering its size and position, will not work. It does demonstrate how individual parts of Dabo can work independently from the whole. ''' import wx from dabo.ui import * class MyForm(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, -1, '') self.SetLabel("Simple Form with Controls") self.debug = True # output verbose self.instantiateControls() def instantiateControls(self): labelWidth = 150 labelAlignment = wx.ALIGN_RIGHT # The form will contain a panel, which will contain all # the controls. Otherwise, tab traversal won't work. panel = wx.Panel(self, -1) # a vertical sizer will contain several horizontal sizers vs = wx.BoxSizer(wx.VERTICAL) # Instantiate several dControls and dLabels into # separate horizontal sizers for obj in ((dTextBox(panel), "txtCounty", "County"), (dTextBox(panel), "txtCity", "City"), (dTextBox(panel), "txtZipcode", "Zip"), (dSpinner(panel), "spnPopulation", "Population"), (dCheckBox(panel), "chkReviewed", "Reviewed"), (dEditBox(panel), "edtComments", "Comments"), (dSlider(panel), "sldFactor", "Factor"), (dCommandButton(panel), "cmdOk", "Ok")): bs = wx.BoxSizer(wx.HORIZONTAL) # Names, captions, and objects are all in the tuple: label = dLabel(panel, style=labelAlignment|wx.ST_NO_AUTORESIZE) label.Width = labelWidth if isinstance(obj[0], dCheckBox): label.Caption = "" else: label.Caption = "%s:" % obj[2] bs.Add(label) object = obj[0] if isinstance(object, dEditBox): expandFlags = wx.EXPAND # Let EditBox expand vertically else: expandFlags = 0 if isinstance(object, dCheckBox): object.Caption = "%s" % obj[2] object.Name = "%s" % obj[1] object.debug = True # output verbose bs.Add(object, 1, expandFlags | wx.ALL, 0) if isinstance(object, dEditBox): vs.Add(bs, 1, wx.EXPAND) else: vs.Add(bs, 0, wx.EXPAND) panel.SetSizer(vs) panel.GetSizer().Layout() self.SetSizer(wx.BoxSizer(wx.VERTICAL)) self.GetSizer().Add(panel, 1, wx.EXPAND) self.GetSizer().Layout() if __name__ == "__main__": app = wx.PySimpleApp() form = MyForm(None) form.Show(True) app.MainLoop()