[pygtk] Writting a widget with native scrolling support

Laszlo Nagy gandalf at shopzeus.com
Tue Oct 21 03:20:19 WST 2008


I want to write an owner-drawn widget (using Cairo) with native 
scrolling capabilities. Let's say this widget has a get_hadjustment() 
and a get_vadjustment() method. Scrolling inside the widget is already 
implemented. E.g. the widget draws different things on its surface, 
depending on the values of its adjustments.

I would like to add this widget to a ScrolledWindow. Here is what I do:

        # Create an owner drawn widget with native scrolling capabilites.
        w = MyTable()
       
        # Create a ScrolledWindow
        # This will share the adjustments between the scrollbars
        # and the w widget.
        sw = gtk.ScrolledWindow(
            hadjustment=w.get_hadjusment(),
            vadjustment=w.get_vadjusment()
        )
        # Add scrollable child widget to scrolled window.
        sw.add(w)


When starting my program, I get this message:

main.py:44: GtkWarning: gtk_scrolled_window_add(): cannot add non 
scrollable widget use gtk_scrolled_window_add_with_viewport() instead
  sw.add(w)

I wonder why it thinks that this is a non-scrollable widget? Should I 
define some special slots for gtk to think this widget is scrollable? 
I'm sorry but I could not find documentation about this.  Of course you 
do not need to explain everything, just please point me to the right 
place in the pygtk docs, or just give some hints how to do it.

Thank you,

   Laszlo



More information about the pygtk mailing list