* Gtkada: attach signals to menus
@ 2016-06-18 17:05 Stephen Leake
2016-06-18 18:07 ` Dmitry A. Kazakov
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2016-06-18 17:05 UTC (permalink / 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Gtkada: attach signals to menus
2016-06-18 17:05 Gtkada: attach signals to menus Stephen Leake
@ 2016-06-18 18:07 ` Dmitry A. Kazakov
2016-06-18 18:21 ` Stephen Leake
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2016-06-18 18:07 UTC (permalink / raw)
On 2016-06-18 19:05, Stephen Leake wrote:
> I'm using GNAT 2016 GtkAda. I'm trying to set a menu signal handler
> in code, but the signal handler is not called.
Great! I missed notification that it is out. (I hope that it is not too
much GtkAda code is broken since GtkAda GPL 2015)
> 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);
Why not this:
Item.On_Activate (...); -- Called when File is activated
> 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?
I believe "activate-current" is not a notification signal, rather a
signal emitted in order to activate the menu item.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Gtkada: attach signals to menus
2016-06-18 18:07 ` Dmitry A. Kazakov
@ 2016-06-18 18:21 ` Stephen Leake
2016-06-19 15:02 ` Stephen Leake
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2016-06-18 18:21 UTC (permalink / raw)
On Saturday, June 18, 2016 at 1:08:03 PM UTC-5, Dmitry A. Kazakov wrote:
> On 2016-06-18 19:05, Stephen Leake wrote:
>
> > I'm using GNAT 2016 GtkAda. I'm trying to set a menu signal handler
> > in code, but the signal handler is not called.
>
> Great! I missed notification that it is out. (I hope that it is not too
> much GtkAda code is broken since GtkAda GPL 2015)
I don't know; I'm upgrading from GtkAda GPL 2012 (finally :). A lot is broken in that.
>
> Why not this:
>
> Item.On_Activate (...); -- Called when File is activated
Yes, that works. I'm not clear why I didn't try that in the first place.
Thanks,
-- Stephe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Gtkada: attach signals to menus
2016-06-18 18:21 ` Stephen Leake
@ 2016-06-19 15:02 ` Stephen Leake
2016-06-19 18:33 ` Dmitry A. Kazakov
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2016-06-19 15:02 UTC (permalink / raw)
Basic menus work, but I can't figure out how to compute the submenu on the fly.
Here's my attempt:
pragma License (GPL);
with Ada.Text_IO;
with Gtk.Main;
with Gtk.Menu;
with Gtk.Menu_Bar;
with Gtk.Menu_Item;
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_Menu_Table (Self : access Gtk.Menu_Item.Gtk_Menu_Item_Record'Class)
is
use Gtk.Menu_Item;
Table_Item : constant Gtk_Menu_Item := Gtk_Menu_Item (Self);
Menu : constant Gtk.Menu.Gtk_Menu := Gtk.Menu.Gtk_Menu_New;
Item : Gtk_Menu_Item;
begin
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Add");
Menu.Append (Item);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Edit");
Menu.Append (Item);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Delete");
Menu.Append (Item);
Table_Item.Set_Submenu (Menu);
end On_Menu_Table;
procedure On_Quit (Self : access Gtk.Menu_Item.Gtk_Menu_Item_Record'Class)
is
pragma Unreferenced (Self);
begin
Ada.Text_IO.Put_Line ("On_Quit");
end On_Quit;
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);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Quit");
Item.On_Activate (On_Quit'Access);
Menu.Append (Item);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_File");
Item.Set_Submenu (Menu);
Menu_Bar.Append (Item);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Table");
-- Submenu computed in On_Menu_Table
-- Item.On_Activate (On_Menu_Table'Access);
Item.On_Select (On_Menu_Table'Access);
Menu_Bar.Append (Item);
Menu_Bar.Show_All;
Main_Window.Add (Menu_Bar);
return Main_Window;
end Gtk_New;
end Menu_Demo_Pkg;
pragma License (GPL);
with Gtk.Window;
package Menu_Demo_Pkg is
function Gtk_New return Gtk.Window.Gtk_Window;
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;
If I use "On_Activate" for On_Menu_Table, the submenu is not shown. So I tried "On_Select"; still no submenu, and it crashes with
(menu_demo.exe:5884): Gtk-WARNING **: GtkWindow 001915B0 is mapped but visible child GtkMenu 08B2C468 is not mapped
I know how to compute a dynamic submenu in Emacs and Win32; there must be a way to do this in Gtk.
-- Stephe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Gtkada: attach signals to menus
2016-06-19 15:02 ` Stephen Leake
@ 2016-06-19 18:33 ` Dmitry A. Kazakov
2016-06-20 9:18 ` Stephen Leake
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2016-06-19 18:33 UTC (permalink / raw)
On 2016-06-19 17:02, Stephen Leake wrote:
> Basic menus work, but I can't figure out how to compute the submenu on the fly.
>
> Here's my attempt:
[...]
> If I use "On_Activate" for On_Menu_Table, the submenu is not shown. So I tried "On_Select"; still no submenu, and it crashes with
This is because you do not "show" submenu you create.
> (menu_demo.exe:5884): Gtk-WARNING **: GtkWindow 001915B0 is mapped but visible child GtkMenu 08B2C468 is not mapped
This is because you do it each time new. Looks like a GTK bug to me, but
the usage is not intended.
> I know how to compute a dynamic submenu in Emacs and Win32; there must be a way to do this in Gtk.
Here I changed your signal handler:
procedure On_Menu_Table (Self : access
Gtk.Menu_Item.Gtk_Menu_Item_Record'Class)
is
use Gtk.Menu_Item;
use Gtk.Widget;
Table_Item : constant Gtk_Menu_Item := Gtk_Menu_Item (Self);
begin
if Table_Item.Get_Submenu = null then -- Do it only once
declare
Menu : constant Gtk.Menu.Gtk_Menu := Gtk.Menu.Gtk_Menu_New;
Item : Gtk_Menu_Item;
begin
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Add");
Menu.Append (Item);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Edit");
Menu.Append (Item);
Item := Gtk_Menu_Item_New_With_Mnemonic ("_Delete");
Menu.Append (Item);
Menu.Show_All; -- Make it visible
Table_Item.Set_Submenu (Menu);
end;
end if;
end On_Menu_Table;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Gtkada: attach signals to menus
2016-06-19 18:33 ` Dmitry A. Kazakov
@ 2016-06-20 9:18 ` Stephen Leake
0 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 2016-06-20 9:18 UTC (permalink / raw)
On Sunday, June 19, 2016 at 1:33:36 PM UTC-5, Dmitry A. Kazakov wrote:
> On 2016-06-19 17:02, Stephen Leake wrote:
> > Basic menus work, but I can't figure out how to compute the submenu on the fly.
> >
> > Here's my attempt:
>
> [...]
>
> > If I use "On_Activate" for On_Menu_Table, the submenu is not shown. So I tried "On_Select"; still no submenu, and it crashes with
>
> This is because you do not "show" submenu you create.
Arg. I keep expecting things to be shown by default.
> Here I changed your signal handler:
Right, but I want different results depending on some state. I ended up creating all the possible menu items in gtk_new, and using show/hide in On_Menu_Table:
procedure On_Menu_Table (Self : access Gtk.Menu_Item.Gtk_Menu_Item_Record'Class)
is
pragma Unreferenced (Self);
begin
case State is
when True =>
Table_Menu_Add.Show;
Table_Menu_Edit.Show;
Table_Menu_Delete.Hide;
when False =>
Table_Menu_Add.Hide;
Table_Menu_Edit.Hide;
Table_Menu_Delete.Show;
end case;
State := not State;
end On_Menu_Table;
That works nicely.
Thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-06-20 9:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-18 17:05 Gtkada: attach signals to menus Stephen Leake
2016-06-18 18:07 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox