[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gtk/glade and combobox

Joel Almeida

11/4/2008 6:46:00 PM

Hi all!
I made a GUI for my ruby gtk2 app and this is the code:
[code]
#!/usr/bin/ruby

require 'libglade2'
require 'gtk2'

class GladeRuby

def button1_clicked
entry1 = @glade.get_widget('entry1')
combo1 = @glade.get_widget('combo1')
combo1.model.append.set_value(0, entry1.text)
end

def window1_destroy
on_window_exit
end

def initialize(glade_file)
Gtk.init
@glade = GladeXML.new(glade_file) { |handler|
method(handler)
}
@window1 = @glade.get_widget('window1')
## Beta ##
cadenas = ['joel', 'caca', 'popo', 'tyta']
liststore = Gtk::ListStore.new(String)
cadenas.each do |item|
iter = liststore.append
iter[0] = item # Doesn't work :(
end
@glade.get_widget('combo1').set_model(liststore)
## ###
@window1.show_all()
Gtk.main
end

def on_window_exit
Gtk.main_quit
end

end

if __FILE__ == $0
GLADE_XML_FILE = 'rbcombo.glade'
GladeRuby.new(GLADE_XML_FILE)
end
[/code]
My goal is to load the strings from 'cadena' into the combobox, which it
doesn't...any ideas?
--
Posted via http://www.ruby-....

1 Answer

Kouhei Sutou

11/6/2008 1:10:00 PM

0

Hi,

In <10fae550348dec41c50ebfe8a82bf382@ruby-forum.com>
"gtk/glade and combobox" on Wed, 5 Nov 2008 03:45:54 +0900,
Joel Almeida <aullidolunar@gmail.com> wrote:

> Hi all!
> I made a GUI for my ruby gtk2 app and this is the code:
> [code]
> #!/usr/bin/ruby
>
> require 'libglade2'
> require 'gtk2'
>
> class GladeRuby
>
> def button1_clicked
> entry1 = @glade.get_widget('entry1')
> combo1 = @glade.get_widget('combo1')
> combo1.model.append.set_value(0, entry1.text)
> end
>
> def window1_destroy
> on_window_exit
> end
>
> def initialize(glade_file)
> Gtk.init
> @glade = GladeXML.new(glade_file) { |handler|
> method(handler)
> }
> @window1 = @glade.get_widget('window1')
> ## Beta ##
> cadenas = ['joel', 'caca', 'popo', 'tyta']
> liststore = Gtk::ListStore.new(String)
> cadenas.each do |item|
> iter = liststore.append
> iter[0] = item # Doesn't work :(
> end
> @glade.get_widget('combo1').set_model(liststore)
> ## ###
> @window1.show_all()
> Gtk.main
> end
>
> def on_window_exit
> Gtk.main_quit
> end
>
> end
>
> if __FILE__ == $0
> GLADE_XML_FILE = 'rbcombo.glade'
> GladeRuby.new(GLADE_XML_FILE)
> end
> [/code]
> My goal is to load the strings from 'cadena' into the combobox, which it
> doesn't...any ideas?

Where is rbcombo.glade file? I couldn't run the example
script.

Thanks,
--
kou