summaryrefslogtreecommitdiffstats
path: root/gio
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-07-18 22:38:29 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-07-18 22:38:29 +0000
commit7213af80481a6bc12588a5e74944b5c47ec30df4 (patch)
treefaec25fa19bfb68b1b2e811af1bdb204bc6686f8 /gio
parent4bea3e15b5aa3aaf42986c9e8fd50d4850f50a59 (diff)
Wrap gio.FileEnumerator.next_files_async/next_files_done. Update the
2008-07-19 Johan Dahlin <johan@gnome.org> * examples/gio/directory-async.py: * gio/gfileenumerator.override: * gio/gio.defs: * tests/test_gio.py: Wrap gio.FileEnumerator.next_files_async/next_files_done. Update the example to use them instead of the synchronous versions, add documentation and tests. svn path=/trunk/; revision=832
Diffstat (limited to 'gio')
-rw-r--r--gio/gfileenumerator.override84
-rw-r--r--gio/gio.defs23
2 files changed, 107 insertions, 0 deletions
diff --git a/gio/gfileenumerator.override b/gio/gfileenumerator.override
index db20893..06c7f54 100644
--- a/gio/gfileenumerator.override
+++ b/gio/gfileenumerator.override
@@ -54,3 +54,87 @@ _wrap_g_file_enumerator_tp_iternext(PyGObject *iter)
return pygobject_new((GObject*)file_info);
}
+%%
+override g_file_enumerator_next_files_async kwargs
+static PyObject *
+_wrap_g_file_enumerator_next_files_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "num_files", "callback",
+ "io_priority", "cancellable", "user_data", NULL };
+ PyGAsyncRequestNotify *notify;
+ int num_files;
+ int io_priority = G_PRIORITY_DEFAULT;
+ GCancellable *cancellable = NULL;
+ PyGObject *py_cancellable = NULL;
+
+ notify = g_slice_new0(PyGAsyncRequestNotify);
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "iO|iOO:GFileEnumerator.enumerate_children_async",
+ kwlist,
+ &num_files,
+ &notify->callback,
+ &io_priority,
+ &py_cancellable,
+ &notify->data))
+ {
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+
+ if (!PyCallable_Check(notify->callback))
+ {
+ PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+ g_slice_free(PyGAsyncRequestNotify, notify);
+ return NULL;
+ }
+ Py_INCREF(notify->callback);
+ Py_XINCREF(notify->data);
+
+ if (!pygio_check_cancellable(py_cancellable, &cancellable))
+ return NULL;
+
+ g_file_enumerator_next_files_async(G_FILE_ENUMERATOR(self->obj),
+ num_files,
+ io_priority,
+ (GCancellable *) cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+%%
+override g_file_enumerator_next_files_finish kwargs
+static PyObject *
+_wrap_g_file_enumerator_next_files_finish(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "result", NULL };
+ PyGObject *result;
+ GList *next_files, *l;
+ GError *error = NULL;
+ PyObject *ret;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O!:GFileEnumerator.next_files_finish",
+ kwlist,
+ &PyGAsyncResult_Type, &result))
+ return NULL;
+
+ next_files = g_file_enumerator_next_files_finish(G_FILE_ENUMERATOR(self->obj),
+ G_ASYNC_RESULT(result->obj),
+ &error);
+ if (pyg_error_check(&error))
+ return NULL;
+
+ ret = PyList_New(0);
+ for (l = next_files; l; l = l->next) {
+ GFileInfo *file_info = l->data;
+ PyObject *item = pygobject_new((GObject *)file_info);
+ PyList_Append(ret, item);
+ Py_DECREF(item);
+ }
+ g_list_free(next_files);
+
+ return ret;
+}
diff --git a/gio/gio.defs b/gio/gio.defs
index 25b8aa9..e02fc9d 100644
--- a/gio/gio.defs
+++ b/gio/gio.defs
@@ -1021,6 +1021,25 @@
)
(define-method next_files_async
+ (docstring
+"FE.next_files_async(num_files, callback, [io_priority, cancellable, user_data])\n"
+"Request information for a number of files from the enumerator asynchronously.\n"
+"When all i/o for the operation is finished the callback will be called with\n"
+"the requested information.\n"
+"\n"
+"he callback can be called with less than num_files files in case of error\n"
+"or at the end of the enumerator. In case of a partial error the callback\n"
+"will be called with any succeeding items and no error, and on the next\n"
+"request the error will be reported. If a request is cancelled the callback\n"
+"will be called with gio.ERROR_CANCELLED.\n"
+"\n"
+"During an async request no other sync and async calls are allowed, and will\n"
+"result in gio.ERROR_PENDING errors.\n"
+"\n"
+"Any outstanding i/o request with higher priority (lower numerical value)\n"
+"will be executed before an outstanding request with lower priority.\n"
+"Default priority is gobject.PRIORITY_DEFAULT.")
+
(of-object "GFileEnumerator")
(c-name "g_file_enumerator_next_files_async")
(return-type "none")
@@ -1034,6 +1053,10 @@
)
(define-method next_files_finish
+ (docstring
+"FE.next_files_finish(result) -> a list of gio.FileInfos\n"
+"Finishes the asynchronous operation started with\n"
+"gio.FileEnumerator.next_files_async().")
(of-object "GFileEnumerator")
(c-name "g_file_enumerator_next_files_finish")
(return-type "GList*")