-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I want to display a TreeView and have the initial selection to be the last saved value.
I have the following code (simplified):

#!/usr/bin/python
import pygtk
import gtk
import gobject

def doit(widget,tv):
        print widget,tv
        sel = tv.get_selection()
        sel.set_mode(gtk.SELECTION_SINGLE)
# This works...
        sel.select_path( (2,) ) 

item=[ "Ab", "Cd", "eF", "gh", "Ij" ]
def dir_dialog():
        ds = gtk.Dialog("Select directory")
        model = gtk.TreeStore(gobject.TYPE_STRING)
        for cnt in range(5):
                root = model.insert(None,cnt,[ item[cnt]  ])
                model.insert(root,0,[ "." ])

tv = gtk.TreeView(model)

        col= gtk.TreeViewColumn("",gtk.CellRendererText(),text=0)
        tv.append_column(col)
        tv.set_headers_visible(gtk.FALSE)

        sel = tv.get_selection()
        sel.set_mode(gtk.SELECTION_SINGLE)
# This select_path() does nothing to the display...
        sel.select_path( (2,) ) 

        s = tv.get_selection().get_selected()
        print "Selected:",model.get_value(s[1],0)

        ds.vbox.pack_start(tv)
        b = gtk.Button("Action")
        b.connect("clicked",doit,tv)
        ds.action_area.pack_start(b)
        ds.show_all()
        ds.run()


def main(): dir_dialog() gtk.main()

if __name__ == "__main__":
~    main()

How to select the right initial value in a gtk.TreeView when displaying it?

I would like to show the initial selection when I display the TreeView but it works 
only when I
press the "Action" button.

Is that a bug or a feature?

Notice the "Selected:" printed on the screen: it contains the right value.

How do an experimented Gtk coder would do that?

Thanks,

- --
"Windows might take you from 0 to 60 faster, but to go to 100 you need Unix."
==============
Martin Gadbois
S/W Developper
Colubris Networks Inc.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFAUgfz9Y3/iTTCEDkRArNhAKDGfZSnRX/u4KaQ6Vaya0rloYx4IgCfdMxZ
pY+4BChX22ewrV9agGAys2Q=
=AjYB
-----END PGP SIGNATURE-----
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to