4

How do I get Gtk.scrolledwindow to scroll to a selection in Gtk.Treeview.

I am writing a touch screen kiosk app that has up and down button to move a selection in a treeview.

It doesn't it doesn't scroll down the scrolledwindow when the selection goes off the screen.

My idea to get around this is when the down button is pressed for the selection to move down one (as it already does) and then for the scrolledwindow to scroll to the selection on treeview but I'm unable to work out how.

I'm using Gtk3

Can anyone give me any ideas?

Samuel Taylor
  • 1,181
  • 2
  • 14
  • 25

2 Answers2

3

See: http://lazka.github.io/pgi-docs/Gtk-3.0/classes/TreeView.html#Gtk.TreeView.scroll_to_cell

Do not add you treeview to the scrolled window with "add_with_viewport". See http://mailman.daa.com.au/cgi-bin/pipermail/pygtk/2009-January/016440.html

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Auto Scroll")
        self.set_size_request(400, 200)

        self.liststore = Gtk.ListStore(str, str)
        for n in range(40):
            self.liststore.append(["Info", "http://lazka.github.io/pgi-docs/Gtk-3.0/classes/TreeView.html"])
        treeview = Gtk.TreeView(model=self.liststore)
        for n, name in enumerate(["Name", "Link"]):
            renderer_text = Gtk.CellRendererText()
            column_text = Gtk.TreeViewColumn("Text", renderer_text, text=n)
            treeview.append_column(column_text)
        scrolled_window = Gtk.ScrolledWindow()
        self.add(scrolled_window)
        scrolled_window.add(treeview)

    def main(self):
        Gtk.main

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
oxidworks
  • 1,563
  • 1
  • 14
  • 37
1

After you've moved the selection call gtk_tree_view_scroll_to_cell on the selected path.

Phillip Wood
  • 831
  • 4
  • 5