In your python module, put this close to the top:

typedef struct {
  PyObject_HEAD
  GdkWindow *obj;
} PyGdkWindow_Object;
static PyTypeObject *PyGdkWindow_Type;
#define PyGdkWindow_Check(op) ((op)->ob_type == PyGdkWindow_Type)
#define PyGdkWindow_Get(op) (((PyGdkWindow_Object *)(op))->obj)

Now in your init function for the module, add code like this:

m = PyImport_ImportModule("_gtk");
d = PyModule_GetDict(m);
Py_DECREF(m);
PyGdkWindow_Type = (PyTypeObject *)PyDict_GetItemString(d,"GdkWindowType");
Py_INCREF(PyGdkWindow_Type);

Now in your functions, put something like this:
  PyObject *py_win;
  GdkWindow *win;
  if (!PyArg_ParseTuple(args, "O!:some-func", PyGdkWindow_Type, &py_win))
    return NULL;
  win = PyGdkWindow_Get(py_win);

And that should do it.  Now you know that you are getting a GdkWindow
passed to you, which you wouldn't know if it was passed as a CObject.

James Henstridge.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/


On 5 Mar 1999, Ture [iso-8859-1] P�lsson wrote:

> James Henstridge <[EMAIL PROTECTED]> writes:
> 
> > If you look at the code in _gdkimlibmodule.c or _gnomeuimodule.c, you will
> > see how I have been passing pointers to the different PyTypeObject's
> > defined in _gtkmodule.c.  That is probably the best way to go.  It only
> > requires a bit of code in the init routine, and you get a bit more type
> > safety than you would using PyCObject's.
> 
> I still can't see any obvious way of getting hold of, for example, a
> GdkWindow* given a widget passed in from some Python code. What is it
> that I'm not seeing? :-)
> 
>   -- Ture
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
> 

To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to