The gtk_timeout_add() function takes a third argument that is not
present in the python bindings.

I did have a go at adding it and have included the patch below if that
is of any use to anyone, it works for me.  I wouldn't be suprised if
there is a neater way of doing it as this is the first time that I have
looked at python extension code..

..Steve

--- gtk.py      1999/04/25 13:10:00     1.1
+++ gtk.py      1999/04/25 13:10:26
@@ -2451,8 +2451,8 @@
        _gtk.gtk_quit_add_destroy(mainlevel, object._o)
 def quit_remove(tag):
        _gtk.gtk_quit_remove(tag)
-def timeout_add(timeout, callback):
-       return _gtk.gtk_timeout_add(timeout, callback)
+def timeout_add(timeout, callback, arg=None):
+       return _gtk.gtk_timeout_add(timeout, callback, arg)
 def timeout_remove(tag):
        _gtk.gtk_timeout_remove(tag)
 
--- gtkmodule.c 1999/04/25 12:57:37     1.1
+++ gtkmodule.c 1999/04/25 14:02:04
@@ -2174,10 +2174,19 @@
  * It is collected here, so I don't accidentally reproduce it elsewhere in
  * pygtk. */
 
+typedef struct {
+  PyObject *func;
+  PyObject *data;
+} PyGtk_TimeoutArgs;
 /* destroy notify for PyObject */
 static void PyGtk_DestroyNotify(gpointer data) {
   Py_DECREF((PyObject *)data);
 }
+static void PyGtk_DestroyTimeout(gpointer data) {
+  Py_DECREF(((PyGtk_TimeoutArgs *)data)->func);
+  Py_DECREF(((PyGtk_TimeoutArgs *)data)->data);
+  g_free(data);
+}
 static void PyGtk_CallbackMarshal(GtkObject *o, gpointer d, guint nargs,
                                  GtkArg *args);
 static PyObject *GtkArgs_AsTuple(int nparams, GtkArg *args);
@@ -2915,6 +2924,30 @@
     *GTK_RETLOC_BOOL(args[0]) = TRUE;
   Py_DECREF(ret);
 }
+static void PyGtk_TimeoutMarshal(gpointer a, PyGtk_TimeoutArgs *targs,
+               int nargs, GtkArg *args) {
+  PyObject *ret;
+  PyObject *tuple;
+
+  tuple = Py_BuildValue("(O)", targs->data);
+  ret = PyObject_CallObject(targs->func, tuple);
+  Py_DECREF(tuple);
+  if (ret == NULL) {
+    if (PyGtk_FatalExceptions)
+      gtk_main_quit();
+    else {
+      PyErr_Print();
+      PyErr_Clear();
+    }
+    *GTK_RETLOC_BOOL(args[0]) = FALSE;
+    return;
+  }
+  if (ret == Py_None || (PyInt_Check(ret) && PyInt_AsLong(ret) == 0))
+    *GTK_RETLOC_BOOL(args[0]) = FALSE;
+  else
+    *GTK_RETLOC_BOOL(args[0]) = TRUE;
+  Py_DECREF(ret);
+}
 
 /* callback for input handlers */
 static void PyGtk_InputMarshal(gpointer a, PyObject *func, int nargs,
@@ -3244,16 +3277,22 @@
 _wrap_gtk_timeout_add(PyObject *self, PyObject *args) {
     guint32 interval;
     PyObject *callback;
-    if (!PyArg_ParseTuple(args, "iO:gtk_timeout_add", &interval, &callback))
+    PyObject *data;
+       PyGtk_TimeoutArgs *targs;
+    if (!PyArg_ParseTuple(args, "iOO:gtk_timeout_add", &interval, &callback, &data))
         return NULL;
     if (!PyCallable_Check(callback)) {
         PyErr_SetString(PyExc_TypeError, "second arg not callable");
         return NULL;
     }
     Py_INCREF(callback);
+    Py_INCREF(data);
+    targs = g_new(PyGtk_TimeoutArgs, 1);
+    targs->func = callback;
+    targs->data = data;
     return PyInt_FromLong(gtk_timeout_add_full(interval, NULL,
-        (GtkCallbackMarshal)PyGtk_HandlerMarshal, callback,
-        (GtkDestroyNotify)PyGtk_DestroyNotify));
+        (GtkCallbackMarshal)PyGtk_TimeoutMarshal, targs,
+        (GtkDestroyNotify)PyGtk_DestroyTimeout));
 }
 
 static PyObject *
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to