here i start with GtkAda but i met a problem that i don't understand. I give you a summary of the code.
file.ads
With Gtk.Window; Use Gtk.Window;
With Gtk.Table; Use Gtk.Table;
With Gtk.Widget; use Gtk.Widget;
With Gtk.Alignment; Use Gtk.Alignment;
Package File is
Type Align is array ( Positive range <> ) of Gtk_Alignment;
Type T_Test_Record is tagged record
Conteneur : Gtk_Table;
Win : Gtk_Window;
Button1 : Gtk_Button;
Button2 : Gtk_Button;
end record;
Type T_Test is access all T_Test_Record;
Align_Elements : Align(1..2);
Procedure Initialize_Window ( Window : out T_Test_Record ) ;
-- Initialize the Window of Gtk_Window type.
Procedure Initialize_Table ( Table : out T_Test_Record );
-- Initialze the Table of Gtk_Table type.
Procedure Initialize_Buttons ( Button : T_Test );
-- Initialize the Button1 and button2 of Gtk_Button type.
Procedure Show_Window ( Window : out T_Test_Record );
-- Display the Window with the method Gtk.Widgdet.Show_All
Private
Procedure Exit_Window (Window : access Gtk_Widget_Record'Class);
-- Callback to Close the Window.
end file;
File.adb
With Gtk.Main; Use Gtk.Main;
Package body File is
Procedure Initialize_Window ( Window : out T_Test_Record ) is
begin
Gtk_New (Window.Win);
Window.Win.Set_Default_Size (Width => 600,
Height => 400);
P.Connect (Window.Win,
Name => Signal_Destroy,
Marsh => P.To_Marshaller (Exit_Window'Access),
After => False);
end Initialize_Window;
Procedure Initialize_Buttons ( Button : T_Test ) is
Begin
Gtk_New (Button.Button1,Label => "Bouton1");
Gtk_New (Button.Button2,Label => "Bouton2");
For i in Align_Elements'range loop
Case i is
When 1 => Gtk_New (Align_Elements(i),
Xalign => 0.0,
Yalign => 0.0,
Xscale => 0.0,
Yscale => 0.0);
Align_Elements(i).Add (Button.Button1);
When 2 => Gtk_new (Align_Elements(i),
Xalign => 0.5,
Yalign => 0.0,
Xscale => 0.0,
Yscale => 0.0);
Align_Elements(i).Add (Button.Button2);
end case;
end loop;
Test2.P.Connect (Widget => Button.Button1,
Name => Signal_Clicked,
Marsh => P.To_Marshaller
(Callback_Bouton1'Access),
After => False);
end Initialize_Buttons;
Procedure Initialize_Table ( Table : out T_Test_Record ) is
Window : T_Test;
begin
Window := New T_Test_Record;
Initialize_Window (Window => Table);
Initialize_Buttons (Button => Window);
Gtk_New (Table.Conteneur,
Rows => 0,
Columns => 0,
Homogeneous => False);
For i in Align_Elements'range loop
Table.Conteneur.Add (Align_Elements(i));
end loop;
Table.Win.Add (Table.Conteneur);
end Initialize_Table;
Procedure Show_Window (Window : out T_Test_Record ) is
begin
Initialize_Table (Table => Window);
Window.Win.Show_All;
end Show_Window;
Procedure Exit_Window ( Window : access Gtk_Widget_Record'Class)
is
begin
Main_Quit;
end Exit_Window;
end File;
file2.ads
With file; Use file;
With Gtk.Radio_Button; Use Gtk.Radio_Button;
With Gtk.Handlers;
Package file2 is
Package P is new Gtk.Handlers.Callback (Gtk_Widget_Record);
Use P;
Type Continent is (Europa, America, Africa, Asia);
Type Payment_Mode ( Choose : Continent := America ) is record
bank_Transfer : Gtk_Radio_Button;
Case Choose is
When Europa | America | Asia =>
By_Check : Gtk_Radio_Button;
By_Card : Gtk_Radio_Button;
When Africa => null;
end case;
end record;
Type Test_Record Is new T_Test_Record with record
Method : Payment_Mode;
Amount : Integer;
end record;
Type Test is access all Test_Record'class;
Procedure Saisir_Montant ( Saisie : out Test_Record );
Procedure Choose_Payment_Mode ( Mode : Test );
Procedure Callback_Bouton1 (Emet : access Gtk_Widget_Record'Class);
end file2;
File2.adb
With Ada.Integer_Text_IO; Use Ada.Integer_Text_IO;
Package body file2 is
Procedure Saisir_Montant (Saisie : out Test_Record ) is
begin
Put_Line ("Entry Amount");
Get (Saisie.Amount); Skip_Line;
end Saisir_Montant;
Procedure Choose_Payment_Mode (Mode : Test ) is
Local_Variable : Test_Record;
begin
Saisir_Montant (Local_Variable);
Put_Line ("What's your payment mode ?");
Gtk_New (Mode.Method.bank_transfer,
Group => null,
Label => "Wire");
Gtk_New (Mode.Method.By_Check,
Group => null,
Label => "Check");
Gtk_New (Mode.Method.By_Card,
Group => null,
Label => "Card");
end Choose_Payment_Mode;
Procedure Callback_Bouton1 (Emet : access Gtk_Widget_Record'Class) is
Local_Variable : Test;
begin
Local_Variable := New Test_Record;
Choose_Payment_Mode (Mode => Local_Variable);
Initialize_Table (Table => Local_Variable.all);
Local_Variable.Conteneur.Add (Local_Variable.Method.bank_transfer);
Local_Variable.Conteneur.Add (Local_Variable.Method.By_Check);
Local_Variable.Conteneur.Add (Local_Variable.Method.By_Card);
Local_Variable.Conteneur.Show_All;
end Callback_Bouton1;
end File2;
Main_Program.Adb
With file; Use file;
Procedure Main_Program is
Test : T_Test_Record;
begin
Init;
Show_Window (Window => Test);
Main;
end Main_Program;
the program compile and execute well but don't show me my Gtk_Radio_Button (in package File2.Choose_Payment_Mode) called when click on button1. the callback works very well but my Gtk_Radio_Button don't Show. yet i don't see any error.