Skip to content

Gtk.Font_Button widget doesn't work #66

@Hubilari

Description

@Hubilari

Hello,
the Gtk.Font_Button widget doesn't work. It does open the window for selecting a new font, but it has no effect.
The same applies to C.
-It seems that all widgets in this family have the same behavior.
Perhaps AdaCore can find a workaround?
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.

`
-- 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;

-- 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_font1_font_set",        On_Font1_Font_Set'Access);

-- Etape 3 : Do_Connect connecte tous les handlers enregistrés en une fois.
Do_Connect (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;
`

`
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);

procedure On_Font1_Font_Set (Builder : access Gtkada_Builder_Record'Class);

end Window_Callbacks;
`

`
-- units from GtkAda
with Gtk.Main;

-- units from GtkAda
with Gtk.Label; use Gtk.Label;
with Gtk.Font_Button; use Gtk.Font_Button;

-- 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_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;

end Window_Callbacks;
`

`

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 141 51 True True True 2 1 Sans 12 140 114 `

`/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+ Glade / Gtk Programming
#+
#+ Copyright (C) 2019 by Kevin C. O'Kane
#+
#+ Kevin C. O'Kane
#+ kc.okane@gmail.com
#+ 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 *font1;
GtkBuilder *builder;

int main(int argc, char *argv[]) {

gtk_init(&argc, &argv); // init Gtk

//---------------------------------------------------------------------
// establish contact with xml code used to adjust widget settings
//---------------------------------------------------------------------

builder = gtk_builder_new_from_file ("glade_9-c.glade");

window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));

g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_builder_connect_signals(builder, NULL);

fixed1  = GTK_WIDGET(gtk_builder_get_object(builder, "fixed1"));
label1  = GTK_WIDGET(gtk_builder_get_object(builder, "label1"));
label2  = GTK_WIDGET(gtk_builder_get_object(builder, "label2"));
font1   = GTK_WIDGET(gtk_builder_get_object(builder, "font1"));

/*******************
struct GtkAdjustment {
                gdouble lower,
                gdouble upper,
                gdouble step_increment,
                gdouble page_increment,
                gdouble page_size};
****************************/

/* alter the range of the scroll bar */

// gtk_range_set_range (GTK_RANGE(scroll1), 0, 100);

gtk_widget_show(window);

gtk_main();

return EXIT_SUCCESS;
}

void on_font1_font_set(GtkFontButton *f1) {
printf("font name = %s\n", gtk_font_button_get_font_name (f1) );
}
`

`

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 True Sans 12 115 197 `

Image
Image
Image
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions