Forum: Ruby GtkTreeview signal "row-activated"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
052e5f25951098c61efd32e1da4863d5?d=identicon&s=25 Patrick Plattes (Guest)
on 2006-12-22 15:31
(Received via mailing list)
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
85ae830f08b5ff5e39a1cbae9e3d0205?d=identicon&s=25 Olivier (Guest)
on 2006-12-22 17:21
(Received via mailing list)
Le vendredi 22 décembre 2006 15:29, Patrick Plattes a écrit :
> If these kind of questions are too Gtk specific, please tell me and I
> require 'gtk2'
>                  column.resizable = true
> Gtk::init
> view.show_all
>          puts "output"
> end
>
>
> window.show_all
> Gtk::main

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

treeview.signal_connect("row-activated") do |treeview, path, column|
  puts path
  i = treeview.selection.selected
  puts "#{i[0]} => #{i[1]}"
end
052e5f25951098c61efd32e1da4863d5?d=identicon&s=25 Patrick Plattes (Guest)
on 2006-12-23 12:46
(Received via mailing list)
thanks oliver, that works great :-)

cu
pp
This topic is locked and can not be replied to.