|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Question aboutusing message dialog to ask confirmationI want to have a "do you really want to do this" type question and I'm
trying to use a message dialog thus: GtkWidget *dlg = gtk_message_dialog_new(GTK_WINDOW(previous), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure?"); g_signal_connect_swapped(dlg, "response", G_CALLBACK(gtk_widget_destroy), dlg); Then I put if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_YES) { /* Do the thing we asked about */ } else { /* Get out of here */ } the return value from gtk_dialog_run is never GTK_RESPONSE_YES, it's always zero whether the Yes or No button is clicked. However if I get rid of the "response" signal and put retval = gtk_dialog_run(GTK_DIALOG(dlg)); gtk_widget_destroy(dlg); if (retval == GTK_RESPONSE_YES) { /* Do stuff */ } else { /* Get out of here */ } It works OK. "Is this a bug or a feature"? John Collins Xi Software Ltd www.xisl.com _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: Question aboutusing message dialog to ask confirmationOn Fri, May 16, 2008 at 3:19 PM, John M Collins <jmc@...> wrote:
> I want to have a "do you really want to do this" type question and I'm > trying to use a message dialog thus: > > GtkWidget *dlg = gtk_message_dialog_new(GTK_WINDOW(previous), > GTK_DIALOG_DESTROY_WITH_PARENT, > GTK_MESSAGE_QUESTION, > GTK_BUTTONS_YES_NO, "Are you sure?"); > g_signal_connect_swapped(dlg, > "response", G_CALLBACK(gtk_widget_destroy), dlg); > > Then I put > > if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_YES) { > > /* Do the thing we asked about */ > } > else { > /* Get out of here */ > } > > > the return value from gtk_dialog_run is never GTK_RESPONSE_YES, it's > always zero whether the Yes or No button is clicked. > > However if I get rid of the "response" signal and put > > retval = gtk_dialog_run(GTK_DIALOG(dlg)); > gtk_widget_destroy(dlg); > > if (retval == GTK_RESPONSE_YES) { > > /* Do stuff */ > } > else { > /* Get out of here */ > } > > It works OK. > > "Is this a bug or a feature"? It is a feature, and of the kind that bears to similarity to a bug. You do not need to use gtk_signal_connect to connect to the "response" signal if you are using the standard interface: it is already connected. By connecting, you are probably destroying the dialog before the value can be read, and it is surprinsing that you do not get some random garbage. _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
|
|
Re: Question aboutusing message dialog to ask confirmationOn Fri, 16 May 2008 19:19:55 +0100 John M Collins wrote:
> I want to have a "do you really want to do this" type question and I'm > trying to use a message dialog thus: > > GtkWidget *dlg = gtk_message_dialog_new(GTK_WINDOW(previous), > GTK_DIALOG_DESTROY_WITH_PARENT, > GTK_MESSAGE_QUESTION, > GTK_BUTTONS_YES_NO, "Are you sure?"); > g_signal_connect_swapped(dlg, > "response", G_CALLBACK(gtk_widget_destroy), dlg); > > Then I put > > if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_YES) { > > /* Do the thing we asked about */ > } > else { > /* Get out of here */ > } > > > the return value from gtk_dialog_run is never GTK_RESPONSE_YES, it's > always zero whether the Yes or No button is clicked. gtk_dialog_run() also connects to the 'response' signal. You cannot rely on signal callbacks being called in any particular order. In your case, likely your handler (gtk_widget_destroy()) is getting called before gtk_dialog_run()'s response handler, so you destroy the widget before the gtk_dialog_run() response handler can run. -brian _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@... http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list |
| Free Forum Powered by Nabble | Forum Help |