[pygtk] Multi-paned window

Tony Nelson tonynelson at georgeanelson.com
Wed Jan 25 03:00:41 WST 2006


At 4:58 PM +0100 1/24/06, Luigi Paioro wrote:
>Hi to all!
>
>I'm new to PyGTK programming (I used Tk widgets) and I'd like to know
>whether it exists a way to have a multi-paned window widget. I explain
>better:
>
>I can use a gtk.HPaned() or gtk.VPaned() widget to pane 2 widgets, for
>example:
>
>import pygtk
>pygtk.require('2.0')
>import gtk, gobject
>
>window = gtk.Window(gtk.WINDOW_TOPLEVEL)
>vpaned = gtk.VPaned()
>window.add(vpaned)
>vpaned.show()
>w1 = gtk.TextView()
>w2 = gtk.TextView()
>vpaned.add1(w1)
>w1.show()
>vpaned.add2(w2)
>w2.show()
>window.show()
>gtk.main()
>
>But if I have more than 2 widgets I cannot pane them into the same
>window but I have to do something like this:
>
>import pygtk
>pygtk.require('2.0')
>import gtk, gobject
>
>window = gtk.Window(gtk.WINDOW_TOPLEVEL)
>vpaned1 = gtk.VPaned()
>vpaned2 = gtk.VPaned()
>window.add(vpaned1)
>vpaned1.show()
>w1 = gtk.TextView()
>w2 = gtk.TextView()
>w3 = gtk.TextView()
>vpaned1.add1(w1)
>w1.show()
>vpaned1.add2(vpaned2)
>vpaned2.show()
>vpaned2.add1(w2)
>w2.show()
>vpaned2.add2(w3)
>w3.show()
>window.show()
>gtk.main()
>
>
>But this is not what I want, 'cause in this way, if I resize w1 using
>the paned1 separator, then w3 is resized too, but I'd like that w2 is
>resized, letting w3 untouched (in my design, adjacent widgets would be
>resized). Furthermore, for a lot of widgets to pack, the code becomes
>very confused.
>
>
>Does anybody know a way to make a multi-paned window as I described?

Well, if you don't need to let your users resize the panes individually,
then a normal HBox or VBox should do the trick.  If you need resizing, then
it will be more involved, but I think it can be done by adding more widgets
in between.

#! /usr/bin/env python2.3
# -*- coding: utf-8 -*-
'''multiple "panes"
'''

import gtk

class TestWind(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)
        self.connect('destroy', self.on_destroy)
        self.set_default_size(400, 400)

        vbox = gtk.VBox(True, 4)
        self.add(vbox)
        vbox.show()
        for i in range(3):
            hbox = gtk.HBox(True, 4)
            vbox.add(hbox)
            hbox.show()
            for j in range(3):
                tv = gtk.TextView()
                hbox.add(tv)
                tv.show()

        self.show()

    def on_destroy(self, wid):
        gtk.main_quit()

TestWind()
gtk.main()
____________________________________________________________________
TonyN.:'                       <mailto:tonynelson at georgeanelson.com>
      '                              <http://www.georgeanelson.com/>


More information about the pygtk mailing list