Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove GTK+ container children, repopulate it, then refresh

I'm into a problem with a GTK+ C application. I have a container that, when starting the application, contains a button. During the running an user interation must cause this widget to contain more of them.
I need to write a function that removes all the "old" inner buttons, then adds all the ones from a list and finally refresh the view. This is what I'm writing but some parts are missing (TODOs)

void refresh_sequence_panel() 
{
    GSList* iterator = NULL;
    GtkWidget* button;

    // TODO: Here the container must be empty

    // Now add all the buttons
    for (iterator = steps; iterator; iterator = iterator->next) {
       button = gtk_button_new_from_stock(GTK_STOCK_ADD);
       gtk_widget_set_size_request(button, SEQ_BUTTON_W, SEQ_BUTTON_H);
       gtk_box_pack_start(GTK_BOX(sequence_panel), button, FALSE, FALSE, 5);
       handler_id = g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(seq_popup), GTK_BOX(sequence_panel));
    }

    // TODO: Now refresh the view, so I can see the changes...
}

Hope that someone can help, thanks!

like image 319
TheUnexpected Avatar asked Feb 08 '12 11:02

TheUnexpected


1 Answers

One-liner:

gtk_container_foreach (GTK_CONTAINER (container), (void*) gtk_widget_destroy, NULL);
like image 64
GingerPlusPlus Avatar answered Sep 21 '22 05:09

GingerPlusPlus