Activating multiple rows in a TreeView

Hi,

When the ‘row-activated’ signal gets fired in a TreeView, either by
pressing
Enter or double-clicking, the selection gets reduced to the currently
focused
row, i.e. any other rows that were previously selected get deselected.

Is there some way to avoid this, so I can get the list of selected rows
in
the row-activated handler? PyGTK supports this directly by passing a
list
of selected rows to the handler, but it looks like in Ruby-GTK this
isn’t
possible for some reason.

Cheers,
Markus


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys – and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

In [email protected]
“[ruby-gnome2-devel-en] Activating multiple rows in a TreeView” on
Fri, 29 Sep 2006 20:02:44 +0200,
Markus K. [email protected] wrote:

Is there some way to avoid this, so I can get the list of selected rows in
the row-activated handler?

What about the following script:

#!/usr/bin/env ruby

require ‘gtk2’

window = Gtk::Window.new

model = Gtk::TreeStore.new(String)

tree_view = Gtk::TreeView.new
tree_view.model = model
tree_view.selection.mode = Gtk::SELECTION_MULTIPLE

prev_selected = []
selected = []
tree_view.selection.signal_connect(“changed”) do |selection|
prev_selected, selected = selected, selection.selected_rows
false
end
tree_view.signal_connect(“row-activated”) do |widget, path, column|
p prev_selected
false
end

cell = Gtk::CellRendererText.new
column = Gtk::TreeViewColumn.new(“column”, cell, “text” => 0)
tree_view.append_column(column)

10.times do |i|
iter = model.append(nil)
iter.set_value(0, i.to_s)
end

window.add(tree_view)
window.show_all

Gtk.main

                       PyGTK supports this directly by passing a list

of selected rows to the handler

Really? Could you show me a example for that?

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys – and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi (sorry for the broken thread, I wasn’t subscribed to the list yet)

PyGTK supports this directly by passing a list of selected rows to the handler
Really? Could you show me a example for that?

You’re script does the trick, though it doesn’t work when
double-clicking, and it
doesn’t restore the selection afterwards. But after rewriting it in
Python I
realized that PyGTK has the same behaviour.

The reason I assumed PyGTK handles this is that I saw it in the code of
the
Python music player Quodlibet, but I just now realized that they use a
custom
TreeView which implements that behaviour (see the MultiDragTreeView in
http://www.sacredchao.net/quodlibet/browser/trunk/quodlibet/qltk/views.py).

So, I guess I’ll try to rebuild that class in ruby.
But thanks for your answer, anyway!

Here’s the python version of your script:

#!/usr/bin/env python

import gtk

window = gtk.Window()

model = gtk.TreeStore(str)

tree_view = gtk.TreeView(model)
tree_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)

prev_selected = []
selected = []
def changed(selection):
global prev_selected, selected
prev_selected = selected
model, selected = selection.get_selected_rows()
tree_view.get_selection().connect(“changed”, changed)
def row_activated(widget, path, column):
global prev_selected
print prev_selected
False
tree_view.connect(“row-activated”, row_activated)

cell = gtk.CellRendererText()
column = gtk.TreeViewColumn(“column”, cell)
column.add_attribute(cell, “text”, 0)
tree_view.append_column(column)

for i in range(0, 10):
model.append(None, row=[str(i)])

window.add(tree_view)
window.show_all()

gtk.main()

Cheers
Markus


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys – and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs