Daniel Trebbien
Daniel Trebbien

Reputation: 39208

How to call gtk_container_remove() on a Gtk.Container in PyGObject?

In a PyGObject project, I am trying to remove a widget from a GtkStatusbar using the gobject-introspection binding of gtk_container_remove ().

Normally when working with the GObject Introspection Python bindings, the method name is the same as the C function name, minus the "type prefix" and taking one less explicit argument. For example, I call gtk_box_pack_end () to add the widget that I later want to remove:

statusbar.pack_end(widget, False, True, 0)

When I try to remove the widget via statusbar.remove(widget), I see:

...
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
TypeError: remove() takes exactly 3 arguments (2 given)

One of the arguments is the implicit self and the other two arguments are apparently supposed to be numbers.

Here is the method's GIR:

<method name="remove" c:identifier="gtk_container_remove">
  <return-value transfer-ownership="none">
    <type name="none" c:type="void"/>
  </return-value>
  <parameters>
    <parameter name="widget" transfer-ownership="none">
      <type name="Widget" c:type="GtkWidget*"/>
    </parameter>
  </parameters>
</method>

How do I call the gtk_container_remove () function in PyGObject?

Upvotes: 1

Views: 647

Answers (1)

mg.
mg.

Reputation: 8012

Gtk.Statusbar override the remove function with another one with a different signature. You could try to destroy the widget, the container, the statusbar, will be notified and it will remove the widget, hoping you don't need it anymore.

Otherwise you could try: Gtk.Container.remove(statusbar, widget).

Upvotes: 2

Related Questions