[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

Hi,

Hi all. I need (again) help with ruby-gtk2.

I have problems with this little code fragment:

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.

A new widget which you create in BotonOpciones#add_options doesn’t
call Gtk::Widget#show or #show_all.
Try to call @menu.show_all after calling BotonOpciones#set_menu().

Everytime you need to call Gtk::Widget#show(#show_all) when you
want to show your Widgets.

···

On Wed, 28 Apr 2004 21:04:11 +0900 David Espada davinciSINSPAM@escomposlinux.org wrote:


.:% Masao Mutohmutoh@highway.ne.jp

An obvious error 0:)

Thanks for all.

						David
···

El miércoles 28 de abril, Masao Mutoh escribió:

I don’t know if I am doing something wrong or this is a bug.

Everytime you need to call Gtk::Widget#show(#show_all) when you
want to show your Widgets.