A simple choice dialog won't work...
I wanted to pop up two buttons for the user to choose between two options (primary and secondary), returning true or false depending which was chosen. I tried this gboolean choose_option (gchar *title, gchar * primary, gchar * secondary) { GtkWidget *dialog; dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (Denemo.window), (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), primary, GTK_RESPONSE_ACCEPT, secondary,GTK_RESPONSE_REJECT, NULL); g_signal_connect_swapped (dialog, response, G_CALLBACK (gtk_widget_destroy), dialog); return (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT); } but it seems to return 0 for both button presses. What am I doing wrong? I'm using GTK3 on a Debian stable installation. Richard ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: A simple choice dialog won't work...
On Thu, 2015-05-07 at 13:02 +0100, Richard Shann wrote: From https://developer.gnome.org/gtk3/stable/GtkDialog.html GTK_RESPONSE_REJECT Generic response id, not used by GTK+ dialogs GTK_RESPONSE_ACCEPT Generic response id, not used by GTK+ dialogs Maybe try GTK_RESPONSE_OK and GTK_RESPONSE_CANCEL If that does not help, I may test your code next weekend --guess I have to add a few lines to get a working example. I wanted to pop up two buttons for the user to choose between two options (primary and secondary), returning true or false depending which was chosen. I tried this gboolean choose_option (gchar *title, gchar * primary, gchar * secondary) { GtkWidget *dialog; dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (Denemo.window), (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), primary, GTK_RESPONSE_ACCEPT, secondary,GTK_RESPONSE_REJECT, NULL); g_signal_connect_swapped (dialog, response, G_CALLBACK (gtk_widget_destroy), dialog); return (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT); } but it seems to return 0 for both button presses. What am I doing wrong? I'm using GTK3 on a Debian stable installation. Richard ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: A simple choice dialog won't work...
On Thu, 2015-05-07 at 16:02 +0100, Richard Shann wrote: After experimenting with a different bit of code, I think I've found the cause of the problem: doing the widget destroy by responding to the response signal seems to be ruining the return value. That is interesting. Indeed I had a feeling in that direction -- but not an exact idea what may went wrong. Unfortunately testing that takes a few minutes of time, and I am not really experienced with plain C code, I generally use Ruby or Nim. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: A simple choice dialog won't work...
On Thu, 2015-05-07 at 16:21 +0200, Stefan Salewski wrote: On Thu, 2015-05-07 at 13:02 +0100, Richard Shann wrote: From https://developer.gnome.org/gtk3/stable/GtkDialog.html GTK_RESPONSE_REJECT Generic response id, not used by GTK+ dialogs GTK_RESPONSE_ACCEPT Generic response id, not used by GTK+ dialogs Maybe try GTK_RESPONSE_OK and GTK_RESPONSE_CANCEL Hmm, I wonder what that means - Generic response id ... I understood that the idea of the pairs in the trailing arguments of gtk_dialog_new_with_buttons () was that the button with the given text would return the paired response id. I tried the ones you suggested, and also two positive values with the same result. After experimenting with a different bit of code, I think I've found the cause of the problem: doing the widget destroy by responding to the response signal seems to be ruining the return value. So, I seem to be back on track - the code that works is below. Thank you for your prompt response! Richard gboolean choose_option (gchar *title, gchar * primary, gchar * secondary) { GtkWidget *dialog; gboolean r; dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (Denemo.window), (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), primary, GTK_RESPONSE_ACCEPT, secondary, GTK_RESPONSE_REJECT, NULL); //g_signal_connect_swapped (dialog, response, G_CALLBACK (gtk_widget_destroy), dialog); r = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT); gtk_widget_destroy (dialog); return r; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list