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

David M. Cook dave at davidcook.org
Sun Feb 5 22:18:36 WST 2006


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

  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


More information about the pygtk mailing list