[pygtk] Creating a subclass of gtk.Image

Graham Whelan gawhelan at gmail.com
Tue Feb 10 00:52:04 WST 2009


Hi,

I'm trying to create a custom widget that inherits from gtk.Image but I'm
having problems. When I add more than one of these widgets to a container,
only the first widget is being rendered. My test case looks like this:

import gtk, gobject

class MyImage(gtk.Image):
    def __init__(self):
        gtk.Image.__init__(self)
        self.unset_flags(gtk.NO_WINDOW)

    def do_realize(self):
        self.set_flags(self.flags() | gtk.REALIZED)

        self.window = gtk.gdk.Window(
            self.get_parent_window(),
            x=self.allocation.x,
            y=self.allocation.y,
            width=self.allocation.width,
            height=self.allocation.height,
            window_type=gtk.gdk.WINDOW_CHILD,
            wclass=gtk.gdk.INPUT_OUTPUT,
            visual=self.get_visual(),
            colormap=self.get_colormap(),
            event_mask=self.get_events() | gtk.gdk.EXPOSURE_MASK)

        self.window.set_user_data(self)
        self.style.attach(self.window)
        self.style.set_background(self.window, gtk.STATE_NORMAL)

    def do_unrealize(self):
        self.window.set_user_data(None)

gobject.type_register(MyImage)

if __name__ == '__main__':
    win = gtk.Window()
    win.connect('destroy', gtk.main_quit)

    box = gtk.HBox()

    image = MyImage()
    image.set_from_stock(gtk.STOCK_OK, gtk.ICON_SIZE_DIALOG)
    box.add(image)

    image = MyImage()
    image.set_from_stock(gtk.STOCK_HELP, gtk.ICON_SIZE_DIALOG)
    box.add(image)

    win.add(box)
    win.show_all()
    gtk.main()


With the above code only the first image is rendered.

Any ideas as to what I'm doing wrong?

Thanks,

Graham
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20090209/be3527f7/attachment.htm 


More information about the pygtk mailing list