[pygtk] Re: On displaying a TreeView and selecting the right element...

2004-03-12 Thread Martin Gadbois
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Abel Daniel wrote:
|
| 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.)
|
Indeed! Thanks a lot!
I knew I would get experimented user on this list :-)
- --
"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
iD8DBQFAUilI9Y3/iTTCEDkRAod7AKCVNgTpH7JgYTfGq7ZgYeloz1DC/ACgyLUZ
owxWkvqKWk3Sw0VFR7UqFM8=
=9/PA
-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/


[pygtk] Re: On displaying a TreeView and selecting the right element...

2004-03-12 Thread Abel Daniel
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/