diff options
| author | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2007-07-08 22:37:54 +0000 |
|---|---|---|
| committer | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2007-07-08 22:37:54 +0000 |
| commit | f1d87874f2479efa763ce31850d6aebba35981a9 (patch) | |
| tree | 00c91bed16c13c77570433a929005900ce0deb9c /gobject | |
| parent | 97d3f066bf84218e7bfb66a6a25d665c450e7f3d (diff) | |
| download | pygobject-f1d87874f2479efa763ce31850d6aebba35981a9.tar.gz pygobject-f1d87874f2479efa763ce31850d6aebba35981a9.tar.xz pygobject-f1d87874f2479efa763ce31850d6aebba35981a9.zip | |
Wrap g_timeout_add_seconds
svn path=/trunk/; revision=690
Diffstat (limited to 'gobject')
| -rw-r--r-- | gobject/gobjectmodule.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 48b2c24..4a78259 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -2038,6 +2038,47 @@ pyg_timeout_add(PyObject *self, PyObject *args, PyObject *kwargs) return PyInt_FromLong(handler_id); } + +static PyObject * +pyg_timeout_add_seconds(PyObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *first, *callback, *cbargs = NULL, *data; + gint len, priority = G_PRIORITY_DEFAULT; + guint interval, handler_id; + + len = PyTuple_Size(args); + if (len < 2) { + PyErr_SetString(PyExc_TypeError, + "timeout_add_seconds requires at least 2 args"); + return NULL; + } + first = PySequence_GetSlice(args, 0, 2); + if (!PyArg_ParseTuple(first, "IO:timeout_add_seconds", &interval, &callback)) { + Py_DECREF(first); + return NULL; + } + Py_DECREF(first); + if (!PyCallable_Check(callback)) { + PyErr_SetString(PyExc_TypeError, "second argument not callable"); + return NULL; + } + if (get_handler_priority(&priority, kwargs) < 0) + return NULL; + + cbargs = PySequence_GetSlice(args, 2, len); + if (cbargs == NULL) + return NULL; + + data = Py_BuildValue("(ON)", callback, cbargs); + if (data == NULL) + return NULL; + handler_id = g_timeout_add_seconds_full(priority, interval, + pyg_handler_marshal, data, + pyg_destroy_notify); + return PyInt_FromLong(handler_id); +} + + static gboolean iowatch_marshal(GIOChannel *source, GIOCondition condition, @@ -2815,6 +2856,8 @@ static PyMethodDef pygobject_functions[] = { (PyCFunction)pyg_idle_add, METH_VARARGS|METH_KEYWORDS }, { "timeout_add", (PyCFunction)pyg_timeout_add, METH_VARARGS|METH_KEYWORDS }, + { "timeout_add_seconds", + (PyCFunction)pyg_timeout_add_seconds, METH_VARARGS|METH_KEYWORDS }, { "io_add_watch", (PyCFunction)pyg_io_add_watch, METH_VARARGS|METH_KEYWORDS }, { "source_remove", |
