From: Joe Van Dyk Date: 2005-07-22T05:56:51+09:00 Subject: Re: ruby gnome question On 7/21/05, Joe Van Dyk wrote: > I have something like this > > class MenuBar < Gtk::MenuBar > def initialize > super > # create menu buttons > show > end > end > > class ApplicationWindow < Gtk::Window > def initialize > super > container = Gtk::VBox.new > container.pack_start MenuBar.new > container.show > end > end > > So, when the menu bar gets clicked, a signal gets emitted in the Menu > Bar object. How can the Application Window object know that a menu > bar gets clicked? Do I need to create a new signal to notify the > Application Window? Below is the actual class, would appreciate suggestions on how I can notify another object that the menu has been clicked. Or should I not do things this way? class MenuBar < Gtk::MenuBar def initialize super # Create the File Menu file_menu = create_top_level_menu "File" create_menu_item(file_menu, "Quit") { Gtk::main_quit } # Create the Scaling Menu scale_menu = create_top_level_menu "Scaling" for scale in World.instance.Scales # returns an array of ints create_menu_item(scale_menu, scale.to_s) do # Gets ran when the menu option gets clicked. how can i notify other objects # that it has been clicked? # # Also, if I print out the value of scale here , it's always the same, no matter what # menu option has been clicked. Why is that? end end # Show the Menu show end # Create a top level menu def create_top_level_menu title top_menu = Gtk::MenuItem.new title sub_menu = Gtk::Menu.new top_menu.submenu = sub_menu sub_menu.show top_menu.show append top_menu sub_menu end # Create a menu item that goes under a top level menu def create_menu_item menu, title, &action menu_item = Gtk::MenuItem.new title menu_item.signal_connect('activate') { action.call } menu_item.show menu.append menu_item end end