Re: key press events and gtk_dialog_new_with_buttons()



Yeti,
I tried your example and it worked fine. I then had a look at my code again and I found that the Enter key would emulate pressing the OK button on all of my entries BUT only the first time the window was displayed. If I hide the window using gtk_widget_hide_all() and then show it some time later using gtk_widget_show_all(), hitting the return key no longer causes the OK button to be 'pressed'. I have found that I need to call gtk_dialog_set_default_response() each time I show the window with gtk_widget_show_all() (not just the first time) then all is fine. Thanks for your help and patience - problem solved.

Richard.

At 21:29 11/01/06, you wrote:
On Wed, Jan 11, 2006 at 06:54:46PM +1100, Richard Gipps wrote:
> I applied this function to the three entries but it only works on one of
> them (the first entry I apply it to).  Note that I have tried them all on
> their own (by commenting out the other two) and they work fine.  Any ideas?

#include <gtk/gtk.h>

int
main(int argc, char *argv[])
{
    GtkWidget *dialog, *entry;
    gint response;

    gtk_init(&argc, &argv);
    dialog = gtk_dialog_new_with_buttons("Entry Activate", NULL, 0,
                                         GTK_STOCK_CANCEL,
                                         GTK_RESPONSE_CANCEL,
                                         GTK_STOCK_OK,
                                         GTK_RESPONSE_OK,
                                         NULL);
    gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);

    entry = gtk_entry_new();
    gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);

    entry = gtk_entry_new();
    gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);

    entry = gtk_entry_new();
    gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);

    gtk_widget_show_all(dialog);
    response = gtk_dialog_run(GTK_DIALOG(dialog));
    g_print("Response: %d\n", response);
    gtk_widget_destroy(dialog);

    return 0;
}

This works.

Yeti


--
That's enough.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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