From: David Espada Date: 2004-04-28T21:04:11+09:00 Subject: [ruby-gtk2] problem changing menu in Gtk::OptionMenu Hi all. I need (again) help with ruby-gtk2. I have problems with this little code fragment: --------------------------------------------- #!/usr/bin/ruby require 'glib2' require 'gtk2' class BotonOpciones < Gtk::OptionMenu def initialize(valores=nil, inicial=nil) super() add_options(valores, inicial) if valores end def add_options(valores, inicial=nil) @valores = valores @valor = inicial || valores[0] # Remove last menu. Is this necesary? if @menu remove_menu @menu.destroy end @items = [] @menu = Gtk::Menu.new grupo = nil @valores.each do |v| item = Gtk::RadioMenuItem.new(grupo, v) @items << item grupo = item.group @menu.append(item) item.signal_connect('activate') do @valor = v if @valor != v end end set_menu(@menu) put_value(inicial) if inicial end def put_value(valor) @valores.each_with_index do |val, i| if valor == val then @items[i].active = true history = i return end end end def get_value @valor end end Gtk::init ventana = Gtk::Window.new ventana.set_title("Problema con OptionMenu") ventana.signal_connect('delete_event') {exit} vbox = Gtk::VBox::new(true, 10) boton1 = BotonOpciones.new(['hola', 'hello'], 'hola') boton2 = BotonOpciones.new(['adi坦s', 'bye'], 'bye') boton1.signal_connect('changed') do boton2.add_options(['otro', 'other'], 'otro') end vbox.pack_start(boton1, true, true, 0) vbox.pack_start(boton2, true, true, 0) ventana.add(vbox) ventana.show_all Gtk.main ------------------------------------------- When I select value of boton1, boton2 doesn't change menu, but instead I get an empty list. I don't know if I am doing something wrong or this is a bug. My system is a Debian Sid with libgtk2 packages from experimental (version 2.4) and ruby-gnome2 from CVS. Thanks. David