Hi,
I'm actually developing an application standing at Gtk having two parts - Ansi C and Python.
The problem I met is how to get a C pointer of Gtk object relating to Python pyGtk object and vice versa.
Example:
Python:
button = gtk.Button()
C:
gtk_widget_destroy(button)
I've found some solution speaking about "_o" field of pyGtk object. However my object doesn't seem to have such pointer. Also, the descriptions speak about gtk.GtkButton instead of gtk.Button.
Is it version mismatch? I'm using pygtk-2.0 and python 2.2.x
So, is there a way to get pointer to wrapped pygtk object? Is there a way to create pygtk wrapper to already existing gtk object?
Others have already pointed out the difference between pygtk-0.6 and 2.0, and that you are reading some outdate documentation. The following is how to do it for pygtk-2.0. I'm assume that you already know how to write a python extension in C.
- Make your foomodule.c look like this:
#include <pygobject.h>
#include <pygtk.h>
/* global variable declared at top of file */
static PyTypeObject *PyGObject_Type=NULL;
/* ... */
void initfoo(void)
{
PyObject *module;
Py_InitModule("foo", foo_functions); init_pygobject();
init_pygtk();
module = PyImport_ImportModule("gobject");
if (module) {
PyGObject_Type =
(PyTypeObject*)PyObject_GetAttrString(module, "GObject");
Py_DECREF(module);
}
}- To create a python gtk widget from a C gtk widget:
pygobject_new((GObject*) widget);
If a python wrapper for 'widget' already exists, it will incref and
return that, other wise it will create a new python wrapper object.- To get a pointer to the underlying C widget from a Python widget that was passed as an argument, do something like this:
PyGObject *py_widget;
GtkWidget *widget; if (!PyArg_ParseTuple(args, "O!", PyGObject_Type, &py_widget))
return NULL;
widget = GTK_WIDGET(py_widget->obj);You might also want to look at the 'codegen' stuff that pygtk uses to automatically generate most of the pygtk interface. Once you get used to using it, it's much easier to use than writing everything by hand.
-- Tim Evans Applied Research Associates NZ http://www.aranz.com/
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
