Re: [gtk-list] Accelerators again
- From: Ted Roth <troth netmagic net>
- To: GTK Liste <gtk-list redhat com>
- Subject: Re: [gtk-list] Accelerators again
- Date: Thu, 12 Aug 1999 08:59:10 -0700 (PDT)
On Thu, 12 Aug 1999, Nils Rennebarth wrote:
> Noone answered my question about accelerators yet, so here it is again:
>
> How do make pressing a certain key (on the keyboard) in my application
> to do the same as klicking a button?
>
> I.e.: there is a button:
>
> button=gtk_button_new_with_label("Quit");
> gtk_signal_connect(GTK_OBJECT(button), "clicked",
> GTK_SIGNAL_FUNC(delete), NULL);
>
> and I would like to make pressing "q" to do the same, that is to call the
> delete function.
>
> How do I do this?
>
Here's a function I wrote that does exactly what you want and will even
under line the acc-key for you.
Enjoy.
Ted Roth
/*
* An underscore '_' in label defines the accelerator key.
*/
void add_button( GtkWidget *box, GtkAccelGroup *ac_grp,
gchar *label, GtkSignalFunc signal,
gpointer data )
{
GtkWidget *button;
guint tmp_key;
button = gtk_button_new_with_label( "" );
tmp_key = gtk_label_parse_uline( GTK_LABEL(GTK_BIN(button)->child),
label );
gtk_signal_connect( GTK_OBJECT(button), "clicked", signal, data );
gtk_box_pack_start( GTK_BOX(box), button, TRUE, TRUE, 0 );
gtk_widget_add_accelerator( button, "clicked", ac_grp, tmp_key, 0,
GTK_ACCEL_VISIBLE | GTK_ACCEL_SIGNAL_VISIBLE );
gtk_widget_show( button );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]