views:

787

answers:

2

Hey guys,

I am trying to make a gui with Glade 3 (gtk) and ruby but cannot figure out how to actually populate a combo box dynamically with say a list of strings. I get the xml .glade file after i visually make my gui in Glade, and use ruby-glade-create-template to generate my .rb file but have no idea where to go from here. I cannot find any guides on how to use ruby with Glade 3 and any help would be appreciated. Thanks!

A: 

Why do you need to generate a .rb file? Code generation is Frowned Upon™. So do you load the glade file with a Gtk::Builder instance? Once you have the Builder object you call the get_object method to get specific widgets.

Here is a pretty good tutorial on glade 3, it doesn't cover ruby but python is close enough. It is a little dated so some bugs mentioned there have been fixed if you are using a recent version of glade 3.

DoR
A: 
def initialize_combobox_script_select()
 #get combobox widget from glade file
 @combobox_script_select = @glade.get_widget("combobox_script_select")
 @combobox_script_select.set_active(0) #this makes <select a script> the default element in the combobox
 @script_list = ["helloworld", "byeworld"]
 @script_list.each{|script| @combobox_script_select.append_text("#{script}")} #populate the combobox with the list of scripts
end

This is some example code to initialize a combobox, that i used to fill up with script names.

Javed Ahamed