pygtk sizing… staring me in the face

Friday, 30 December, 2005

The problem:

I want to create a window with effectively 2 panels, separated by a horizontal line. Panel 1 takes up (approximately) 90% of the height. Panel 2 takes up the remaining 10%. Let’s just ignore the height of the line for the moment.

For example, something like:


    |-------------------------|
    |                         |
    |                         |
    |                         |
    |-------------------------|
    |                         |
    |-------------------------|


However with my bounding gtk.VBox, I was ending up with 3 boxes of equal height, containing panel 1, the horizontal line and panel 2.

What I somehow kept missing in the documentation were the expand and fill parameters. For example:


vbox.pack_start(panel1)
vbox.pack_start(hline, expand=False, fill=False)
vbox.pack_start(panel2, expand=False, fill=False)
vbox.set_size_request(-1, 30)

The first pack_start call uses the default expand and fill (True). If you don’t set expand and fill to false on the calls for hline and panel2, then you end up with my initial problem (3 boxes of equal height).

Note that for the parameters to set_size_request, -1 is a request to automatically size the width to the bounding container, and 30 is the pixel height.

Of course, now I’ve decided I don’t need this layout anyway…

Leave a Reply