Web lists-archives.com

Re: Font selection panel




Hi,
I looked more closely at the code you provided and here are some observations.

On Fri, Dec 23, 2016 at 2:23 PM,  <cecashon@xxxxxxx> wrote:
>
> Give it a try. For GTK2 you can change a few things around to get it to
> work.

Yes in your code I need to set button2 as disabled initially - call
gtk_widget_set_sensitive( button2, false ); when the program starts.
Then when the user changes the font in any way (i.e. (s)he presses
arrow key anywhere),
the button becomes enabled.

IIUC, in GTK3 it may be possible with
https://developer.gnome.org/gtk3/stable/GtkFontChooser.html#GtkFontChooser-font-activated
signal, but if I read the docs correctly there is no equivalent for GTK+2.

>
> Pass the selection or chooser with your apply button "clicked" signal and
> you can apply the changes.

Yes, this part I understand.

>
> I tried the following with Ubuntu 16.04 and GTK2.24.30 and it worked. Maybe
> get a start at setting something up. I would recommend GTK3 over GTK2 but if
> GTK2 is the needed library then program with it.
>
> I don't see a deprecated warning for gtk_font_selection_set_font_name() when
> I compile in GTK2.

That's weird - I definitely see the deprecation warning in the GTK+2 docs -
see https://developer.gnome.org/gtk2/stable/GtkFontSelection.html#gtk-font-selection-set-font-name
for the reference.

Thank you for the code and Happy New Year!!

>
>
> /*
>     gcc -Wall notebook2.c -o notebook2 `pkg-config --cflags --libs gtk+-2.0`
> */
>
> #include<gtk/gtk.h>
>
> static void click_button1(GtkWidget *widget, gpointer user_data)
>  {
>    g_print("Properties OK\n");
>  }
> static void click_button2(GtkWidget *widget, gpointer user_data)
>  {
>    gchar
> *selection=gtk_font_selection_get_font_name(GTK_FONT_SELECTION(user_data));
>    g_print("%s\n", selection);
>    g_free(selection);
>  }
> static void set_font(GtkWidget *widget, gpointer user_data)
>  {
>    gtk_font_selection_set_font_name(GTK_FONT_SELECTION(widget), "Monospace
> Bold 18");
>  }
> int main(int argc, char **argv)
>  {
>    gtk_init(&argc, &argv);
>    g_print("%d.%d.%d\n", gtk_major_version, gtk_minor_version,
> gtk_micro_version);
>
>    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
>    gtk_window_set_title(GTK_WINDOW(window), "Notebook Test2");
>    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
>    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
>    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
>
>    GtkWidget *label1=gtk_label_new("Some Properties");
>
>    GtkWidget *button1=gtk_button_new_with_label("Properties OK");
>    g_signal_connect(button1, "clicked", G_CALLBACK(click_button1), NULL);
>
>    GtkWidget *table1=gtk_table_new(2, 1, FALSE);
>    gtk_table_attach(GTK_TABLE(table1), label1, 0, 1, 0, 1, GTK_EXPAND,
> GTK_EXPAND, 0, 0);
>    gtk_table_attach(GTK_TABLE(table1), button1, 0, 1, 1, 2, GTK_EXPAND,
> GTK_SHRINK, 0, 0);
>
>    GtkWidget *font=gtk_font_selection_new();
>    g_signal_connect(font, "realize", G_CALLBACK(set_font), NULL);
>
>    GtkWidget *button2=gtk_button_new_with_label("Font OK");
>    g_signal_connect(button2, "clicked", G_CALLBACK(click_button2), font);
>
>    GtkWidget *table2=gtk_table_new(2, 1, FALSE);
>    gtk_table_attach(GTK_TABLE(table2), font, 0, 1, 0, 1, GTK_EXPAND,
> GTK_EXPAND, 0, 0);
>    gtk_table_attach(GTK_TABLE(table2), button2, 0, 1, 1, 2, GTK_EXPAND,
> GTK_SHRINK, 0, 0);
>
>    GtkWidget *notebook=gtk_notebook_new();
>    GtkWidget *notebook_label1=gtk_label_new("Properties");
>    GtkWidget *notebook_label2=gtk_label_new("Fonts");
>    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table1,
> notebook_label1);
>    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table2,
> notebook_label2);
>
>    gtk_container_add(GTK_CONTAINER(window), notebook);
>
>    gtk_widget_show_all(window);
>
>    gtk_main();
>    return 0;
>  }
>
>
>
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list