Re: On key pulsation, again

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Gasa Castell wrote:
Thanks a lot for interest... but, you attached me an example which use an other technique (the other): mnemonics. In fact, I'd like to understand the use of accelerators (like gtk_widget_add_accelerator()) for clicking buttons.
I've missed your previous post, sorry. Here's a new sample.
-- sample
#include <gtk/gtk.h>

static void
clicked(GtkButton *button, gint n)
{
        g_print("button %d was clicked\n", n);
}

int
main(int argc, char **argv)
{
        GtkWidget *window;
        GtkWidget *table;
        GtkWidget *button;
        GtkAccelGroup *accel_group;
        gint    i;
        gchar   *s;

        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width(GTK_CONTAINER(window), 4);
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), 0);

        accel_group = gtk_accel_group_new();
        gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);

        table = gtk_table_new(TRUE, 2,2);
        gtk_container_add(GTK_CONTAINER(window), table);

        for (i=0; i<4; i++) {
                s = g_strdup_printf("Press '%d'", i+1);
                button = gtk_button_new_with_label(s);
                g_free(s);
                gtk_widget_add_accelerator(
                        button,
                        "clicked",
                        accel_group,
                        '1'+i, 0,
                        0
                );
g_signal_connect(button, "clicked", G_CALLBACK(clicked), (gpointer)(i+1));
                gtk_table_attach(
                        GTK_TABLE(table),
                        button,
                        i%2,i%2+1, i/2,i/2+1,
                        GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND,
                        0, 0
                );
        }

        gtk_widget_show_all(window);

        gtk_main();

        return 0;
}
sample --

Is it OK ?

	Olexiy
_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux