dPanel is a container for other controls. It is helpful in arranging controls into logical groupings. On Windows, it is required as the "background" of a form in order for the form to look "normal".
Some of the more useful properties for dPanel:
- BackColor - (RGB tuple or color name string): The color for this panel. If you do not set this explicitly, its appearance is handled by the underlying UI toolkit, making the panel appear as a native part of the form.
- ActiveControl - (dObject): Specifies which control in the panel has the keyboard focus.
- Buffered - (bool): If you are doing a lot of low-level drawing (see DrawObjects), setting this to
Trueusually improves the performance of the drawings and reduces flicker. Default=
Example: Create a panel and add a control
import dabo dabo.ui.loadUI("wx") class MainForm(dabo.ui.dForm): def afterInit(self): # Create an initial sizer to add to self.Sizer = dabo.ui.dSizer("horizontal") # Create a panel and add a control (in this case a label) pnl = self.Panel = dabo.ui.dPanel(self, BackColor=(255,200,200)) pnl.addObject(dabo.ui.dLabel, Name="MyLabel", Caption=" I am a Label ", FontSize=24) # add the panel to the sizer self.Sizer.append(pnl, "expand", proportion=1, valign="middle") self.Sizer.layout() if __name__ == "__main__": app = dabo.dApp() app.MainFormClass = MainForm app.start()
See the Dabo Class Documentation for an exhaustive documentation of this control's Properties and Methods. (Note that this documentation is no longer live, but it's still available via the Internet Archive).
If you really want to use the power of Dabo for a GUI display, you need to make even more use of Sizers. Sizers are one of the tricky things to come to grips with, but once you have, you will be away laughing.
The Sizer stores a bunch of rules about how to display (layout) your controls on the screen. The Sizer is not the parent of your control. It is the containing object that is the parent to your control. Typically the first containing object is the Form, and the one after that is probably going to be a panel. And you may well want to use more than one panel on a professional looking page. You can set you controls in place with fixed dimensions, but life is much happier when you use another sizer.
Example of how to add a sizer to a panel:
#!/usr/bin/env python # -*- coding: utf-8 -*- """ This sample code demonstrates how to add a sizer to a panel. In this example we create a dForm (MainForm) with a dSizer. On to this we add a dPanel (pnl), and a dSizer (psz). On to this we add two labels as examples of controls that could be added. """ import dabo dabo.ui.loadUI("wx") class MainForm(dabo.ui.dForm): def afterInit(self): self.Sizer = dabo.ui.dSizer("v") # self (MainForm) is the parent(containing object)using the property .Sizer pnl = self.Panel = dabo.ui.dPanel(self, BackColor="Yellow", FontSize=18) psz = pnl.Sizer = dabo.ui.dSizer("h") # pan.Sizer is the property to which this sizer is assigned lab1 = dabo.ui.dLabel(pnl, Caption="One") # pan= self.Panel is the parent(containing object) # the sizer is not the parent. It is the parent's rules. lab2 = dabo.ui.dLabel(pnl, Caption="Two") """In a typical family Dad, Mum and the kids live in a home. The kids (children) belong to Dad & Mum (the Parents), and the Parents set the rules for how the children will behave. Sizer is a property of any Containing Object, which 'stores the Rules' for how the child objects will be displayed (layed out). """ psz.append1x(lab1) # append the controls to the sizer which controls their layout psz.append1x(lab2) # Note that append1x is a nice shortcut command self.Sizer.append1x(pnl) # add the panel to the containing objects Sizer """Then use either the controlling sizer or the Containing object to apply the layout rules""" self.Sizer.layout() # Apply the controlling sizer layout rules #self.layout() # or we could have use the controlling object layout rules. if __name__ == "__main__": app = dabo.dApp() app.MainFormClass = MainForm app.start()
It is common practice to use the controlling sizer rules way of expressing the layout command as it makes it very clear what we are trying to achieve. Python and Dabo are BIG on making things understandable.