[wxPython] wxSizer, nested sizers and spacers

I'm trying to move from using layout constraints to
the wonderful world of wxSizers. However, I have come
across what is undoubtedly a pretty basic problem that
I can't see my way through.

The problem boils down to the behaviour of spacers in
nested sizers.

If I create a wxStaticText control (lbl1) and a
wxTextCtrl (fld1) I can lay them out vertically with
spacers above and below with:

box=wxBoxSizer(wxVERTICAL)
box.Add(1,1,1,wxEXPAND)
box.Add(self.lbl1)
box.Add(self.fld1)
box.Add(1,1,1,wxEXPAND)
self.SetAutoLayout(true)
self.SetSizer(box)
self.Layout()

Changing wxVERTICAL to wxHORIZONTAL works fine too.
However, if boxes are nested as in:

box=wxBoxSizer(wxVERTICAL)
box2=wxBoxSizer(wxHORIZONTAL)
box2.Add(1,1,1,wxEXPAND)
box2.Add(self.lbl1)
box2.Add(self.fld1)
box2.Add(1,1,1,wxEXPAND)
box.Add(1,1,1,wxEXPAND)
box.Add(box2)
box.Add(1,1,1,wxEXPAND)
self.SetAutoLayout(true)
self.SetSizer(box)
self.Layout()

the vertical layout is as expected, but the spacers in
the nested box (box2) don't expand. Ie. everything's
on the left. I assumed that a Layout() on box and/or
box2 was required but can find no combination that
works.

Thanks in Advance,
John Bell

···

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

You must specify some flags when adding the 'box' sizer to the 'box2'
sizer.

I.e.

box=wxBoxSizer(wxVERTICAL)
box2=wxBoxSizer(wxHORIZONTAL)
box2.Add(1,1,1,wxEXPAND)
box2.Add(self.lbl1,1,wxEXPAND) #add flags to ensure vertical exansion
box2.Add(self.fld1,1,wxEXPAND) # ditto
box2.Add(1,1,1,wxEXPAND)
box.Add(1,1,1,wxEXPAND)
box.Add(box2,1,wxEXPAND) # add flags to ensure horizontal exansion
box.Add(1,1,1,wxEXPAND)
self.SetAutoLayout(true)
self.SetSizer(box)
self.Layout()

hope this works.

Bryan

···

On Tue, 2002-04-09 at 12:30, Bell John wrote:

I'm trying to move from using layout constraints to
the wonderful world of wxSizers. However, I have come
across what is undoubtedly a pretty basic problem that
I can't see my way through.

The problem boils down to the behaviour of spacers in
nested sizers.

If I create a wxStaticText control (lbl1) and a
wxTextCtrl (fld1) I can lay them out vertically with
spacers above and below with:

box=wxBoxSizer(wxVERTICAL)
box.Add(1,1,1,wxEXPAND)
box.Add(self.lbl1)
box.Add(self.fld1)
box.Add(1,1,1,wxEXPAND)
self.SetAutoLayout(true)
self.SetSizer(box)
self.Layout()

Changing wxVERTICAL to wxHORIZONTAL works fine too.
However, if boxes are nested as in:

box=wxBoxSizer(wxVERTICAL)
box2=wxBoxSizer(wxHORIZONTAL)
box2.Add(1,1,1,wxEXPAND)
box2.Add(self.lbl1)
box2.Add(self.fld1)
box2.Add(1,1,1,wxEXPAND)
box.Add(1,1,1,wxEXPAND)
box.Add(box2)
box.Add(1,1,1,wxEXPAND)
self.SetAutoLayout(true)
self.SetSizer(box)
self.Layout()

the vertical layout is as expected, but the spacers in
the nested box (box2) don't expand. Ie. everything's
on the left. I assumed that a Layout() on box and/or
box2 was required but can find no combination that
works.

Thanks in Advance,
John Bell

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge
CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382