comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Gtkada: attach signals to menus
Date: Sat, 18 Jun 2016 10:05:28 -0700 (PDT)
Date: 2016-06-18T10:05:28-07:00	[thread overview]
Message-ID: <adc9838a-a454-46ab-ae39-20f9f306c168@googlegroups.com> (raw)

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

             reply	other threads:[~2016-06-18 17:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-18 17:05 Stephen Leake [this message]
2016-06-18 18:07 ` Gtkada: attach signals to menus Dmitry A. Kazakov
2016-06-18 18:21   ` Stephen Leake
2016-06-19 15:02     ` Stephen Leake
2016-06-19 18:33       ` Dmitry A. Kazakov
2016-06-20  9:18         ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox