From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.46.5.146 with SMTP id 140mr2301327ljf.1.1466269528887; Sat, 18 Jun 2016 10:05:28 -0700 (PDT) X-Received: by 10.157.47.177 with SMTP id r46mr263163otb.15.1466269528789; Sat, 18 Jun 2016 10:05:28 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!goblin3!goblin1!goblin.stu.neva.ru!w10no2383292lbo.0!news-out.google.com!di11ni25188lbb.1!nntp.google.com!oe3no4184052lbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 18 Jun 2016 10:05:28 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.218.37.33; posting-account=W2gdXQoAAADxIuhBWhPFjUps3wUp4RhQ NNTP-Posting-Host: 76.218.37.33 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Gtkada: attach signals to menus From: Stephen Leake Injection-Date: Sat, 18 Jun 2016 17:05:28 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:30790 Date: 2016-06-18T10:05:28-07:00 List-Id: I'm using GNAT 2016 GtkAda. I'm trying to set a menu signal handler in code, but the signal handler is not called. I'm not using the xml ui builder, because in my full app I need to compute a submenu based on context. Here's the code that doesn't work (pasted into Google Groups web UI, so pardon the line breaks): pragma License (GPL); with Ada.Text_IO; with Gtk.Main; with Gtk.Menu; with Gtk.Menu_Bar; with Gtk.Menu_Item; with Gtk.Menu_Shell; with Gtk.Widget; package body Menu_Demo_Pkg is procedure On_Window_Destroy (Widget : access Gtk.Widget.Gtk_Widget_Record'Class) is pragma Unreferenced (Widget); begin Gtk.Main.Main_Quit; end On_Window_Destroy; procedure On_File_Menu_Activate (Self : access Gtk.Menu_Shell.Gtk_Menu_Shell_Record'Class; Force_Hide : Boolean) is pragma Unreferenced (Force_Hide); pragma Unreferenced (Self); begin Ada.Text_IO.Put_Line ("On_File_Menu_Activate"); end On_File_Menu_Activate; procedure On_Menu_Activate (Self : access Gtk.Menu_Shell.Gtk_Menu_Shell_Record'Class; Force_Hide : Boolean) is pragma Unreferenced (Force_Hide); pragma Unreferenced (Self); begin Ada.Text_IO.Put_Line ("On_Menu_Activate"); end On_Menu_Activate; function Gtk_New return Gtk.Window.Gtk_Window is use Gtk.Menu; use Gtk.Menu_Item; Main_Window : constant Gtk.Window.Gtk_Window := Gtk.Window.Gtk_Window_New; Menu_Bar : constant Gtk.Menu_Bar.Gtk_Menu_Bar := Gtk.Menu_Bar.Gtk_Menu_Bar_New; Menu : constant Gtk_Menu := Gtk_Menu_New; Item : Gtk_Menu_Item; begin Main_Window.On_Destroy (On_Window_Destroy'Access); Menu.Append (Gtk_Menu_Item_New_With_Mnemonic ("_Quit")); Item := Gtk_Menu_Item_New_With_Mnemonic ("_File"); Item.Set_Submenu (Menu); Menu_Bar.Append (Item); Menu_Bar.Show_All; Menu.On_Activate_Current (On_File_Menu_Activate'Access); Menu_Bar.On_Activate_Current (On_Menu_Activate'Access); Main_Window.Add (Menu_Bar); return Main_Window; end Gtk_New; end Menu_Demo_Pkg; pragma License (GPL); with Ada.Exceptions; with Ada.Text_IO; with GNAT.Traceback.Symbolic; with Gtk.Main; with Gtk.Window; with Menu_Demo_Pkg; procedure Menu_Demo is Main_Window : Gtk.Window.Gtk_Window; begin Gtk.Main.Init; Main_Window := Menu_Demo_Pkg.Gtk_New; Main_Window.Show; Gtk.Main.Main; exception when E : others => Ada.Text_IO.Put_Line ("Unhandled exception " & Ada.Exceptions.Exception_Name (E) & ": " & Ada.Exceptions.Exception_Message (E)); Ada.Text_IO.Put_Line (GNAT.Traceback.Symbolic.Symbolic_Traceback (E)); end Menu_Demo; When I run menu_demo, a window shows, with a menu. But when I select the menu item, no text is displayed. How do I make this work? -- stephe