GtkTreeview signal "row-activated"

P

Patrick Plattes

Hello,

I have a problem with the TreeView of RubyGTK. Catching the signal works
very well, but I don't know which row of the list was activated :-(.
Does anyone know how to figure out which line was activated?

I've written a litte script to show what I mean. At the moment I do a
'puts "output"', but how could I print the first column of the selected
row? (or anything else)

If these kind of questions are too Gtk specific, please tell me and I
won't bother you with them.

Thanks,
Patrick




#!/usr/bin/env ruby

require 'gtk2'


def create_list(headline, liststore)
treeview = Gtk::TreeView.new(liststore)
renderer = Gtk::CellRendererText.new
view = Gtk::ScrolledWindow.new.add(treeview)

headline.each_index do |index|
column = Gtk::TreeViewColumn.new(headline[index],
renderer, :text => index)
column.resizable = true
column.clickable = true
column.sort_column_id = index
treeview.append_column(column)
end

return view, treeview, liststore
end



Gtk::init

window = Gtk::Window.new
window.title = "Tattletale"
window.border_width = 10
window.set_size_request(600, 400)
window.add(box = Gtk::VBox.new(false, 0))

view, treeview, liststore = create_list(["Foo", "Bar"],
Gtk::ListStore.new(String, String))
box.pack_start(view)
view.show_all

row = liststore.append
row[0] = "Hello World"
row[1] = "I agree with Hello World"

row = liststore.append
row[0] = "Welcome to Brazil"
row[1] = "Welcome to Denmark"

treeview.signal_connect("row-activated") do |treeview, path, column|
puts "output"
end


window.show_all
Gtk::main
 
O

Olivier

Le vendredi 22 d=E9cembre 2006 15:29, Patrick Plattes a =E9crit=A0:
Hello,

I have a problem with the TreeView of RubyGTK. Catching the signal works
very well, but I don't know which row of the list was activated :-(.
Does anyone know how to figure out which line was activated?

I've written a litte script to show what I mean. At the moment I do a
'puts "output"', but how could I print the first column of the selected
row? (or anything else)

If these kind of questions are too Gtk specific, please tell me and I
won't bother you with them.

Thanks,
Patrick




#!/usr/bin/env ruby

require 'gtk2'


def create_list(headline, liststore)
treeview =3D Gtk::TreeView.new(liststore)
renderer =3D Gtk::CellRendererText.new
view =3D Gtk::ScrolledWindow.new.add(treeview)

headline.each_index do |index|
column =3D Gtk::TreeViewColumn.new(headline[index],
renderer, :text =3D> index)
column.resizable =3D true
column.clickable =3D true
column.sort_column_id =3D index
treeview.append_column(column)
end

return view, treeview, liststore
end



Gtk::init

window =3D Gtk::Window.new
window.title =3D "Tattletale"
window.border_width =3D 10
window.set_size_request(600, 400)
window.add(box =3D Gtk::VBox.new(false, 0))

view, treeview, liststore =3D create_list(["Foo", "Bar"],
Gtk::ListStore.new(String, String))
box.pack_start(view)
view.show_all

row =3D liststore.append
row[0] =3D "Hello World"
row[1] =3D "I agree with Hello World"

row =3D liststore.append
row[0] =3D "Welcome to Brazil"
row[1] =3D "Welcome to Denmark"

treeview.signal_connect("row-activated") do |treeview, path, column|
puts "output"
end


window.show_all
Gtk::main

You can do all this with the block arguments given :
=2D "path" tells you which is the activated row
=2D "treeview" can be asked for the currently selected Iter=20
(#selection#selected), then you can do whatever you want with it :)

treeview.signal_connect("row-activated") do |treeview, path, column|
puts path
i =3D treeview.selection.selected
puts "#{i[0]} =3D> #{i[1]}"
end

=2D-
Olivier
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top