[pygtk] how to get selected rows at the time user selects a row ('cursor-changed' does not do it)

Nikos Kouremenos kourem at gmail.com
Tue Feb 7 04:04:51 WST 2006


On 2/5/06, David M. Cook <dave at davidcook.org> wrote:
> On Sun, Feb 05, 2006 at 03:48:17PM +0200, Nikos Kouremenos wrote:
>
> > so which signal to connect to so when user has a row selected and goes
> > to select another one (with SHIFT) when he presses the row I can get
> > both 2? (cursor-changed returns 1)
>
> Use the selection objects "changed" signal.  The GTK reference gives the
> caveat
the PyGTK one?

>   One of the important things to remember when monitoring the selection of a
>   view is that the "changed" signal is mostly a hint. That is, it may only
>   emit one signal when a range of rows is selected. Additionally, it may on
>   occasion emit a "changed" signal when nothing has happened (mostly as a
>   result of programmers calling the select_path() or select_iter() methods
>   on an already selected row).
>
> So you have to check for the actual selected rows in your callback.
>
> def on_selection_changed(selection):
>     model, selectedRows = selection.get_selected_rows()
>     # do something with rows
>     ...
> ...
> treeview.get_selection().connect("changed", on_selection_changed)
>
> Dave Cook

thanks Dave. your recipe (hehe Cook :-*) works. /me wonders if PyGTK
REF says it, else needs to be added in a FAQ

--
Nikos Kouremenos


More information about the pygtk mailing list