Equivalent to "weight" parameter in pyGTK?
When building a GUI in pyGTK, I often want multiple child objects to expand at a given ratio. As an example (not my application, just what I felt was easy to draw), imagine that I am creating some sort of photo viewer that displays EXIF ββmetadata in a tab on the right, and I would like them to support 2 : 1, so the photo is always 2 / 3rds wide and the metadata is 1/3 wide:
In wxWindows, you have to assign a "weight" to each of these elements, so the left VBox
will have weight = 2
and the right VBox
will weight = 1
, then when the window is resized, the containers will maintain a 2: 1 ratio. On GTK +, however, it seems that all you what you can do is choose whether you want the containers to expand or not, so in this case I would use something like:
top_level_hbox.pack_start(exif_container, expand=False)
top_level_hbox.pack_start(photo_container, expand=True, fill=True)
However, I believe this would leave exif_container
at a fixed size based on the size of its child widgets, and
photo_container
would grow as needed, so even if they originally had a 2: 1 ratio it would not survive window resizing. Is there a simple, or at least standard way of doing this kind of "weighted extension" in GTK?
source to share
You can do this with a table layout. I.e. instead of using hbox, create a gtk.Table with one row and three columns. Attach a portion of the photo to cover the first two columns and the status bar for the third, which should maintain the 2: 1 ratio you want as they expand.
Eg.
table = gtk.Table(rows=1, columns=3)
table.attach(photo_container, 0, 2, 0, 1) # Span column 0..2
table.attach(exif_container, 2, 3, 0, 1) # Span final column
window.add(table)
source to share
I agree with Brian's suggestion to use gtk.Table. To force table cells to all be the same size, you can specify homogeneous=True
in the constructor.
Another approach is to package the phot_container and exif_container into a gtk.VPaned container, which allows the user to manage the space used by the two child containers, and you can also manage it dynamically with a method set_position()
, although that might figure out a bit.
Personally, I would tend to use a simple fixed size gtk.HBox exif_container for this interface, although I would probably put photo_container in gtk.ScrolledWindow.
source to share