pobrien@orbtech.com wrote:
I'd like to propose a change to the current API for sizers. Since the
current API isn't documented in the wxWindows reference, this change
shouldn't be too dramatic. I'll outline the existing API followed by
my proposed change.
[...]
Issues
None of the wxPython variants are documented in the wxWindows manual,
so no changes are needed there.This change only effects code that uses the wxPython variants, and I
wasn't able to find any examples that did. For instance, the examples
on the wiki use Add(...), not AddWindow(...) or AddSizer(...).Boa doesn't use sizers, so this change won't effect Boa.
I don't know what the other designers do with sizers. Anyone?
What do the rest of you think about this proposal?
What issues have I missed?
1) wxDesigner uses the explicit names AddWindow/Spacer/Sizer.
(I see I wasn't fast enough with this message; Robin's already
noted this in the list!)
Therefore there is presumably a lot of code out there using
them that you wouldn't want to break. I recommend contacting
its author, Robert Roebling (Robert.Roebling@t-online.de)
about these changes. (And talk to him about true/false vs.
True/False whilst you're at it.
2) I personally just discovered that "Add()" was "overloaded"
when I modified a demo in the suite. Because I have been
using wxDesigner for the bulk of my layout work, and because
I knew that Add was overloaded in C++, and that generally
wxPython had equivalents to handle the overloading, it never
occurred to me that Robin might have tweaked Add() to do
runtime type checking to "do the right thing."
That having been said, I find the AddWindow/Spacer/Sizer
rather helpful from a readability standpoint, particularly when
the rest of the arguments are used positionally vs. being
specified with keywords. (I guess I find overloading
to be obfuscating rather than elegant.) Given the polymorphism
of Python, these kind of names make it much easier (imho)
to understand how you are laying things out, and also easier
to detect when you've accidentally made a mistake.
3) Conceptually, the names of the methods used to add stuff to
them don't confuse me. However, I find:
a) how the values of the arguments (eg "proportion=0|1|2|...",
wxEXPAND, wxGROW, wxALIGN_CENTER_VERTICAL, etc.) affect the
resulting layout,
b) how the whole window Layout/SetAutoLayout/Fit/FitInside
stuff works and relates to sizers,
c) how nested panels/sizers interact
are the tricky things about sizers.
For example, I find it odd that you can add stuff to a sizer,
and then ask for sizer.GetSize(), and get (0,0), but call
sizer.GetMinSize() and you get the size that its layout will
eventually have once it's rendered... Do sizers have a size
or not, and if so, when?
When should you call sizer.Fit(window) to tell the specified
window to "size itself around the sizer?" Do you/why do you
need to, particularly if you've just called window.SetSizer(sizer)?
(etc.)
IMO, anything that can be done to make these aspect of sizers
clearer/cleaner would be an improvement.
4) Donnal Walter suggested:
> But the second source of confusion is that if one uses nested
> windows (panels) and nested sizers to any degree, one ends up
> with two entirely different containment hierarchies. The way
> I have handled this is to build sizers into my panels, so that
> adding a component to the panel automatically adds it to the
> sizer. No muss, no fuss.
I often use nested sizers on a single panel to lay things out.
(I got into this habit using wxDesigner, which forces you to
do things this way.) In this scenario, having a single
sizer for the panel is not sufficient. You could, I suppose,
define set of nested subpanels within the main one, but I submit
this isn't what I'd want, as I think of all of the actual
controls visible from the main panel as being parented to that
panel, regardless of the layout. Sizers just enforce a
layout *on* that panel. (IMO, I think it is precisely this
"dual containment" hierarchy that makes sizers so powerful, if
somewhat hard to understand (see (3).)
(My $0.04,)
/Will Sadkin
Parlance Corporation