Buttons and Sizers

Hi Seb. I have just a couple of small, general pieces of advice.

-) Exactly as Robin pointed out, sizers are "things" like any

visible control, except that they can’t be seen. They are placement
algorithms and no one can see algorithms, just their effects. So,
when designing your general layout “make them visible” by sketching
what you want everything to look like before you start coding. It
will become obvious how you want the visible items laid out and
grouped. Each group will require at least one sizer. Now, sketch a
tight fitting box around each group to represent the individual
sizers. It will be pretty obvious if they need to be horizontal,
vertical or a compound grouping of sizers. If a group needs its
controls to be laid out in a 2-dimensional manner, then either you
need to subdivide that group into more individual sizers or,
perhaps, substitute a sizer that can hold multiple controls such as
a wx.GridBagSizer. “Divide and Conquer”. Once it makes sense on
paper you can start coding.

-) This suggestion goes way back to "Programming 101", but, for

Pete’s sake, use descriptive variable names ! Names like “vbox” and
“panel1” are lazy and downright hazardous. Trying to remember what
each generic name is for works only for geniuses and trivial
examples. Give yourself and everyone else that reads your code a
break.

For example, what would be a better name for "vbox" ? Well, what

does it do ? It’s a vertical sizer that arranges every control in
the frame. A better name for it could be “frameVertBox_sizer”. What
about “panel3” ? How about “buttonsHorzBox_sizer” ? You went out of
your way to name the two wx.ListBox_es more descriptively, so just
keep going on doing that ! Make your chosen names as descriptive as
reasonable. How are the two wx.ListBox_es different ? Well, put it
in their names. Abbreviations are often needed to avoid creating
names that are as long as some German nouns! The slippery phrase "
as descriptive as reasonable" will become easier to define with
practice.

I sketched out how the revised code defines its sizers in the

attached PNG file.

Note how the revised code is nearly self-documenting in regards to

the sizers.

Ray Pasco

PROPERTIES_EDITED.ANNOTATED.PNG

PROPERTIES_EDITED.PY (3.04 KB)

Well, if panel3 is a wx.Panel (and I’m not sure what it is), then calling it a sizer is confusing. I’d probably call it buttonPanel or something along those lines…this is called “self documenting code”. Now Seb knows one of our buzz phrases!

···

On Thu, Jul 15, 2010 at 12:47 PM, Ray Pasco pascor@verizon.net wrote:

Hi Seb. I have just a couple of small, general pieces of advice.

-) Exactly as Robin pointed out, sizers are "things" like any

visible control, except that they can’t be seen. They are placement
algorithms and no one can see algorithms, just their effects. So,
when designing your general layout “make them visible” by sketching
what you want everything to look like before you start coding. It
will become obvious how you want the visible items laid out and
grouped. Each group will require at least one sizer. Now, sketch a
tight fitting box around each group to represent the individual
sizers. It will be pretty obvious if they need to be horizontal,
vertical or a compound grouping of sizers. If a group needs its
controls to be laid out in a 2-dimensional manner, then either you
need to subdivide that group into more individual sizers or,
perhaps, substitute a sizer that can hold multiple controls such as
a wx.GridBagSizer. “Divide and Conquer”. Once it makes sense on
paper you can start coding.

-) This suggestion goes way back to "Programming 101", but, for

Pete’s sake, use descriptive variable names ! Names like “vbox” and
“panel1” are lazy and downright hazardous. Trying to remember what
each generic name is for works only for geniuses and trivial
examples. Give yourself and everyone else that reads your code a
break.

For example, what would be a better name for "vbox" ? Well, what

does it do ? It’s a vertical sizer that arranges every control in
the frame. A better name for it could be “frameVertBox_sizer”. What
about “panel3” ? How about “buttonsHorzBox_sizer” ? You went out of
your way to name the two wx.ListBox_es more descriptively, so just
keep going on doing that ! Make your chosen names as descriptive as
reasonable. How are the two wx.ListBox_es different ? Well, put it
in their names. Abbreviations are often needed to avoid creating
names that are as long as some German nouns! The slippery phrase "
as descriptive as reasonable" will become easier to define with
practice.

I sketched out how the revised code defines its sizers in the

attached PNG file.

Note how the revised code is nearly self-documenting in regards to

the sizers.

Ray Pasco

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mike Driscoll

Blog: http://blog.pythonlibrary.org