summaryrefslogtreecommitdiff
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
parent4bea3e15b5aa3aaf42986c9e8fd50d4850f50a59 (diff)
downloadpygobject-7213af80481a6bc12588a5e74944b5c47ec30df4.tar.gz
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
-rw-r--r--ChangeLog10
-rw-r--r--examples/gio/directory-async.py12
-rw-r--r--gio/gfileenumerator.override84
-rw-r--r--gio/gio.defs23
-rw-r--r--tests/test_gio.py17
5 files changed, 143 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e1ca8b2d..2cc324d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,16 @@
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.
+
+2008-07-19 Johan Dahlin <johan@gnome.org>
+
+ * examples/gio/directory-async.py:
Only fetch name, saves a couple of syscalls.
* gio/gio.override:
Set name to gio._gio so pychecker/pydoc works.
diff --git a/examples/gio/directory-async.py b/examples/gio/directory-async.py
index eaec2a85..439e62e4 100644
--- a/examples/gio/directory-async.py
+++ b/examples/gio/directory-async.py
@@ -1,13 +1,19 @@
import gobject
import gio
-def callback(gfile, result):
- for file_info in gfile.enumerate_children_finish(result):
+def next_files_done(enumerator, result):
+ print 'done!'
+ for file_info in enumerator.next_files_finish(result):
print file_info.get_name()
loop.quit()
+def enumerate_children_done(gfile, result):
+ enumerator = gfile.enumerate_children_finish(result)
+ enumerator.next_files_async(10, next_files_done)
+
gfile = gio.File("/")
-gfile.enumerate_children_async("standard::name", callback)
+gfile.enumerate_children_async(
+ "standard::name", enumerate_children_done)
loop = gobject.MainLoop()
loop.run()
diff --git a/gio/gfileenumerator.override b/gio/gfileenumerator.override
index db208936..06c7f549 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 25b8aa90..e02fc9dd 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*")
diff --git a/tests/test_gio.py b/tests/test_gio.py
index df82e36f..00ccb5af 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -119,6 +119,23 @@ class TestGFileEnumerator(unittest.TestCase):
loop = gobject.MainLoop()
loop.run()
+ def testNextFilesAsync(self):
+ def callback(enumerator, result):
+ try:
+ for file_info in enumerator.next_files_finish(result):
+ if file_info.get_name() == 'test_gio.py':
+ break
+ else:
+ raise AssertionError
+ finally:
+ loop.quit()
+
+ enumerator = self.file.enumerate_children(
+ "standard::*", gio.FILE_QUERY_INFO_NOFOLLOW_SYMLINKS)
+ enumerator.next_files_async(1000, callback)
+ loop = gobject.MainLoop()
+ loop.run()
+
class TestInputStream(unittest.TestCase):
def setUp(self):