def testAll(self): """Create a dForm and populate it with example dWidgets.""" frame = ui.dForm(Name="formTestAll") frame.Caption = "Test of all the dControls" frame.LogEvents = logEvents panel = frame.addObject(ui.dScrollPanel, "panelTest") panel.SetScrollbars(10,10,50,50) labelWidth = 150 vs = ui.dSizer("vertical") # Get all the python modules in this directory into a list: modules = [modname.split(".")[0] for modname in os.listdir(".") if modname[-3:] == ".py"] for modname in sorted(modules): print "==> ", modname # if the module has a test class, instantiate it: if modname == "__init__": # importing __init__ will pollute the dabo.ui namespace and cause # isinstance() problems. continue try: mod = __import__(modname) except ImportError, e: print "ImportError:", e continue objname = "_%s_test" % modname if objname in mod.__dict__: print "Trying to instantiate %s..." % objname try: obj = mod.__dict__[objname](panel) except StandardError, e: print "+++++++++++++++++++++++++++++++++++++++" print "+++ Instantiating %s caused:" % objname print traceback.print_exception(*sys.exc_info()) print "+++++++++++++++++++++++++++++++++++++++" continue if objname == "_dToolBar_test": frame.ToolBar = obj break bs = ui.dSizer("horizontal") label = ui.dLabel(panel, Alignment="Right", AutoResize=False, Width=labelWidth) label.Caption = "%s:" % modname bs.append(label) if isinstance(obj, ui.dEditBox): layout = "expand" else: layout = "normal" bs.append(obj, layout) if isinstance(obj, ui.dEditBox): vs.append(bs, "expand") else: vs.append(bs, "expand")
def afterInit(self): hs = self.Sizer = dSizer("h") but_props = { "FontBold": True, "ShowInBrowser": False, "OnHit": self.onHit_but, "VisitedUnderline": False, "LinkUnderline": False, "VisitedColor": "black", "HoverUnderline": False, "LinkColor": "black" } left_but = dHyperLink(self, Name="butLeft", Caption=" < ", **but_props) right_but = dHyperLink(self, Name="butRight", Caption=" > ", **but_props) lbl = dLabel(self, Name="lblMonthYear", FontBold=True) hs.appendSpacer(20) hs.append(left_but) hs.appendSpacer(10) hs.append(lbl, alignment="middle") hs.appendSpacer(10) hs.append(right_but) hs.appendSpacer(20)
def afterInit(self): self.dummy = DummyTextBox(self) vs = self.Sizer = dSizer("v") hs = dSizer("h") hs.append(Day(self), "expand") hs.append1x(Static(self)) vs.append(hs, "expand") vs.append1x(DiaryView(self)) vs.append1x(DiaryEdit(self)) parent = self.Parent diary = self.diary self.key_actions = { (dKeys.key_Enter, dKeys.key_Numpad_enter): (diary.setFocus, ()), (ord("t"), ord("T")): (parent.setFocusToToday, ()), (ord("+"), ord("=")): (self.setFocusToInterval, ("days", 1)), (ord("-"),): (self.setFocusToInterval, ("days", -1)), (ord("["),): (self.setFocusToInterval, ("months", -1)), (ord("]"),): (self.setFocusToInterval, ("months", 1))}
def afterInit(self): self.dummy = DummyTextBox(self) vs = self.Sizer = dSizer("v") hs = dSizer("h") hs.append(Day(self), "expand") hs.append1x(Static(self)) vs.append(hs, "expand") vs.append1x(DiaryView(self)) vs.append1x(DiaryEdit(self)) parent = self.Parent diary = self.diary self.key_actions = { (dKeys.key_Enter, dKeys.key_Numpad_enter): (diary.setFocus, ()), (ord("t"), ord("T")): (parent.setFocusToToday, ()), (ord("+"), ord("=")): (self.setFocusToInterval, ("days", 1)), (ord("-"), ): (self.setFocusToInterval, ("days", -1)), (ord("["), ): (self.setFocusToInterval, ("months", -1)), (ord("]"), ): (self.setFocusToInterval, ("months", 1)) }
def afterInit(self): self._appendCaption = "" dcon = self.Connection if dcon is None: # use in-memory test sqlite database dcon = self.Connection = dabo.db.connect(":memory:") con = dcon._connection con.executescript(open("./create_tables.sql").read()) self._appendCaption = "Temporary Database" self._instantiatedLayouts = {} vs = self.Sizer = dSizer("v") vs.appendSpacer(5) vs.append(PnlNavigation(self, Name="pnlNavigation"), alignment="center") vs.appendSpacer(5) self.updateLayout()
def afterInit(self): hs = self.Sizer = dSizer("h") but_props = {"FontBold": True, "ShowInBrowser": False, "OnHit": self.onHit_but, "VisitedUnderline": False, "LinkUnderline": False, "VisitedColor": "black", "HoverUnderline": False, "LinkColor": "black"} left_but = dHyperLink(self, Name="butLeft", Caption=" < ", **but_props) right_but = dHyperLink(self, Name="butRight", Caption=" > ", **but_props) lbl = dLabel(self, Name="lblMonthYear", FontBold=True) hs.appendSpacer(20) hs.append(left_but) hs.appendSpacer(10) hs.append(lbl, alignment="middle") hs.appendSpacer(10) hs.append(right_but) hs.appendSpacer(20)
def runTest(self, classRefs, *args, **kwargs): if not isinstance(classRefs, (tuple, list)): classRefs = (classRefs, ) isDialog = False if issubclass(classRefs[0], (wx.Frame, wx.Dialog)): # Can't display a frame within another frame, so create this # class as the main frame frame = classRefs[0](None, *args, **kwargs) isDialog = (issubclass(classRefs[0], wx.Dialog)) else: frame = ui.dForm(Name="formTest") panel = frame.addObject(ui.dPanel, Name="panelTest") panel.Sizer = ui.dSizer("Vertical") frame.Sizer.append(panel, 1, "expand") frame.testObjects = [] for class_ in classRefs: obj = class_(parent=panel, LogEvents=logEvents, *args, **kwargs) panel.Sizer.append(obj, "expand") frame.testObjects.append(obj) # This will get a good approximation of the required size w, h = panel.Sizer.GetMinSize() # Some controls don't report sizing correctly, so set a minimum w = max(w, 400) h = max(h, 300) frame.Size = ((w + 10, h + 30)) if len(classRefs) > 1: frame.Caption = "Test of multiple objects" else: frame.Caption = "Test of %s" % obj.BaseClass.__name__ obj.setFocus() if isDialog: ret = frame.ShowModal() print ret frame.Destroy() else: frame.Show() frame.Layout() self.app.start()
def runTest(self, classRefs, *args, **kwargs): if not isinstance(classRefs, (tuple, list)): classRefs = (classRefs,) isDialog = False if issubclass(classRefs[0], (wx.Frame, wx.Dialog)): # Can't display a frame within another frame, so create this # class as the main frame frame = classRefs[0](None, *args, **kwargs) isDialog = (issubclass(classRefs[0], wx.Dialog)) else: frame = ui.dForm(Name="formTest") panel = frame.addObject(ui.dPanel, Name="panelTest") panel.Sizer = ui.dSizer("Vertical") frame.Sizer.append(panel, 1, "expand") frame.testObjects = [] for class_ in classRefs: obj = class_(parent=panel, LogEvents=logEvents, *args, **kwargs) panel.Sizer.append(obj, "expand") frame.testObjects.append(obj) # This will get a good approximation of the required size w,h = panel.Sizer.GetMinSize() # Some controls don't report sizing correctly, so set a minimum w = max(w, 400) h = max(h, 300) frame.Size = ( (w+10, h+30) ) if len(classRefs) > 1: frame.Caption = "Test of multiple objects" else: frame.Caption = "Test of %s" % obj.BaseClass.__name__ obj.setFocus() if isDialog: ret = frame.ShowModal() print ret frame.Destroy() else: frame.Show() frame.Layout() self.app.start()
label = ui.dLabel(panel, Alignment="Right", AutoResize=False, Width=labelWidth) label.Caption = "%s:" % modname bs.append(label) if isinstance(obj, ui.dEditBox): layout = "expand" else: layout = "normal" bs.append(obj, layout) if isinstance(obj, ui.dEditBox): vs.append(bs, "expand") else: vs.append(bs, "expand") panel.Sizer = vs fs = frame.Sizer = ui.dSizer("vertical") fs.append(panel, "expand", 1) fs.layout() self.app.MainForm = frame self.app.start() if __name__ == "__main__": t = Test() t.testAll()
def testAll(self): """Create a dForm and populate it with example dWidgets.""" frame = ui.dForm(Name="formTestAll") frame.Caption = "Test of all the dControls" frame.LogEvents = logEvents panel = frame.addObject(ui.dScrollPanel, "panelTest") panel.SetScrollbars(10, 10, 50, 50) labelWidth = 150 vs = ui.dSizer("vertical") # Get all the python modules in this directory into a list: modules = [ modname.split(".")[0] for modname in os.listdir(".") if modname[-3:] == ".py" ] for modname in sorted(modules): print "==> ", modname # if the module has a test class, instantiate it: if modname == "__init__": # importing __init__ will pollute the dabo.ui namespace and cause # isinstance() problems. continue try: mod = __import__(modname) except ImportError, e: print "ImportError:", e continue objname = "_%s_test" % modname if objname in mod.__dict__: print "Trying to instantiate %s..." % objname try: obj = mod.__dict__[objname](panel) except StandardError, e: print "+++++++++++++++++++++++++++++++++++++++" print "+++ Instantiating %s caused:" % objname print traceback.print_exception(*sys.exc_info()) print "+++++++++++++++++++++++++++++++++++++++" continue if objname == "_dToolBar_test": frame.ToolBar = obj break bs = ui.dSizer("horizontal") label = ui.dLabel(panel, Alignment="Right", AutoResize=False, Width=labelWidth) label.Caption = "%s:" % modname bs.append(label) if isinstance(obj, ui.dEditBox): layout = "expand" else: layout = "normal" bs.append(obj, layout) if isinstance(obj, ui.dEditBox): vs.append(bs, "expand") else: vs.append(bs, "expand")
AutoResize=False, Width=labelWidth) label.Caption = "%s:" % modname bs.append(label) if isinstance(obj, ui.dEditBox): layout = "expand" else: layout = "normal" bs.append(obj, layout) if isinstance(obj, ui.dEditBox): vs.append(bs, "expand") else: vs.append(bs, "expand") panel.Sizer = vs fs = frame.Sizer = ui.dSizer("vertical") fs.append(panel, "expand", 1) fs.layout() self.app.MainForm = frame self.app.start() if __name__ == "__main__": t = Test() t.testAll()
def createControls(self): self.Caption = _("Connection Editor") self.bg = dui.dPanel(self, BackColor="LightSteelBlue") gbsz = dui.dGridSizer(VGap=12, HGap=5, MaxCols=2) # Add the fields # Connection Dropdown cap = dui.dLabel(self.bg, Caption=_("Connection")) ctl = dui.dDropdownList(self.bg, Choices=list(self.connDict.keys()), RegID="connectionSelector", OnHit=self.onConnectionChange) btn = dui.dButton(self.bg, Caption=_("Edit Name"), RegID="cxnEdit", OnHit=self.onCxnEdit) hsz = dui.dSizer("h") hsz.append(ctl) hsz.appendSpacer(10) hsz.append(btn) btn = dui.dButton(self.bg, Caption=_("Delete This Connection"), RegID="cxnDelete", DynamicEnabled=self.hasMultipleConnections, OnHit=self.onCxnDelete) hsz.appendSpacer(10) hsz.append(btn) gbsz.append(cap, halign="right", valign="middle") gbsz.append(hsz, valign="middle") # Backend Type cap = dui.dLabel(self.bg, Caption=_("Database Type")) ctl = dui.dDropdownList(self.bg, RegID="DbType", Choices=["MySQL", "Firebird", "PostgreSQL", "MsSQL", "SQLite"], DataSource="form", DataField="dbtype", OnHit=self.onDbTypeChanged) gbsz.append(cap, halign="right") gbsz.append(ctl) self.dbTypeSelector = ctl # Host cap = dui.dLabel(self.bg, Caption=_("Host")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="host") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.hostText = ctl # Port cap = dui.dLabel(self.bg, Caption=_("Port")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="port") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.portText = ctl # Database cap = dui.dLabel(self.bg, Caption=_("Database")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="database") hsz = dui.dSizer("h") self.btnDbSelect = dui.dButton(self.bg, Caption=" ... ", RegID="btnDbSelect", Visible=False, OnHit=self.onDbSelect) hsz.append1x(ctl) hsz.appendSpacer(2) hsz.append(self.btnDbSelect, 0, "x") gbsz.append(cap, halign="right") gbsz.append(hsz, "expand") self.dbText = ctl # Username cap = dui.dLabel(self.bg, Caption=_("User Name")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="user") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.userText = ctl # Password cap = dui.dLabel(self.bg, Caption=_("Password")) ctl = dui.dTextBox(self.bg, PasswordEntry=True, DataSource="form", DataField="password") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.pwText = ctl # Open Button btnSizer1 = dui.dSizer("h") btnSizer2 = dui.dSizer("h") btnTest = dui.dButton(self.bg, RegID="btnTest", Caption=_("Test..."), OnHit=self.onTest) btnSave = dui.dButton(self.bg, RegID="btnSave", Caption=_("Save"), OnHit=self.onSave) btnNewConn = dui.dButton(self.bg, RegID="btnNewConn", Caption=_("New Connection"), OnHit=self.onNewConn) btnNewFile = dui.dButton(self.bg, RegID="btnNewFile", Caption=_("New File"), OnHit=self.onNewFile) btnOpen = dui.dButton(self.bg, RegID="btnOpen", Caption=_("Open File..."), OnHit=self.onOpen) btnSizer1.append(btnTest, 0, border=3) btnSizer1.append(btnSave, 0, border=3) btnSizer2.append(btnNewConn, 0, border=3) btnSizer2.append(btnNewFile, 0, border=3) btnSizer2.append(btnOpen, 0, border=3) gbsz.setColExpand(True, 1) self.gridSizer = gbsz sz = self.bg.Sizer = dui.dSizer("v") sz.append(gbsz, 0, "expand", halign="center", border=20) sz.append(btnSizer1, 0, halign="center") sz.append(btnSizer2, 0, halign="center") # Only create the 'Set Crypto Key' button if PyCrypto is installed try: from Crypto.Cipher import DES3 as _TEST_DES3 self._showKeyButton = True del _TEST_DES3 except ImportError: self._showKeyButton = False if self._showKeyButton: self.cryptoKeyButton = dui.dButton(self.bg, Caption=_("Set Crypto Key"), OnHit=self.onSetCrypto) btnSizer1.append(self.cryptoKeyButton, 0, halign="center", border=3) self.Sizer = dui.dSizer("h") self.Sizer.append(self.bg, 1, "expand", halign="center") self.Layout()
def createControls(self): self.Caption = _("Connection Editor") self.bg = dui.dPanel(self, BackColor="LightSteelBlue") gbsz = dui.dGridSizer(VGap=12, HGap=5, MaxCols=2) # Add the fields # Connection Dropdown cap = dui.dLabel(self.bg, Caption=_("Connection")) ctl = dui.dDropdownList(self.bg, Choices=self.connDict.keys(), RegID="connectionSelector", OnHit=self.onConnectionChange) btn = dui.dButton(self.bg, Caption=_("Edit Name"), RegID="cxnEdit", OnHit=self.onCxnEdit) hsz = dui.dSizer("h") hsz.append(ctl) hsz.appendSpacer(10) hsz.append(btn) btn = dui.dButton(self.bg, Caption=_("Delete This Connection"), RegID="cxnDelete", DynamicEnabled=self.hasMultipleConnections, OnHit=self.onCxnDelete) hsz.appendSpacer(10) hsz.append(btn) gbsz.append(cap, halign="right", valign="middle") gbsz.append(hsz, valign="middle") # Backend Type cap = dui.dLabel(self.bg, Caption=_("Database Type")) ctl = dui.dDropdownList(self.bg, RegID="DbType", Choices=["MySQL", "Firebird", "PostgreSQL", "MsSQL", "SQLite"], DataSource="form", DataField="dbtype", OnHit=self.onDbTypeChanged) gbsz.append(cap, halign="right") gbsz.append(ctl) self.dbTypeSelector = ctl # Host cap = dui.dLabel(self.bg, Caption=_("Host")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="host") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.hostText = ctl # Port cap = dui.dLabel(self.bg, Caption=_("Port")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="port") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.portText = ctl # Database cap = dui.dLabel(self.bg, Caption=_("Database")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="database") hsz = dui.dSizer("h") self.btnDbSelect = dui.dButton(self.bg, Caption=" ... ", RegID="btnDbSelect", Visible=False, OnHit=self.onDbSelect) hsz.append1x(ctl) hsz.appendSpacer(2) hsz.append(self.btnDbSelect, 0, "x") gbsz.append(cap, halign="right") gbsz.append(hsz, "expand") self.dbText = ctl # Username cap = dui.dLabel(self.bg, Caption=_("User Name")) ctl = dui.dTextBox(self.bg, DataSource="form", DataField="user") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.userText = ctl # Password cap = dui.dLabel(self.bg, Caption=_("Password")) ctl = dui.dTextBox(self.bg, PasswordEntry=True, DataSource="form", DataField="password") gbsz.append(cap, halign="right") gbsz.append(ctl, "expand") self.pwText = ctl # Open Button btnSizer1 = dui.dSizer("h") btnSizer2 = dui.dSizer("h") btnTest = dui.dButton(self.bg, RegID="btnTest", Caption=_("Test..."), OnHit=self.onTest) btnSave = dui.dButton(self.bg, RegID="btnSave", Caption=_("Save"), OnHit=self.onSave) btnNewConn = dui.dButton(self.bg, RegID="btnNewConn", Caption=_("New Connection"), OnHit=self.onNewConn) btnNewFile = dui.dButton(self.bg, RegID="btnNewFile", Caption=_("New File"), OnHit=self.onNewFile) btnOpen = dui.dButton(self.bg, RegID="btnOpen", Caption=_("Open File..."), OnHit=self.onOpen) btnSizer1.append(btnTest, 0, border=3) btnSizer1.append(btnSave, 0, border=3) btnSizer2.append(btnNewConn, 0, border=3) btnSizer2.append(btnNewFile, 0, border=3) btnSizer2.append(btnOpen, 0, border=3) gbsz.setColExpand(True, 1) self.gridSizer = gbsz sz = self.bg.Sizer = dui.dSizer("v") sz.append(gbsz, 0, "expand", halign="center", border=20) sz.append(btnSizer1, 0, halign="center") sz.append(btnSizer2, 0, halign="center") # Only create the 'Set Crypto Key' button if PyCrypto is installed try: from Crypto.Cipher import DES3 as _TEST_DES3 self._showKeyButton = True del _TEST_DES3 except ImportError: self._showKeyButton = False if self._showKeyButton: self.cryptoKeyButton = dui.dButton(self.bg, Caption=_("Set Crypto Key"), OnHit=self.onSetCrypto) btnSizer1.append(self.cryptoKeyButton, 0, halign="center", border=3) self.Sizer = dui.dSizer("h") self.Sizer.append(self.bg, 1, "expand", halign="center") self.Layout()