hi, i created a selection-list that pops up when a user presses a button in the main window. Everything works fine until i try to destroy the selection-window after the user clicks an item from the list. If i do not try to destroy the window, the program does not crash, but the selection-window stays up and the user must force it closed from the window's tab [x]. i would like the selection-list to disappear automatically after the user picks an item, since many programs work this way.
I condensed an example in the following program: //--------------------------------------------------------------------------------- #include <gtk/gtk.h> GtkWidget *outer_window, *popupselector; int selected; void select_item( GtkWidget *wdg, gpointer data ) { GtkTreeIter iter; GtkTreeModel *model; char *text; if (gtk_tree_selection_get_selected( (GtkTreeSelection *)wdg, &model, &iter)) gtk_tree_model_get(model, &iter, 0, &text, -1); else return; printf("User selected '%s'.\n", text ); selected++; if (selected == 2) // Commenting out these two lines prevents gtk_widget_destroy( popupselector ); // program from crashing but selection-list stays up. } void select_button( GtkWidget *widget, gpointer data ) { GtkWidget *panel, *bpanel, *scroll_window, *tree; GtkTreeStore *list; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeSelection *select; GtkTreeIter iter; /* Create a window for the selection-list. */ popupselector = gtk_window_new( GTK_WINDOW_TOPLEVEL ); gtk_widget_set_size_request( popupselector, 200, 200 ); gtk_window_set_transient_for( GTK_WINDOW( popupselector ), GTK_WINDOW( outer_window ) ); gtk_window_set_position( GTK_WINDOW( popupselector ), GTK_WIN_POS_CENTER_ON_PARENT ); gtk_window_set_title( GTK_WINDOW( popupselector ), "Selection Items" ); panel = gtk_fixed_new(); gtk_container_add( GTK_CONTAINER( popupselector ), panel ); /* Add the list widget to the window. */ list = gtk_tree_store_new( 1, G_TYPE_STRING ); bpanel = gtk_fixed_new(); gtk_fixed_put( GTK_FIXED( panel ), bpanel, 2, 2 ); gtk_widget_set_size_request( bpanel, 150, 150 ); scroll_window = gtk_scrolled_window_new( NULL, NULL ); gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scroll_window ), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS ); gtk_widget_set_size_request( scroll_window, 150, 150 ); gtk_container_add( GTK_CONTAINER( bpanel ), scroll_window ); tree = gtk_tree_view_new_with_model( GTK_TREE_MODEL( list ) ); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes( "Selection Items", renderer, "text", 0, NULL ); gtk_tree_view_append_column( GTK_TREE_VIEW(tree), column ); gtk_container_add( GTK_CONTAINER( scroll_window ), tree ); select = gtk_tree_view_get_selection( GTK_TREE_VIEW(tree) ); gtk_tree_selection_set_mode( select, GTK_SELECTION_SINGLE ); g_signal_connect( G_OBJECT(select), "changed", G_CALLBACK( select_item), 0 ); gtk_tree_store_append( list, &iter, 0 ); /* Add item to the list. */ gtk_tree_store_set( list, &iter, 0, "Oranges", -1 ); gtk_tree_store_append( list, &iter, 0 ); /* Add item to the list. */ gtk_tree_store_set( list, &iter, 0, "Apples", -1 ); gtk_tree_store_append( list, &iter, 0 ); /* Add item to the list. */ gtk_tree_store_set( list, &iter, 0, "Pairs", -1 ); selected = 0; gtk_widget_show_all( popupselector ); } int main( int argc, char *argv[] ) { GtkWidget *panel, *bpanel, *button; gtk_init( &argc, &argv ); /* Create a window. */ outer_window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); gtk_widget_set_size_request( outer_window, 150, 150 ); gtk_window_set_title( GTK_WINDOW( outer_window ), "Test"); gtk_window_set_position( GTK_WINDOW( outer_window ), GTK_WIN_POS_CENTER ); panel = gtk_fixed_new(); gtk_container_add( GTK_CONTAINER( outer_window ), panel ); bpanel = gtk_fixed_new(); /* Add a button to bring up the selection-list window. */ gtk_fixed_put( GTK_FIXED( panel ), bpanel, 20, 20 ); button = gtk_button_new_with_label( "Select Items"); gtk_signal_connect( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC( select_button ), 0 ); gtk_container_add( GTK_CONTAINER( bpanel ), button ); gtk_widget_show_all( outer_window ); gtk_main(); return 0; } -------------------------------------- Note that I added the global counter "selected" so that the destroy is attempted on the second call to the callback, since it gets called once immediately when the list-window is created. The second call happens when the user actually picks an item. Without checking for the second call, the window gets destroyed before the user sees it. Interestingly the program does not crash when destroyed on the first call. When the destroy call is removed, the program does not crash, but the window stays up after picking an item. Any ideas on how to do this, or what is going wrong ? _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list