Your code almost works… Try changing “row_activated” to
“row-activated”
and double click the value to see the dropdown appear. I’m guessing you
probably don’t want to have to double click the item to see the
dropdown,
so you may need to connect to a different signal.
Jon
From: “Eric C.” [email protected]
To: [email protected],
Date: 02/03/2012 12:29 AM
Subject: Re: [ruby-gnome2-devel-en] Can CellRendererCombo do
individual rows?
Sorry about my badly phrased question. Thank you for your responses.
This is what I’m trying to do exactly:
I’m trying to make a listbox for a person with these fields:
NAME
ADDRESS
CHILDREN (dropdown menu)
I can’t get the CHILDREN dropdown to work.
I’ve distilled it down to a short file that runs, but won’t show
individual dropdowns for children. Just run this script, and you’ll see
that the “row_activated” signal dies for some reason. If you can get
each of these rows to display their own individual menu, you will have
fixed my problem. Notice that when you run the program, the same
dropdow appears for every entry.
Thanks!
require ‘gtk2’
module Util # generates a random set of choices
def Util.rand_model
s = Gtk::ListStore.new(String)
r = s.append
r[0] = rand(1000).to_s
r = s.append
r[0] = rand(1000).to_s
r = s.append
r[0] = rand(1000).to_s
return s
end
end
@v = Gtk::TreeView.new()
@v.model = Gtk::ListStore.new(String)
r = @v.model.append
r[0] = “Hello”
r = @v.model.append
r[0] = “World”
r = @v.model.append
r[0] = “Today”
ren = Gtk::CellRendererCombo.new
uncomment this and the value will update
ren.signal_connect(‘edited’) do |ren, path, text|
i = @v.model.get_iter(path)
i[0] = text
end
col = Gtk::TreeViewColumn.new
col.pack_start( ren, false )
col.add_attribute( ren, :text, 0)
@v.append_column(col)
I tried “changed” signal too, but it doesn’t work
@v.signal_connect(“row_activated”) do |view, path, col|
puts "row_activated: "
i = view.selection.selected
puts i.to_s
rend = col.cell_renderers[0]
rend.text_column = 0
rend.model = Util.rand_model
end
ren.editable = true
window = Gtk::Window.new(Gtk:
:TOPLEVEL)
window.signal_connect(“delete_event”) { Gtk.main_quit; exit! }
window.add(@v)
window.show_all
Gtk.main
–
Posted via http://www.ruby-forum.com/.