[EMAIL PROTECTED] wrote:
[snip]
And the code begins:

top_widget = MyTopWidget()
sub_widget = MySubWidget()
sub_sub_widget = MySubSubWidget()

I'd prefer adding my widgets in the usual PyGTK sytle:

sub_widget.add(sub_sub_widget)
top_widget.add(sub_widget)

Instead of this plain and ugly hack (where the 'widget' member of my classes is the created PyGTK widget):

sub_widget.add(sub_sub_widget.widget)
top_widget.add(sub_widget.widget)


I don't know whether it is possible or not. So please anyone drop me a line. Is it posibble at all from Python?

There is nothing wrong with subclass a gtk widget class in Python. Something like this should work fine:


class MyTopWidget(gtk.VBox):
    def __init__(self):
        gtk.VBox.__init__(self, False, 6)
        self.set_border_width(12)
        self.connect('expose-event', self._on_expose)

    def add(self, widget):
        self.pack_start(widget, fill=True, expand=True)

    def _on_expose(self, widget, event):
        print "I've been exposed!"

Make sure that you are using pygtk-2.0.0. I don't think that subclassing will work at all with 0.6, and some 1.99.x versions had problems with reference counts when you started doing stuff like that 'connect' call above.

--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to