""" 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. """ import dabo.ui # For now, 'wx' is the only valid UI. In the future, though, try changing # this to 'tk' or 'qt'... if not dabo.ui.loadUI('wx'): dabo.errorLog.write("Could not import wx.") class SimpleLabel(dabo.ui.dLabel): def initStyleProperties(self): self.Alignment = "Right" def initProperties(self): self.Width = 150 class MyForm(dabo.ui.dForm): def afterInit(self): self.Caption = "Simple Form with Controls" self.debug = True # output verbose self.instantiateControls() def instantiateControls(self): # The form will contain a panel, which will contain all # the controls. Otherwise, tab traversal won't work. self.addObject(dabo.ui.dPanel, "testPanel") panel = self.testPanel # a vertical sizer will contain several horizontal sizers vs = dabo.ui.dSizer("vertical") # Instantiate several dControls and dLabels into # separate horizontal sizers for obj in ((dabo.ui.dTextBox(panel), "txtCounty", "County"), (dabo.ui.dTextBox(panel), "txtCity", "City"), (dabo.ui.dTextBox(panel), "txtZipcode", "Zip"), (dabo.ui.dSpinner(panel), "spnPopulation", "Population"), (dabo.ui.dCheckBox(panel), "chkReviewed", "Reviewed"), (dabo.ui.dEditBox(panel), "edtComments", "Comments"), (dabo.ui.dSlider(panel), "sldFactor", "Factor"), (dabo.ui.dCommandButton(panel), "cmdOk", "Ok")): bs = dabo.ui.dSizer("horizontal") # Names, captions, and objects are all in the tuple: label = SimpleLabel(panel) if isinstance(obj[0], dabo.ui.dCheckBox): label.Caption = "" else: label.Caption = "%s:" % obj[2] bs.append(label, "fixed") object = obj[0] if isinstance(object, dabo.ui.dEditBox): layout = "expand" else: layout = "normal" if isinstance(object, dabo.ui.dCheckBox): object.Caption = "%s" % obj[2] object.Name = "%s" % obj[1] object.debug = True # output verbose bs.append(object, layout, 1) if isinstance(object, dabo.ui.dEditBox): vs.append(bs, "expand", 1) else: vs.append(bs, "expand") panel.Sizer = vs panel.Sizer.layout() self.Sizer = dabo.ui.dSizer("vertical") self.Sizer.append(panel, "expand", 1) self.Sizer.layout() if __name__ == "__main__": app = dabo.dApp() app.MainFormClass = MyForm app.setup() app.start()