Is it possible to unwrap a PyGTK object?

111 Views Asked by At

I have a Gtk.Window object in Python. This object is essentially little more than a wrapper around a GtkWindow *. Is it possible, from C (with a PyObject *) or Python, to get at that GtkWindow *?

I have an app, written in Python, but some of the rendering code for a particular widget is just too slow. I attempted to isolate it in an alternate thread, but I think I'm getting bit by the GIL, because I'm attempting to have two threads do CPU work. (The background thread, with is nearly 100% CPU, is fighting too much time away from the UI thread when it needs it, causing it to be unresponsive.) It'd be simple enough to write the background worker in C, if I had the pointer.

1

There are 1 best solutions below

0
On

If you have a PyGObject it should go like this:

PyGObject *py_widget;
GtkWidget *widget;

if (!PyArg_ParseTuple(args, "O!", PyGObject_Type, &py_widget))
    return NULL;
widget = GTK_WIDGET(py_widget->obj);

(Taken from http://www.daa.com.au/pipermail/pygtk/2003-November/006292.html) Only I do not know how to convert a PyObject to PyGObject.