Hi: I'm trying to make CellRendererCombo work. If I understand it correctly, you set the model like this: store = Gtk::ListStore.new) add rows... renderer.model = store Does that mean that the same model applies to all rows? Is it possible to make each row have its own combobox settings? For example, if your combobox had a list of people, then you could have a combobox that contains their children? Thanks, Eric
on 2012-02-02 08:51
on 2012-02-02 14:08
Eric C. wrote in post #1043611: > Does that mean that the same model applies to all rows? This question makes no sense. The model contains all the rows, just like an array. Read 'Model', think 'List'. > Is it possible to make each row have its own combobox settings? For > example, if your combobox had a list of people, then you could have a > combobox that contains their children? You misunderstand combobox I think. ComboBox is one way to display models. If you have one combo with parent, and one with children, then you have 2 models, one with parent, and one with children. And you can update the children model when you select a parent in the parent combobox. Simon
on 2012-02-02 14:14
Hi Eric, Are you talking about having a dependant combo box? So you select a parent in one and it populates the 2nd with the children? If so, I believe all you have to do is swap out the model for the children whenever a parent is selected. If the data set is going to be a reasonable size, you can use a hash to cache the children models so you don't have to create them each time. Alternatively, instead of swapping out the models you can use a single one and clear / repopulate each time. Its a little slower, but with a huge dataset it saves you from wasting memory. Jon From: "Eric C." <ruby-forum-incoming@andreas-s.net> To: ruby-gnome2-devel-en@lists.sourceforge.net, Date: 02/02/2012 02:51 AM Subject: [ruby-gnome2-devel-en] Can CellRendererCombo do individual rows? Hi: I'm trying to make CellRendererCombo work. If I understand it correctly, you set the model like this: store = Gtk::ListStore.new) add rows... renderer.model = store Does that mean that the same model applies to all rows? Is it possible to make each row have its own combobox settings? For example, if your combobox had a list of people, then you could have a combobox that contains their children? Thanks, Eric -- Posted via http://www.ruby-forum.com/.
on 2012-02-03 06:29
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::Window::TOPLEVEL)
window.signal_connect("delete_event") { Gtk.main_quit; exit! }
window.add(@v)
window.show_all
Gtk.main
on 2012-02-03 15:19
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." <ruby-forum-incoming@andreas-s.net>
To: ruby-gnome2-devel-en@lists.sourceforge.net,
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::Window::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/.
on 2012-02-03 22:53
SOLVED!!!! Thanks for your help!!! The problem was that the row_activated event was occurring after the cell was being edited. So, my program was trying to changed the model after the dropdown was being shown. I changed to the "cursor_changed" event, so now when a user double-clicks on a cell to edit, the model will populate on the first click BEFORE the edit starts. I guess timing is everything :) I'm happy to say this will be included when I release my software. Look for "Visual Ruby" Thanks again, Eric
on 2012-02-04 22:01
Eric C. wrote in post #1044009: > I changed to the "cursor_changed" event, so now when a user > double-clicks on a cell to edit, the model will populate on the first > click BEFORE the edit starts. I wonder, since you change the model on the fly, what do you get when you read back the value after editing multiple lines ? Simon
on 2012-02-07 10:02
Hi Simon: When I said, "the model will populate on the first click..." I was refering to the model of the dropdown menu, not the model of the listview itself. What happens is that the user clicks the child field, which fires the "cursor_changed" event. That event populates the dropdown menu with the names of the children. Then, on the second click, the edit field (??? exact name???) event is called which switches the text to a combobox dropdown menu. The user can select a child from the list, and press <enter>. Then the "edited" event is called which updates the model of the listview. So each child is edited individually. Everything works perfectly. I'm getting very close to releasing my gem, "visualruby." Thanks for your help with it! Eric
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.