One way to think of how to code sizers is to go from inner to outer,
from control widgets groups (inner) to the frame (outer).
Meaning:
# --------------
First step make windows and widgets
make frame
make panel 1
make controls for group 1.1
make controls for group 1.2
make panel 2
make controls for group 2.1
make controls for group 2.2
# --------------
now make sizers for controls and widgets first
and add the controls to them
make widget group 1.1 sizer
add group 1.1 widgets to group sizer 1.1
sizer1_1.Add(control1, ...)
sizer1_1.Add(control2, ...)
sizer1_1.Add(control3, ...) etc.
make widget group 1.2 sizer
add group 1.2 widgets to group sizer 1.2
sizer1_2.Add(control1, ...)
sizer1_2.Add(control2, ...)
sizer1_2.Add(control3, ...) etc.
make widget group 2.1 sizer
add group 2.1 widgets to group sizer 2.1
sizer2_1.Add(control1, ...)
sizer2_1.Add(control2, ...)
sizer2_1.Add(control3, ...) etc.
make widget group 2.2 sizer
add group 2.2 widgets to group sizer 2.2
sizer2_2.Add(control1, ...)
sizer2_2.Add(control2, ...)
sizer2_2.Add(control3, ...) etc.
# -----------------
Next make sizers for the panels and add the widget_group_sizers to the
panel sizers
make panel one sizer
add widget-group-1.1 sizer to panel_1 sizer
panel1sizer.Add(sizer1_1, ...)
add widget-group-1.2 sizer to panel_1 sizer
panel1sizer.Add(sizer1_2, ...)
make panel 2 sizer
add widget-group-2.1 sizer to panel_2 sizer
panel2sizer.Add(sizer1_1, ...)
add widget-group-2.2 sizer to panel_2 sizer
panel2sizer.Add(sizer1_2, ...)
# _____________
Next -assign- (not add) the panel sizers to the panels
(note you do not normally assign sizers to controls - I believe, only
for panels and frames or container windows get this.)
panel1.SetSizer(sizerpanel1)
panel2.SetSizer(sizerpanel2)
# _____________
Next optionally make a sizer for the frame and assign the sizer to the
frame.
frame.SetSizer(framesizer)
If you make just one child panel of the frame the child panel will
fill the frame
If you make just one child control (and no panel) of the frame the
control will fill the frame.
(for example if you add one single multi-line textctrl as the only
child to the frame)
Some OS's have weird visuals if at least one panel is not childed a
frame.
Some things to avoid:
1. Controls get "added" to a sizer. Sizers usually shouldn't
get assigned to a widget. I have not seen:
wx.TextCtrl.SetSizer(wx.BoxSizer(wx.HORIZONTAL) )
2. The sizers that have controls or subpanels added to
them may be added to a panel sizer or frame sizer.
Then you -assign- the panel/frame sizer to the panel or frame
like this: panel.SetSizer(mypanel_sizer)
3. The mypanel_sizer should usually only have children added
to it which belong to the wx object the mypanel_sizer will
be assigned to.
Things can get weird and broken when you mix up the
parent/child object relationship and the sizer containment
heiarchy. So -add- child objects to a sizer, then -assign- that
sizer to the parent of the child widgets'.
For example:
mainframe() has
panelA() has
controlA1
controlA2
panelB() has
controlB1
controlB2
I believe things can break when you do something like this:
framesizer = wxboxsizer(wxhorizontal)
framesizer.add(panelA)
framesizer.add(panelB)
framesizer.add(controlA1)
framesizer.add(controlA2)
framesizer.add(controlB1)
framesizer.add(controlB2)
Here controlA1 and controlA2 are children of panelA,
but we missmatch the sizer setup by assigning
controlA1 and controlA2 locations to be controlled
by the frame sizer and not controlA1/2's parent
panelA. This may conflict with panelA
layout algorithms for it's children - but not always.
Note there is a missmatch between the
parent/child wx object relationship and the
sizer hiearchy.
A better way to do it:
panelAsizer = wxboxsizer(wxhorizontal)
panelAsizer.Add(controlA1)
panelAsizer.Add(controlA2)
panelA.SetSizer(panelAsizer)
panelBsizer = wxboxsizer(wxhorizontal)
panelBsizer.Add(controlB1)
panelBsizer.Add(controlB2)
panelB.SetSizer(panelBsizer)
framesizer = wxboxsizer(wxhorizontal)
framesizer.add(panelA)
framesizer.add(panelB)
frame.SetSizer(framesizer)
Thus we keep child wx objects controlled by the sizer of its parent wx
object.
Did I get it right?
DevPlayer
We must use Python to build another super mega computer to figure out
the question to the answer 42.