plese suggest good tutorial for sizers.

krishnakant Mane wrote:

can some one suggest a good tutorial to learn sizers in details?

There are a few in the Wiki -- do a title search for "Sizer". In particular, there is:

http://wiki.wxpython.org/index.cgi/UsingSizers

http://wiki.wxpython.org/index.cgi/ChallengeSizers

I am particularly interested to know that how I can put grid sizers
and box sizers to best use and also get control over the actual size
of controls.

for the most part, you don't control the actual size of the controls -- that's the whole point of sizers. However, if you need to, you can fix the size of a given control ( I think SetSizeHints() does it)

some times grids make the controls of same size and I don't want it.

A GridSizer will make all the controls the same size. A FlexGridSizer will make each column and each row the size it needs to be.

at the same time I may like to increase or decrease the sizes of the
gapps between the controls.

When you Add() a control to a Sizer, you can put a space around it on the side that want -- specify the side with flags: wx.TOP, wx.RIGHT, etc -- or wx.ALL for all. Then the size of that space is specified in pixels by the next parameter.

With a GridSizer or FlexGridSizer, you can specify the space between the rows and columns. You can also put in spacers in any location to customize the spacing.

ok but I will like to leave some wide gap between my 4 rows with edit
fields and the line of buttons, will I be able to do that?

yes, you can put a spacer in anywhere -- either at a fixed size, or make it stretchable.

and if the box sizer is vertical, how can I put a custom grid of
lebel-text pares?

Key to this is that sizers can be (and often have to be) nested. In your case, the grid of label-text pairs is one sizer, the buttons are another, and those both get put in the vertical box sizer.

the layout will be not actually 2 colums but 4 columns. a lable-text
pare with very little space between the static text and the textctrl
then some significant gap before the other pare. means column 1,2
with little or no space and then some significant space and then
column 3 and 4.

the way to do that is to add an extra column for a spacer. so in your case, it would look something like (untested):

fgs = wx.FlexGridSizer(nrows=3, ncols=5, hgap=4, vgap=4)

# 1st label-text pair
fgs.Add(label1, 0, wx.ALIGN_RIGHT)
fgs.Add(text1, 1, wx.ALIGN_LEFT)

# a space
fgs.Add((10,1), 0)

# 2nd label-text pair
fgs.Add(label2, 0, wx.ALIGN_RIGHT)
fgs.Add(text2, 1, wx.ALIGN_LEFT)

## now a new row will be started

# 3rd label-text pair
fgs.Add(label3, 0, wx.ALIGN_RIGHT)
fgs.Add(text3, 1, wx.ALIGN_LEFT)

# a space
fgs.Add((10,1), 0)

# 4th label-text pair
fgs.Add(label4, 0, wx.ALIGN_RIGHT)
fgs.Add(text4, 1, wx.ALIGN_LEFT)

etc....

You can see how this might be done programatically in a loop, rather than writing all this redundant code.

By the way, As it is often the case that you want to use a label and a text box as essentially one control, I wrote a little module that helps with that. I've enclosed it.

ok got the point but will I be able to change the sizes of the buttons
once I tell the box to lay them on the screen?

If you need to change the size of a control, you can do so, then call Layout() on the parent sizer -- you generally don't want to do that, though, unless you change what is on or in the control.

can a spacer be altered for different sizes and how?

A spacer can be any (width, height) size, and it can be put in the sizer to be stretchable or not -- its often useful to put a small stretchable space in between two controls to allow the controls to stay aligned to the right and left as the Window grows.

I want to know if my code will become to complex if there are two many
controls and if yes how to avoid it?

It can get pretty complex, but in general, when you have a lot of controls, they are laid out in logical groups -- essentially each group gets a sizer. In addition, if you really have a lot, they are probably grouped in functional groups -- and should be put on a panel in a separate class -- then these custom Panels can be laid out together.

Keep in mind that "easy to learn" and "easy to use" are not the same. I think sizers are easy to use, in the sense that they will make you a more productive programmer, but they are not easy to learn -- they do take a while to wrap your brain around.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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

hi chris

for the most part, you don't control the actual size of the controls --
that's the whole point of sizers. However, if you need to, you can fix
the size of a given control ( I think SetSizeHints() does it)

The point here I am trying to address is that some labels will be
small and some big. for example "name " is a small caption and needs
small lable and "home-phone" is a big lable. so if I use grid then
what's the point in having both the lables of same size?
some times I want to make buttons of different size and I have often
observed in layout oriented gui (in particular java) that the sizes of
the controls are mostly not what we desired. this should not happen
else there is no point using layouts.

> some times grids make the controls of same size and I don't want it.

A GridSizer will make all the controls the same size. A FlexGridSizer
will make each column and each row the size it needs to be.

and what is the logic it uses to decide the size? is it the caption
or some thing else?

> at the same time I may like to increase or decrease the sizes of the
> gapps between the controls.

When you Add() a control to a Sizer, you can put a space around it on
the side that want -- specify the side with flags: wx.TOP, wx.RIGHT, etc
-- or wx.ALL for all. Then the size of that space is specified in pixels
by the next parameter.

so will that in turn actually effect the sizes of the controls? if
yes then I think this is what I want . I can make a control small by
pressing it between two spacers in a box layout.

With a GridSizer or FlexGridSizer, you can specify the space between the
rows and columns. You can also put in spacers in any location to
customize the spacing.

in that case if I can particularly specify where (bwtween which
columns ) I want to put the gap I can do a lot of good gui I suppose.
like for example in your example you suggested to leave a column blank
for the lable-textbox pare. will it not be good to add a gap between
second and third column so that the first 2 columns can have the first
pare and then a gap and the second pare of lable-textbox comes in the
3rd. and 4th. column after the space?
can I also add spacers inside the cells of a grid thus created?
I will appreciate any example.
because if the answers to my above queries are "yes" then I think I
have achieved what I wanted and wont feel it that much complex to code
and maintain the gui program I create.

Key to this is that sizers can be (and often have to be) nested.

well, so I am now left with 2 options in my particular case. I put a
vertical box sizer and put horizontal box sizers with controls as I
wish with spacers around controls or second option is to use a grid
with gapps in between the second and third columns for seperating
pares of lable-textboxes. is that right?

Please guide me for this because I want to keep it as simple as
possible for practical perpuses and I am trying to find out the
easiest way not just to create it one time but to maintain it as well.
thanks.
Krishnakant.

···

On 05/01/07, Christopher Barker <Chris.Barker@noaa.gov> wrote: