# Radio button in menu activate

**URL:** <https://www.ruby-forum.com/t/radio-button-in-menu-activate/77863>\
**Category:** Ruby-Gnome 2\
**Created:** [December 1, 2006, 2:08am UTC](https://www.ruby-forum.com/t/radio-button-in-menu-activate/77863 "2006-12-01T02:08:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![J-Van](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@J-Van](https://www.ruby-forum.com/u/J-Van)\
**Post date:** [December 1, 2006, 2:08am UTC](https://www.ruby-forum.com/t/radio-button-in-menu-activate/77863/1 "2006-12-01T02:08:11Z")

</div>

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:🪟: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](http://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](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![J-Van](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@J-Van](https://www.ruby-forum.com/u/J-Van)\
**Post date:** [December 1, 2006, 2:28am UTC](https://www.ruby-forum.com/t/radio-button-in-menu-activate/77863/2 "2006-12-01T02:28:18Z")

</div>

Hi,

2006/12/1, J-Van [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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](http://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](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![J-Van](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@J-Van](https://www.ruby-forum.com/u/J-Van)\
**Post date:** [December 1, 2006, 2:36am UTC](https://www.ruby-forum.com/t/radio-button-in-menu-activate/77863/3 "2006-12-01T02:36:20Z")

</div>

On 11/30/06, Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> 2006/12/1, J-Van [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > 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](http://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](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
