[wxPython-users] Learning Boa and Sizers
Werner F. Bruhin
werner.bruhin at free.fr
Wed Aug 22 07:00:25 PDT 2007
Hi Duane,
Kaufman, Duane wrote:
> Hi,
>
> I am trying to teach myself about wxPython sizers, and Boa.
>
> I am using an example from the 'wxPython In Action' book (Chapter 11),
> and trying to use Boa to construct the staticboxsizer example
> (staticboxsizer and blockwindow). My attempts at using Boa to construct
> a similar example are in the suffixed _Boa files.
>
> Currently, I have been able to use Boa to re-construct this example, but
> only by hand-editing generated code. In particular, the collection
> editor for the boxSizerpanel will only allow the addition of the
> staticbox(es) (box1, box2, box3). The boxSizerpanel however, needs to be
> passed the _sizers_ for the staticbox, not the staticbox itself.
>
> I think I am missing some little detail, is there a way to do this in
> Boa without hand-editing generated code?
> =
You already created the staticbox'es and sizers in Boa, so I think your =
only problem is to change the code in FillStaticBoxSizer (I assume that =
you want to keep that as is and not generate that code with Boa).
Attached just the changed file.
Werner
-------------- next part --------------
#Boa:Frame:TestFrame
import wx
from blockwindow_Boa import BlockWindow
labels =3D "one two three four five six seven eight nine".split()
def create(parent):
return TestFrame(parent)
[wxID_TESTFRAME, wxID_TESTFRAMEBOX1, wxID_TESTFRAMEBOX2, wxID_TESTFRAMEBOX3=
, =
wxID_TESTFRAMEPANEL, =
] =3D [wx.NewId() for _init_ctrls in range(5)]
class TestFrame(wx.Frame):
def _init_coll_boxSizerpanel_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.staticBoxSizerbox1, 0, border=3D10, flag=3Dwx=
.ALL)
parent.AddWindow(self.staticBoxSizerbox2, 0, border=3D10, flag=3Dwx=
.ALL)
parent.AddWindow(self.staticBoxSizerbox3, 0, border=3D10, flag=3Dwx=
.ALL)
def _init_sizers(self):
# generated method, don't edit
self.staticBoxSizerbox1 =3D wx.StaticBoxSizer(box=3Dself.box1,
orient=3Dwx.VERTICAL)
self.staticBoxSizerbox2 =3D wx.StaticBoxSizer(box=3Dself.box2,
orient=3Dwx.VERTICAL)
self.staticBoxSizerbox3 =3D wx.StaticBoxSizer(box=3Dself.box3,
orient=3Dwx.VERTICAL)
self.boxSizerpanel =3D wx.BoxSizer(orient=3Dwx.HORIZONTAL)
self._init_coll_boxSizerpanel_Items(self.boxSizerpanel)
self.panel.SetSizer(self.boxSizerpanel)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=3DwxID_TESTFRAME, name=3Du'TestFrame',
parent=3Dprnt, pos=3Dwx.Point(183, 522), size=3Dwx.Size(644, =
259),
style=3Dwx.DEFAULT_FRAME_STYLE, title=3Du'StaticBoxSizer Test=
')
self.SetClientSize(wx.Size(628, 223))
self.panel =3D wx.Panel(id=3DwxID_TESTFRAMEPANEL, name=3Du'panel',
parent=3Dself, pos=3Dwx.Point(0, 0), size=3Dwx.Size(628, 223),
style=3Dwx.TAB_TRAVERSAL)
self.box1 =3D wx.StaticBox(id=3DwxID_TESTFRAMEBOX1, label=3Du'Box 1=
',
name=3Du'box1', parent=3Dself.panel, pos=3Dwx.Point(10, 10),
size=3Dwx.Size(10, 22), style=3D0)
self.box2 =3D wx.StaticBox(id=3DwxID_TESTFRAMEBOX2, label=3Du'Box 2=
',
name=3Du'box2', parent=3Dself.panel, pos=3Dwx.Point(40, 10),
size=3Dwx.Size(10, 22), style=3D0)
self.box3 =3D wx.StaticBox(id=3DwxID_TESTFRAMEBOX3, label=3Du'Box 3=
',
name=3Du'box3', parent=3Dself.panel, pos=3Dwx.Point(70, 10),
size=3Dwx.Size(10, 22), style=3D0)
self._init_sizers()
def __init__(self, parent):
self._init_ctrls(parent)
# Programmatically fill three static boxes with windows positioned =
inside them
self.FillStaticBoxSizer(self.box1, labels[0:3])
self.FillStaticBoxSizer(self.box2, labels[3:6])
self.FillStaticBoxSizer(self.box3, labels[6:9])
self.panel.GetSizer().Fit(self)
=
def FillStaticBoxSizer(self, box, itemlabels):
# then add items to it like normal
sizer =3D box.GetContainingSizer()
for itemlabel in itemlabels:
bw =3D BlockWindow(self.panel, label=3Ditemlabel)
sizer.Add(bw, 0, wx.ALL, 2)
sizer.Layout()
More information about the wxpython-users
mailing list