Hi,
VR doesn’t initialize the Gtk::ComboBox correctly. It looks as if VR’s
combobox constructor is always called with the argument false. Anyhow,
it seems not only is the run-time assignment of different data model to
a VR combo-box not working, initialization of VR’s combo-box too, looks
like a generic VR/Glade problem!?
Both, GTK+ and Ruby-GTK allow to dynamically change the models for any
combo-box.
I have tested Gtk::ComboBox in VR with both, (1) the model created in
Glade, (2) and the one generated manually in initialize method. It
turned out that VR’s ComboBox object is aware of both and can even
combine them, i.e. you can append programmatically items to the Glade
generated model, if you so desire. However, VR fails to display either
of them regardless of how you set up the respective model values (rows).
You can tinker with the following code in VR’s “MyClass”, and see for
yourself that all items are available to ‘cb’ (combobox) object in VR:
class MyClass #(change name)
include GladeGUI
def initialize
load_glade(FILE)
combArray = [“plane”, “ship”, “car”]
store = Gtk::ListStore.new(String)
store = @builder[“liststore1”]
combArray.each do |e|
iter = store.append
iter[0] = e
end
puts "DEBUG: @builder.class=#{@builder.class} " +
"store.class=#{store.class}"
cb = @builder["combobox1"]
cb.set_model(store)
cb.active = 3
puts "DEBUG: active_text=#{cb.active_text}"
end
def show()
load_glade(FILE) #loads glade/MyClass.glade into @builder
@label1 = “Hello World”
set_glade_all() #populates glade controls with instance variables
show_window()
end
end
If you correctly initialize the ‘liststore1’ in Glade, and also set a
few columns, say (“horse”, “bicycle”, “rollers”), values in it, you can
combine the model rows (“plane”, “ship”, “car”) defined programmatically
in MyClass’s ‘initialize’ with the model rows (“horse”, “bicycle”,
“rollers”) defined in Glade into a single VR’s “cb” list (“horse”,
“bicycle”, “rollers”, “plane”, “ship”, “car”), by uncommenting // store
= @builder[“liststore1”] // line in the above listing. To confirm that
VR’s combobox contains both lists you can first set //cb.active = 0//,
and in the next test run to ‘4’ (//cb.active = 4//). The two VR test
runs will in //puts “DEBUG: active_text=#{cb.active_text}”// correctly
print ‘horse’ and ‘ship’ respectively.
For this test to work for both programmatically set model and the one
set in Glade, you have to assign ‘liststore1’ ‘to tour combobox1’ in
Glade. Also in Glade under “Add and remove columns” you have to set up
liststore1’s “Column type” to “gchararray” data type. And lastly, under
“Add and remove rows” add for example the rows as suggested above
(“horse”, “bicycle”, “rollers”) to the ‘liststore1’.