You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-The switch button doesn't light up, in red, when it's in the “on” position, whereas it does with the equivalent C code.
-In fact, its behavior is random: under certain circumstances, it lights up, but this behavior cannot be linked to any event.
Thanks
mark
-- units from Gtk
with Gtk.Main;
with Glib.Error; use Glib.Error;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Builder; use Gtk.Builder;
with Gtkada.Builder; use Gtkada.Builder;
-- Ada predefined units
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions;
-- Application specific units
with Window_Callbacks; use Window_Callbacks;
begin
-- Appelé dans toutes les applications GtkAda.
-- Arguments ligne de commande sont analysés & retournés à l'application.
Gtk.Main.Init;
-- Etape 1 : créer un Builder
-- & lui donner accès à la fenetre maitre du fichier XML.
Gtk_New (Builder);
-- C'est le test qui provoqe le chargement du fichier xml (*.glade) par le builder.
if Add_From_File (Gtk_Builder(Builder), GladeFileName, Error'Access) = 0 then
Put_Line ("Error : " & Get_Message (Error));
Error_Free (Error);
return;
end if;
Put_Line (FileName & " : loading of builder OK ");
-- Etape 2 : créer les handlers ("poignées") des events
-- (de façon à préparer les callback).
Register_Handler (Builder, "on_delete_event", On_Delete_Event'Access);
Register_Handler (Builder, "on_destroy", On_Destroy'Access);
Register_Handler (Builder, "on_switch1_state_set", On_Switch1_State_Set'Access);
Register_Handler (Builder, "on_font1_font_set", On_Font1_Font_Set'Access);
Register_Handler (Builder, "on_volume1_value_changed", On_Volume1_Value_Changed'Access);
Register_Handler (Builder, "on_scroll1_value_changed", On_Volume1_Value_Changed'Access);
Register_Handler (Builder, "adjustment2", On_Adjustment2'Access);
-- Etape 3 : Do_Connect connecte tous les handlers enregistrés en une fois.
Do_Connect (Builder);
Put_Line ("Booleen du Switch : " & boolean'Image (On_Switch1_State_Set (Builder)));
-- Etape 4 : Afficher la fenetre avec ses dépendances
Show_All (Gtk_Widget (Get_Object (GTK_Builder (Builder), "window")));
-- Etape 5 : Lancer la boucle infinie.
Gtk.Main.Main;
-- Etape 6 : appeler Unref quand l'application se termine
-- pour libérer la memoire associée au Builder.
Unref (Builder);
Put_Line ("Program " & FileName & " is finished !");
exception
when Error : others =>
Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (Error));
end Glade_9;
-- units from GtkAda
with Gtk.Label; use Gtk.Label;
with Gtk.Switch; use Gtk.Switch;
with Gtk.Font_Button; use Gtk.Font_Button;
with Gtk.Scale_Button; use Gtk.Scale_Button;
with Gtk.GRange; use Gtk.GRange;
-- units from Glib
with Glib; use Glib;
with Glib.Object; use Glib.Object;
-- Ada predefined units
with Ada.Text_IO; use Ada.Text_IO;
package body Window_Callbacks is
-- On_Window1_Delete_Event
function On_Delete_Event
(Builder : access Gtkada_Builder_Record'Class) return Boolean is
pragma Unreferenced (Builder);
begin
put_line("Delete event");
return False;
end On_Delete_Event;
-- Callback to destroy a widget
procedure On_Destroy (Builder : access Gtkada_Builder_Record'Class) is
pragma Unreferenced (Builder);
begin
Put_Line ("quitting");
Gtk.Main.Main_Quit;
end On_Destroy;
-- On_Switch1_Activate
Function On_Switch1_State_Set (Builder : access Gtkada_Builder_Record'Class) return boolean is
begin
if Gtk_Switch (Get_Object (Builder, "switch1")).Get_Active then
-- Pas de contrôles des "fontes".
--Gtk.Label.Set_Text (Gtk_Label (Get_Object (Builder, "label1")), "Switch 1 Active");
-- Contrôle des "fontes". NB : seul "size" est actif, cause inconnue..
Set_Markup (Gtk_Label (Get_Object (Builder, "label1")),
"<span weight=""ultrabold"" color=""#FF6600"" size=""x-large"">Switch 1 Active</span>");
else
Gtk.Label.Set_Text (Gtk_Label (Get_Object (Builder, "label1")), "Switch 1 Not Active");
end if;
return (Gtk_Switch (Get_Object (Builder, "switch1")).Get_Active);
end On_Switch1_State_Set;
-- On_Font_Font_Set
procedure On_Font1_Font_Set (Builder : access Gtkada_Builder_Record'Class) is
Button : access Gtk_Font_Button_Record;
begin
-- Get the font chooser button
Button := Gtk_Font_Button (Get_Object(Builder, "font1"));
declare
Font_Name : constant string := Get_Font (Button);
--Font_Name : constant string := Get_Font_Name (Button); --Deprecated since 3.22
--Font_Name : constant string := Get_Font (Button); --Ne marche pas (comme en C).
--Font_Name : constant string := Get_Font_Features (Button); --Ne marche pas
--Font_Size : constant Gint := Get_Font_Size (Button); --Ne marche pas.
begin
--Afficher l'entry du selecteur de fontes
Gtk.Label.Set_Text (Gtk_Label (Get_Object (Builder, "label2")), "Ne marche pas, ni en GtkAda, ni en C..");
Ada.Text_IO.Put_Line ("Font selected : " & Font_Name & " Ne marche pas, ni en GtkAda, ni en C..");
--Deprecated since: 3.22
--Use the GtkFontChooser::font property instead.
--Ada.Text_IO.Put_Line ("Size selected : " & GInt'Image (Font_Size));
end;
end On_Font1_Font_Set;
-- On_Volume_Value_Changed
procedure On_Volume1_Value_Changed (Builder : access Gtkada_Builder_Record'Class) is
Button : access Gtk_Scale_Button_Record;
begin
Button := Gtk_Scale_Button (Get_Object(Builder, "volume1"));
declare
-- Gtk.Scale_Button.Set_Value
-- can be used to set the volume control to a particular value.
Volume_Value : constant GDouble := (Gtk.Scale_Button.Get_Value (Button));
begin
Ada.Text_IO.Put_Line ("Volume scale : " & GDouble'Image (Volume_Value));
end;
end On_Volume1_Value_Changed;
-- Attaché au scroll précédent (On_Scroll_Value_Changed)
procedure On_Adjustment2 (Builder : access Gtkada_Builder_Record'Class) is --Ajout
begin
null;
end On_Adjustment2;
end Window_Callbacks;
-- gtkada_issues.glade
1000
1
10
38
False
399
272
True
False
205
True
False
I am a label hiding here.
label 1
150
216
205
True
False
label2
150
238
False
True
True
Switch!
10
126
141
51
True
True
True
2
1
Sans 12
140
114
True
True
False
True
none
vertical
audio-volume-muted-symbolic
audio-volume-high-symbolic
audio-volume-low-symbolic
audio-volume-medium-symbolic
True
True
center
center
none
True
True
center
center
none
185
63
16
244
True
False
vertical
adjustment2
321
15
`
`/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+ Glade / Gtk Programming
#+
#+ Copyright (C) 2019 by Kevin C. O'Kane
#+
#+ Kevin C. O'Kane
#+ [email protected]
#+ https://www.cs.uni.edu/~okane
#+ http://threadsafebooks.com/
#+
#+ This program is free software; you can redistribute it and/or modify
#+ it under the terms of the GNU General Public License as published by
#+ the Free Software Foundation; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program is distributed in the hope that it will be useful,
#+ but WITHOUT ANY WARRANTY; without even the implied warranty of
#+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#+ GNU General Public License for more details.
#+
#+ You should have received a copy of the GNU General Public License
#+ along with this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/
//---------------------------------------------------------------------
// establish contact with xml code used to adjust widget settings
//---------------------------------------------------------------------
/*******************************************************************
The function:
void gtk_scale_button_set_value (GtkScaleButton *, gdouble)
can be used to set the volume control to a particular value.
********************************************************************/
printf("volume scale = %f\n", gtk_scale_button_get_value(GTK_SCALE_BUTTON(v1)) );
}
void on_scroll1_value_changed(GtkRange *r) {
gdouble x = gtk_range_get_value (r);
printf("scroll = %d\n", (int) x );
}
/* glade_9-c.glade */
1000
1
10
False
True
False
205
True
False
I am a label hiding here.
label 1
220
282
205
True
False
label2
220
306
True
True
Switch!
10
231
True
True
True
Sans 12
115
197
True
True
False
True
vertical
invalid
adjustment2
audio-volume-muted-symbolic
audio-volume-high-symbolic
audio-volume-low-symbolic
audio-volume-medium-symbolic
True
True
center
center
none
True
True
center
center
none
145
151
16
244
True
False
vertical
adjustment2
421
75
`
The text was updated successfully, but these errors were encountered:
-The switch button doesn't light up, in red, when it's in the “on” position, whereas it does with the equivalent C code.
-In fact, its behavior is random: under certain circumstances, it lights up, but this behavior cannot be linked to any event.
Thanks
mark
AMD Ryzen 7 1700 Eight-Core Processor. RAM 16MB. AB350M-Gaming 3-CF
Ubuntu 24.04.2
GNAT 13.3.0
gtkada_25.0.1_d3787772 installed by Alire.
`
-- glade_9.adb
-- units from Gtk
with Gtk.Main;
with Glib.Error; use Glib.Error;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Builder; use Gtk.Builder;
with Gtkada.Builder; use Gtkada.Builder;
-- Ada predefined units
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions;
-- Application specific units
with Window_Callbacks; use Window_Callbacks;
procedure Glade_9 is
Builder : Gtkada_Builder;
Error : aliased Glib.Error.GError;
FileName : constant String := "gtkada_issues";
GladeFileName : constant String := FileName & ".glade";
use type Glib.Guint;
begin
-- Appelé dans toutes les applications GtkAda.
-- Arguments ligne de commande sont analysés & retournés à l'application.
Gtk.Main.Init;
exception
when Error : others =>
Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (Error));
end Glade_9;
-- windows_callbacks.ads
with Gtkada.Builder; use Gtkada.Builder;
package Window_Callbacks is
function On_Delete_Event (Builder : access Gtkada_Builder_Record'Class) return Boolean;
procedure On_Destroy (Builder : access Gtkada_Builder_Record'Class);
--Autant de procedures que d'events
function On_Switch1_State_Set (Builder : access Gtkada_Builder_Record'Class) return boolean;
procedure On_Font1_Font_Set (Builder : access Gtkada_Builder_Record'Class);
procedure On_Volume1_Value_Changed (Builder : access Gtkada_Builder_Record'Class);
procedure On_Scroll1_Value_Changed (Builder : access Gtkada_Builder_Record'Class);
procedure On_Adjustment2 (Builder : access Gtkada_Builder_Record'Class);
end Window_Callbacks;
-- windows_callbacks.adb
-- units from GtkAda
with Gtk.Main;
-- units from GtkAda
with Gtk.Label; use Gtk.Label;
with Gtk.Switch; use Gtk.Switch;
with Gtk.Font_Button; use Gtk.Font_Button;
with Gtk.Scale_Button; use Gtk.Scale_Button;
with Gtk.GRange; use Gtk.GRange;
-- units from Glib
with Glib; use Glib;
with Glib.Object; use Glib.Object;
-- Ada predefined units
with Ada.Text_IO; use Ada.Text_IO;
package body Window_Callbacks is
-- On_Window1_Delete_Event
function On_Delete_Event
(Builder : access Gtkada_Builder_Record'Class) return Boolean is
pragma Unreferenced (Builder);
begin
put_line("Delete event");
return False;
end On_Delete_Event;
-- Callback to destroy a widget
procedure On_Destroy (Builder : access Gtkada_Builder_Record'Class) is
pragma Unreferenced (Builder);
begin
Put_Line ("quitting");
Gtk.Main.Main_Quit;
end On_Destroy;
-- On_Switch1_Activate
Function On_Switch1_State_Set (Builder : access Gtkada_Builder_Record'Class) return boolean is
begin
if Gtk_Switch (Get_Object (Builder, "switch1")).Get_Active then
-- Pas de contrôles des "fontes".
--Gtk.Label.Set_Text (Gtk_Label (Get_Object (Builder, "label1")), "Switch 1 Active");
-- On_Font_Font_Set
procedure On_Font1_Font_Set (Builder : access Gtkada_Builder_Record'Class) is
Button : access Gtk_Font_Button_Record;
begin
-- Get the font chooser button
Button := Gtk_Font_Button (Get_Object(Builder, "font1"));
declare
Font_Name : constant string := Get_Font (Button);
--Font_Name : constant string := Get_Font_Name (Button); --Deprecated since 3.22
--Font_Name : constant string := Get_Font (Button); --Ne marche pas (comme en C).
--Font_Name : constant string := Get_Font_Features (Button); --Ne marche pas
--Font_Size : constant Gint := Get_Font_Size (Button); --Ne marche pas.
begin
--Afficher l'entry du selecteur de fontes
Gtk.Label.Set_Text (Gtk_Label (Get_Object (Builder, "label2")), "Ne marche pas, ni en GtkAda, ni en C..");
Ada.Text_IO.Put_Line ("Font selected : " & Font_Name & " Ne marche pas, ni en GtkAda, ni en C..");
--Deprecated since: 3.22
--Use the GtkFontChooser::font property instead.
--Ada.Text_IO.Put_Line ("Size selected : " & GInt'Image (Font_Size));
end;
end On_Font1_Font_Set;
-- On_Volume_Value_Changed
procedure On_Volume1_Value_Changed (Builder : access Gtkada_Builder_Record'Class) is
Button : access Gtk_Scale_Button_Record;
begin
Button := Gtk_Scale_Button (Get_Object(Builder, "volume1"));
declare
-- Gtk.Scale_Button.Set_Value
-- can be used to set the volume control to a particular value.
Volume_Value : constant GDouble := (Gtk.Scale_Button.Get_Value (Button));
begin
Ada.Text_IO.Put_Line ("Volume scale : " & GDouble'Image (Volume_Value));
end;
end On_Volume1_Value_Changed;
-- On_Scroll_Value_Changed
procedure On_Scroll1_Value_Changed (Builder : access Gtkada_Builder_Record'Class) is --Ajout
Button : access Gtk_Range_Record;
begin
Button := Gtk_Range (Get_Object(Builder, "scroll1"));
declare
Range_Value : constant GDouble := (Gtk.GRange.Get_Value (Button));
Range_Value_Integer : constant integer := integer (Range_Value);
begin
Ada.Text_IO.Put_Line ("Scroll : " & integer'Image (Range_Value_Integer));
end;
end On_Scroll1_Value_Changed;
-- Attaché au scroll précédent (On_Scroll_Value_Changed)
procedure On_Adjustment2 (Builder : access Gtkada_Builder_Record'Class) is --Ajout
begin
null;
end On_Adjustment2;
end Window_Callbacks;
-- gtkada_issues.glade
1000 1 10 38 False 399 272 True False 205 True False I am a label hiding here. label 1 150 216 205 True False label2 150 238 False True True Switch! 10 126 141 51 True True True 2 1 Sans 12 140 114 True True False True none vertical audio-volume-muted-symbolic audio-volume-high-symbolic audio-volume-low-symbolic audio-volume-medium-symbolic True True center center none True True center center none 185 63 16 244 True False vertical adjustment2 321 15 ``/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+ Glade / Gtk Programming
#+
#+ Copyright (C) 2019 by Kevin C. O'Kane
#+
#+ Kevin C. O'Kane
#+ [email protected]
#+ https://www.cs.uni.edu/~okane
#+ http://threadsafebooks.com/
#+
#+ This program is free software; you can redistribute it and/or modify
#+ it under the terms of the GNU General Public License as published by
#+ the Free Software Foundation; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program is distributed in the hope that it will be useful,
#+ but WITHOUT ANY WARRANTY; without even the implied warranty of
#+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#+ GNU General Public License for more details.
#+
#+ You should have received a copy of the GNU General Public License
#+ along with this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <math.h>
#include <ctype.h>
// Make them global
GtkWidget *window;
GtkWidget *fixed1;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *switch1;
GtkWidget *font1;
GtkWidget *volume1;
GtkWidget *scroll1;
GtkBuilder *builder;
GtkAdjustment *adjustment2;
int main(int argc, char *argv[]) {
//---------------------------------------------------------------------
// establish contact with xml code used to adjust widget settings
//---------------------------------------------------------------------
// gtk_range_set_range (GTK_RANGE(scroll1), 0, 100);
void on_switch1_state_set (GtkSwitch s) {
gboolean T = gtk_switch_get_active(s);
if (T) gtk_label_set_text (GTK_LABEL(label1), (const gchar ) "Switch 1 Active");
else gtk_label_set_text (GTK_LABEL(label1), (const gchar* ) "Switch 1 Not Active");
}
void on_font1_font_set(GtkFontButton *f1) {
printf("font name = %s\n", gtk_font_button_get_font_name (f1) );
}
void on_volume1_value_changed (GtkVolumeButton *v1) {
void on_scroll1_value_changed(GtkRange *r) {
gdouble x = gtk_range_get_value (r);
printf("scroll = %d\n", (int) x );
}
/* glade_9-c.glade */
1000 1 10 False True False 205 True False I am a label hiding here. label 1 220 282 205 True False label2 220 306 True True Switch! 10 231 True True True Sans 12 115 197 True True False True vertical invalid adjustment2 audio-volume-muted-symbolic audio-volume-high-symbolic audio-volume-low-symbolic audio-volume-medium-symbolic True True center center none True True center center none 145 151 16 244 True False vertical adjustment2 421 75 `The text was updated successfully, but these errors were encountered: