Remove non-GtkListBoxRow parent from GtkListBox
Question: Just a quick note about something I have encountered recently. I used python,
but I guess, it applies for other languages as well.

    
    
    from gi.repository import Gtk
    
    win = Gtk.Window()
    listbox = Gtk.ListBox()
    somewidget = Gtk.Somewidget()
    win.add(listbox)
    
    listbox.insert(somewidget -1)
    listbox.remove(somewidget)  #ERROR
    

This is a GtkListBox, filled with an item not of type GtkListBoxRow. When
attempting to remove it from the GtkListBox, it gives me the following:

    
    
    Gtk-CRITICAL **: gtk_container_remove: assertion 'gtk_widget_get_parent (widget) == GTK_WIDGET (container) || GTK_IS_ASSISTANT (container) || GTK_IS_ACTION_BAR (container) || GTK_IS_POPOVER_MENU (container)' failed
    


Answer: The problem is, that GtkListBox must only have children of type GtkListBoxRow.
(see [GTK
doc](https://developer.gnome.org/gtk3/stable/GtkListBox.html#GtkListBoxRow))
So, when trying to insert another widget, there is automatically added a
GtkListBoxRow widget inbetween:

    
    
    +-----------------------------------+
    |                                   |
    | GtkListBox                        |
    |  +                                |
    |  +---> GtkListBoxRow (auto-added) |
    |         +                         |
    |         +---> Gtksomewidget       |
    |                                   |
    +-----------------------------------+
    

Gtk will fail if you try to remove your own widget, because it wants the
direct children of your ListBox. So instead of using

    
    
    listbox.remove(somewidget)
    

type

    
    
    listbox.remove(somewidget.get_parent())
    

