Radio button in menu activate

Hi,

In the following code, when I select the second radio button, both the
‘activate’ callbacks are executed. I don’t want both to be executed,
only the selected menu should have its callback executed. Any ideas?

Thanks,
Joe

require ‘gtk2’
Gtk.init

Create a new window

window = Gtk::Window.new( Gtk::Window::TOPLEVEL )
window.set_size_request( 200, 100 )
window.set_title( “Ruby-GNOME2 Menu Test” )
window.signal_connect( “delete_event” ) { Gtk.main_quit }
vbox = Gtk::VBox.new( false, 0 )
window.add( vbox )

Create the menubar

menubar = Gtk::MenuBar.new
vbox.pack_start( menubar, false, false, 0)

Create our toplevel menuitem

top_menu = Gtk::MenuItem.new( “Root Menu” )

Append top_menu into the menubar

menubar.append( top_menu )

Create an empty menu to hold all of our menuitems

menu = Gtk::Menu.new

Create radio menus

first = Gtk::RadioMenuItem.new “First”
second = Gtk::RadioMenuItem.new first, “Second”
menu.append first
menu.append second

Connect signals to the radio menu items

first.signal_connect(“activate”) { puts “First activated” }
second.signal_connect(“activate”) { puts “Second activated” }

top_menu.set_submenu( menu )

window.show_all
Gtk.main


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Hi,

2006/12/1, J-Van [email protected]:

In the following code, when I select the second radio button, both the
‘activate’ callbacks are executed. I don’t want both to be executed,
only the selected menu should have its callback executed. Any ideas?

Use Gtk::RadioMenuItem#active? method.

Connect signals to the radio menu items

first.signal_connect(“activate”) { puts “First activated” }
second.signal_connect(“activate”) { puts “Second activated” }
first.signal_connect(“activate”) { |w| puts “First activated: active?:
#{w.active?}” }
second.signal_connect(“activate”) { |w| puts “Second activated:
active?: #{w.active?}” }

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

On 11/30/06, Kouhei S. [email protected] wrote:

Hi,

2006/12/1, J-Van [email protected]:

In the following code, when I select the second radio button, both the
‘activate’ callbacks are executed. I don’t want both to be executed,
only the selected menu should have its callback executed. Any ideas?

Use Gtk::RadioMenuItem#active? method.

Ah, thanks.
The following does what I want:

first.signal_connect(“activate”) { puts “First activated” if
first.active? }
second.signal_connect(“activate”) { puts “Second activated” if
second.active? }

Joe

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV