beginner questions

I've gotten to understanding Tkinter fairly well and now I *trying* to
understand wxWindows and having a terrible time.

Why is a window not a window but a frame?
Why is a frame not a frame but a panel?
Or do I have that wrong?

How do I get a window (or is it a frame) to figure out for itself
what size it ought to be based on its contents?

How can I adjust the internal padding on a button?
How can I make all buttons in a group the same size?

Can a cell in a wxGridSizer span multiple rows or columns?

AddMany() is used in examples but I can't find it in the docs.

I'm running debian/sarge linux so I'm using wxWindows 2.2.

···

--
But the individual has no right to use force for any other end. I
cannot legitimately force my fellow men to be industrious, sober,
thrift, generous, learned, or pious; but I can force them to be
just. -- Frédéric Bastiat (1801-1850)
    Rick Pasotto rick@niof.net http://www.niof.net

Rick Pasotto wrote:

I've gotten to understanding Tkinter fairly well and now I *trying* to
understand wxWindows and having a terrible time.

Why is a window not a window but a frame?
Why is a frame not a frame but a panel?
Or do I have that wrong?

Terminology differs between different toolkits: there isn't either a right or a standard way of describing these things. I'm not familiar with Tk so I can't translate their terminology to wxWindows, but I can give a brief (and somewhat simplified) overview.

In wxWindows:

1. all controls (buttons, text boxes, etc.) and all containers of other controls (frames, dialogs, panels, notebooks) are derived from a common class wxWindow.

2. The top level windows (ones which appear directly on the desktop) are either wxFrames or wxDialogs (the latter are usually temporary)

3. dialogs implement the standard Windows-style tab navigation between the controls they contain. To get this effect in a frame, you need to create a panel with the frame as its parent, and then create controls with the panel as their parent.

How do I get a window (or is it a frame) to figure out for itself
what size it ought to be based on its contents?

The best way to do layout in wxWindows/wxPython is to use sizers. Look up sizers in the wxWindows documentation, and also see http://wiki.wxpython.org/index.cgi/UsingSizers. Start with box sizers - the rest are more special purpose. Also, search the recent archives for this list - I wrote a brief introduction to box sizers recently.

By default, sizers work the other way around: given the size of the container window (usually a frame or dialog or panel), they figure out how to allocate that space to the different controls. This simplifies dealing with text controls and others with variable sizes, where the actual minimum size is not very useful. However, you can make the sizer re-size the window by adding a call to sizer.Fit(window) (see the documentation listed above for details).

How can I adjust the internal padding on a button?

By internal padding, you mean the space inside the button around the text of the button? I'm not sure if there is a way to do this directly, other than specifying a size for the button manually. If you do so, and then add the button to a box sizer, make sure to use 0 for the proportion, so that it will use your manually specified size.

How can I make all buttons in a group the same size?

Either specify their size manually, or put them in the same box sizer with the same (non-zero) value of the proportion argument.

Can a cell in a wxGridSizer span multiple rows or columns?

AddMany() is used in examples but I can't find it in the docs.

I haven't used either, so someone else will have to answer.

David

Rick Pasotto wrote:

I've gotten to understanding Tkinter fairly well and now I *trying* to
understand wxWindows and having a terrible time.

wxWindows and TK use different vocabulary, and different layout
mechanisms, so the transition takes some brain re-wiring.

Why is a window not a window but a frame?
Why is a frame not a frame but a panel?
Or do I have that wrong?

I've kind of forgotten my TK definitions, and the answer to "why" is
jsut arbitrary choice of vocabulary, but here are some quick wxPython
definitions:

A wxWindow is the base class for all controls, etc. It is a rectangular
thing that can be drawn on the screen, and subclasses to create
virtually all the GUI elements you need (most of that subclassing has
been done for you)

a wxFrame is is a "top level" window: it is managed by the system, in
the sense that the system ddrawas a border around it, and provides a way
to move, re-size it, etc. It is what most computer users, rather than
progarmmers, would call a "Window".

A wxPanel is a type of wxWindow that is used to place other windows,
(controls, etc) on. It adds a little bit of functionality to the baseic
wxWindows, including tabbing between controls, etc. It is usually used
to group a set of widgets that all work together as a unit in some way.
You will often find yourself placing your widgets on a panel, and then
the panel in some kind of container, like a wxNotebook, or wxSashWindow,
etc.

How do I get a window (or is it a frame) to figure out for itself
what size it ought to be based on its contents?

It could be either a window or a frame, though most likely it will be a
class you define, that is subclassed from a wxFrame (for a top level
window) or a wxPanel(for a piece of what be on a frame)

wxWhatever.Fit()

How can I adjust the internal padding on a button?

I'm not sure what "internal" padding is, but to put space around a
button, you use the spacer flags and sizes when you add the button to a
sizer. For example:

MySizer.Add(myButton,0,wxALL|OtherFlags, 4)

wxALL is a flag that indicates that you want space on all sides, and the
4 is the number of pixels to make that space.

How can I make all buttons in a group the same size?

This depends on whether you want them a fixed size, or all the same size
to fit something else. Fixed size is easy. For all the same size, put
them in a wxBoxSizer, either horizontal or vertical, and give them all
the saem flagg wxEXPAND if you want them to expand to fit the dimension
perpindicular to the main one, and give them all the option value,
usually 1, so they will all stretch the same amount. Example:

ButtonSizer = wxBoxSizer(wxVERTICAL)
for (button) in ButtonList:
            ID = wxNewId()
            ButtonSizer.Add(button,0,wxEXPAND|wxALL,2)

This will put all the buttons in ButtonsList in a vertical row, making
them all the same size, with a border of two pixels around them.
(example cut and pasted from a small app of mine)

Can a cell in a wxGridSizer span multiple rows or columns?

No, but take a look at wxFlexGridSizer(). It doesn't appear to be in my
copy of the demo, but it is in the wxWindows reference docs.

Make sure you read the wxSizer overview in teh docs, ans well as the
sizer stuff in the Wiki.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Rick Pasotto wrote:

AddMany() is used in examples but I can't find it in the docs.

Here's the source: (use the source, Luke!)

    def AddMany(self, widgets):
        for childinfo in widgets:
            if type(childinfo) != type(()):
                childinfo = (childinfo, )
            apply(self.Add, childinfo)

It looks like a simple way to add a bunch of widgets in a list to a
sizer at once. Between that and an example or two, you should be able to
figure it out.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

David C. Fox wrote:

Can a cell in a wxGridSizer span multiple rows or columns?

I haven't used either, so someone else will have to answer.

No wxGridSizer or wxFlexGridSizer can't span, but there is the RowColSizer class in the wxPython.lib that was added in the 2.3 series sometime that does allow for it. It's pure Python so I expect that it will work with 2.2.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!