Re: Dialog closing prematurely with response code of 0
- From: David Nečas (Yeti) <yeti physics muni cz>
- To: gtk-app-devel-list gnome org
- Subject: Re: Dialog closing prematurely with response code of 0
- Date: Fri, 23 Mar 2007 00:12:01 +0100
On Thu, Mar 22, 2007 at 09:20:47AM -0400, Kevin Lambert wrote:
I have a button in DispenserLoadDialog that launches DispenserLoadingDialog
without emitting a return value for DispenserLoadDialog. The response value
from DispenserLoadingDialog is only supposed to be caught by the buttons
code and shouldn't be causing gtk_dialog_run() in DispenserLoadDialog to
return with an invalid response.
DispenserLoadDialog->gtk_dialog_run() started with the DispenserLoadDialog
dialog pointer passed in
Load Button pushed which causes load_button_clicked to be executed
load_button_clicked() launches DispenserLoadingDialog()
DispenserLoadingDialog->gtk_dialog_run() started with the
DispenserLoadingDialog dialog pointer passed in
Ok button in DispenserLoadingDialog pressed which causes
ok_button_clicked to be executed
ok_button_clicked() calls gtk_dialog_response() with GTK_RESPONSE_OK
and the DispenserLoadingDialog pointer as the first parameter
load_button_clicked() finishes executing WITHOUT calling
DispenserLoadDialog->gtk_dialog_run() returns with a response code of 0
(which is invalid as far as the documenation is concerned).
So it is something like this:
=======================================================================
#include <gtk/gtk.h>
static void
next_dialog(GtkWidget *button,
gpointer user_data)
{
GtkWindow *parent = NULL;
GtkWidget *dialog, *label;
gint response, level;
gchar *s;
if (button)
parent = GTK_WINDOW(gtk_widget_get_toplevel(button));
level = GPOINTER_TO_INT(user_data);
level++;
s = g_strdup_printf("Dialog %d", level);
dialog = gtk_dialog_new_with_buttons(s, parent, GTK_DIALOG_MODAL,
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);
g_free(s);
s = g_strdup_printf("This is dialog level %d", level);
label = gtk_label_new(s);
gtk_misc_set_padding(GTK_MISC(label), 12, 12);
g_free(s);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
button = gtk_button_new_with_mnemonic("_Destroy Me");
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), button);
g_signal_connect_swapped(button, "clicked",
G_CALLBACK(gtk_widget_destroy), dialog);
button = gtk_button_new_with_mnemonic("_Go Deeper");
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), button);
g_signal_connect(button, "clicked",
G_CALLBACK(next_dialog), GINT_TO_POINTER(level));
gtk_widget_show_all(dialog);
gtk_window_present(GTK_WINDOW(dialog));
response = gtk_dialog_run(GTK_DIALOG(dialog));
g_printerr("level: %d, response: %d\n", level, response);
if (response != GTK_RESPONSE_NONE)
gtk_widget_destroy(dialog);
}
int
main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
next_dialog(NULL, NULL);
return 0;
}
=======================================================================
Except that this program of course works.
The variable that holds the response id is initialized to
GTK_RESPONSE_NONE == -1, so whatever happens, you should not
get 0 from gtk_dialog_run() unless
- something sets it to 0 (note GtkDialog does not prevent you
from using zero response id)
- memory is corrupted
In either case I would assume it is not GtkDialog what
somehow breaks out of the inner main loop by force and/or sets
the response id to 0. You cannot expect much from reporting
it to bugzilla either if you don't show how to reproduce the
problem with GtkDialog.
Yeti
--
http://gwyddion.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]