[pygtk] treeview.scroll_to_cell() has no effect

Karl Ostmo kostmo at purdue.edu
Sun Sep 14 02:37:36 WST 2008


Does anyone know what is wrong with my usage of scroll_to_cell( ) ?  When I
run the program below, after I click on a row and scroll such that it is out
of view, I would expect that when I click on the "Scroll to highlighted row"
button that the row would be brought back into view.

Thanks,
Karl

#!/usr/bin/python

from pygtk import require
require('2.0')
import gtk, gobject

class TreeviewTest(gtk.Window):
    def __init__(self):
        gtk.Window.__init__( self, gtk.WINDOW_TOPLEVEL )
        self.connect("destroy", self.destroy)

        vbox = gtk.VBox(False, 5)
        self.add( vbox )

        button = gtk.Button("Scroll to highlighted row")
        button.connect("clicked", self.cb_scroll)
        vbox.pack_start(button, False, False)

        self.tv = gtk.TreeView( gtk.TreeStore(gobject.TYPE_STRING,
gobject.TYPE_STRING) )

        for i, colname in enumerate(["Index", "Name"]):
            self.tv.append_column( gtk.TreeViewColumn(colname,
gtk.CellRendererText(), text=i) )

        for i in range(20):
            self.tv.get_model().append(None, row=(str(i), "Foo"))

        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.add_with_viewport(self.tv)
        vbox.pack_start(scrolled_window, True, True)

        self.show_all()

    def cb_scroll(self, widget):
        selection = self.tv.get_selection()
        tm, tree_iter = selection.get_selected()
        path = tm.get_path(tree_iter)
        print path
        self.tv.scroll_to_cell(path)
#        gobject.idle_add(self.tv.scroll_to_cell, path)    # This doesn't
work either

    def destroy(self, widget, data=None):
        gtk.main_quit()

if __name__ == "__main__":
    application = TreeviewTest()
    gtk.main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080913/1f2628e1/attachment.htm 


More information about the pygtk mailing list