Re: [pygtk] Making my own widget in Pygthon - Some more info
On Thu, Sep 25, 2003 at 04:28:45PM +1200, Tim Evans wrote: > 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 Note that subclassing *does* work fine in 0.6 -- Kiwi uses it all over the place :-) Take care, -- Christian Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331 ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Making my own widget in Pygthon - Some more info
Hi, You have to derive your widget class from a GTK widget. That way, your widget inherits all necessary methods. If you want to look at some code to see how this is done, you could look at the projects gDeskCal and gDesklets, both on www.pycage.de. :) Basically, it works like this: class MyWidget(gtk.Foo): def __init__(self): # invoke the super constructor gtk.Foo.__init__(self) ... Bye, Martin Grimme > My detailed problem: > I want to write an application that uses many complex dialogs. These dialogs are > recursively built up (in an XMLized way) of many smaller (but still complex) > widgets. I want to build my own widgets, so I could create a nice tree of my > high level widgets. > 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? ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] Making my own widget in Pygthon - Some more info
[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/
[pygtk] Making my own widget in Pygthon - Some more info
Hi, I bring up this subject the second time (unfortunately in another thread - sorry about this), since I haven't recieved any feedback from you. Maybe nobody likes me and I'm just a pain in everyone's ass, but maybe not. So I keep trying :) My detailed problem: I want to write an application that uses many complex dialogs. These dialogs are recursively built up (in an XMLized way) of many smaller (but still complex) widgets. I want to build my own widgets, so I could create a nice tree of my high level widgets. 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? Thanks, Laci - This mail sent through IMP: http://horde.org/imp/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/