Re: Bizarre window behavior
- From: Jeff Shipman <shippy nmt edu>
- To: GTK List <gtk-list gnome org>
- Subject: Re: Bizarre window behavior
- Date: Tue, 13 Feb 2001 17:08:59 -0700 (MST)
Well, I finally had a chance today to whip up an
example piece of code so attached is sample code
that reproduces the error. After clicking on the
popup dialog, it should popup the dialog, print
the things instructed, and then close, but instead
it hangs until the button that originally opened
the dialog is clicked, which in turn causes the
things to print again.
Jeff "Shippy" Shipman E-Mail: shippy nmt edu
Computer Science Major ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy
On Tue, 13 Feb 2001, Jeff Shipman wrote:
> I've got a button that causes a window to
> popup. The "show" signal of that window is
> hooked up to a callback that does a g_list_foreach()
> and then hides the window. However, when it
> goes to hide the dialog box, it hangs (just the
> window, not the whole GUI), as in, I can't cause
> the delete_event to kick in...it won't close unless
> I click the button again (which is only hooked
> up to make the window appear, not disappear), but
> it also re-runs the g_list_foreach(). I hope I'm
> explaining this well, but it is rather odd behavior.
> I've tried stopping the "show" signal and blocking
> the "show" handler before calling gtk_widget_hide_all()
> on the window, but I still get left with a blank box
> until I click on the button again.
>
> Any help would be greatly appreciated.
>
> Jeff "Shippy" Shipman E-Mail: shippy nmt edu
> Computer Science Major ICQ: 1786493
> New Mexico Institute of Mining and Technology
> Homepage: http://www.nmt.edu/~shippy
>
>
#include <stdio.h>
#include <gtk/gtk.h>
GList *list = NULL;
GtkWidget *dlg;
void init_glist()
{
gint i;
gchar *text;
for(i=0;i<5;i++)
{
text = g_strdup_printf("Hi, this is number %d!", i);
list = g_list_append(list, (gpointer)text);
}
}
void do_thing(gpointer data, gpointer user_data)
{
gchar *text = (gchar *)data;
printf("%s\n", text);
}
void dialog_shown(GtkWidget *widget, gpointer data)
{
g_list_foreach(list, do_thing, NULL);
printf("\n");
gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "show");
gtk_widget_hide(widget);
}
void init_dialog()
{
GtkWidget *tmp, *vbox, *hbox, *pbar;
dlg = gtk_window_new(GTK_WINDOW_DIALOG);
gtk_signal_connect_object(GTK_OBJECT(dlg), "delete_event",
GTK_SIGNAL_FUNC(gtk_widget_hide),
GTK_OBJECT(dlg));
gtk_window_set_title(GTK_WINDOW(dlg), "Doing some stuff...");
gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
gtk_container_add(GTK_CONTAINER(dlg), vbox);
tmp = gtk_label_new("This program is doing some stuff...");
gtk_misc_set_alignment(GTK_MISC(tmp), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), tmp, FALSE, FALSE, 0);
gtk_widget_show(tmp);
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
tmp = gtk_label_new("Progress: ");
gtk_box_pack_start(GTK_BOX(hbox), tmp, FALSE, FALSE, 0);
gtk_widget_show(tmp);
pbar = gtk_progress_bar_new();
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pbar), GTK_PROGRESS_LEFT_TO_RIGHT);
gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(pbar), GTK_PROGRESS_CONTINUOUS);
gtk_progress_set_format_string(GTK_PROGRESS(pbar), "%p%%");
gtk_progress_set_show_text(GTK_PROGRESS(pbar), TRUE);
gtk_box_pack_start(GTK_BOX(hbox), pbar, TRUE, TRUE, 0);
gtk_object_set_data(GTK_OBJECT(dlg), "pbar", pbar);
gtk_widget_show(pbar);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show(hbox);
gtk_signal_connect(GTK_OBJECT(dlg), "show",
GTK_SIGNAL_FUNC(dialog_shown), NULL);
gtk_widget_show(vbox);
}
void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char **argv)
{
GtkWidget *main_win, *box, *button;
gtk_init(&argc, &argv);
init_glist();
init_dialog();
main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(main_win), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(main_win), "gtk_test");
gtk_signal_connect(GTK_OBJECT(main_win), "destroy",
GTK_SIGNAL_FUNC(destroy), NULL);
gtk_signal_connect(GTK_OBJECT(main_win), "delete_event",
GTK_SIGNAL_FUNC(destroy), NULL);
gtk_window_set_policy(GTK_WINDOW(main_win), FALSE, TRUE, TRUE);
gtk_widget_realize(main_win);
box = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(main_win), box);
button = gtk_button_new_with_label("Popup Dialog");
gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_show),
GTK_OBJECT(dlg));
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
gtk_widget_show(button);
gtk_widget_show(box);
gtk_widget_show(main_win);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]