pygobject r832 - in trunk: . examples/gio gio tests
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: pygobject r832 - in trunk: . examples/gio gio tests
- Date: Fri, 18 Jul 2008 22:38:29 +0000 (UTC)
Author: johan
Date: Fri Jul 18 22:38:29 2008
New Revision: 832
URL: http://svn.gnome.org/viewvc/pygobject?rev=832&view=rev
Log:
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.
Modified:
trunk/ChangeLog
trunk/examples/gio/directory-async.py
trunk/gio/gfileenumerator.override
trunk/gio/gio.defs
trunk/tests/test_gio.py
Modified: trunk/examples/gio/directory-async.py
==============================================================================
--- trunk/examples/gio/directory-async.py (original)
+++ trunk/examples/gio/directory-async.py Fri Jul 18 22:38:29 2008
@@ -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()
Modified: trunk/gio/gfileenumerator.override
==============================================================================
--- trunk/gio/gfileenumerator.override (original)
+++ trunk/gio/gfileenumerator.override Fri Jul 18 22:38:29 2008
@@ -54,3 +54,87 @@
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,
+ ¬ify->callback,
+ &io_priority,
+ &py_cancellable,
+ ¬ify->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;
+}
Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs (original)
+++ trunk/gio/gio.defs Fri Jul 18 22:38:29 2008
@@ -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*")
Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py (original)
+++ trunk/tests/test_gio.py Fri Jul 18 22:38:29 2008
@@ -119,6 +119,23 @@
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):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]