Martin Gadbois <[EMAIL PROTECTED]> writes:
> I want to display a TreeView and have the initial selection to be
> the last saved value.
[ ...code snipped... ]
> 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?
I don't know as I wouldn't call myself experienced :), but this version
seems to work:
---
# rest of the code not changed
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)
ds.vbox.pack_start(tv)# this is changed: in your version this
b = gtk.Button("Action") # part was at the end of the
b.connect("clicked",doit,tv) # dir_dialog() function
ds.action_area.pack_start(b) #
ds.show_all() # end of changes
sel = tv.get_selection()
sel.set_mode(gtk.SELECTION_SINGLE)
# This select_path() does nothing to the display...
sel.select_path( (2,) )
tv.set_cursor( (2,), None, False ) # an extra line added to set cursor, too
s = tv.get_selection().get_selected()
print "Selected:",model.get_value(s[1],0)
ds.run()
---
Moving the 'display the widgets' code before the 'set selection' part
apparently fixes it. This, of course, only sets the selection and
will leave the cursor (a dashed box around the row) at the first
row. The tv.set_cursor line sets this to the selected row, too. (This
might or might not make sense in your case.)
--
Abel Daniel
___
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/