[pygobject] Python iterator interface support for GFileEnumerator.



commit 9e7b95b3676a1b502662523a9bd4ebe40ccb4845
Author: Tony Young <rofflwaffls gmail com>
Date:   Thu Dec 16 23:39:33 2010 +0000

    Python iterator interface support for GFileEnumerator.

 gi/overrides/Gio.py      |   41 +++++++++++++++++++++++++++++++++++++++++
 gi/overrides/Makefile.am |    1 +
 tests/test_overrides.py  |   20 ++++++++++++++++++++
 3 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py
new file mode 100644
index 0000000..880aea9
--- /dev/null
+++ b/gi/overrides/Gio.py
@@ -0,0 +1,41 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+#
+# Copyright (C) 2010 Ignacio Casal Quinteiro <icq gnome org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+from ..overrides import override
+from ..importer import modules
+
+Gio = modules['Gio']._introspection_module
+
+__all__ = []
+
+class FileEnumerator(Gio.FileEnumerator):
+    def __iter__(self):
+        return self
+
+    def next(self):
+        file_info = self.next_file(None)
+
+        if file_info is not None:
+            return file_info
+        else:
+            raise StopIteration
+
+FileEnumerator = override(FileEnumerator)
+__all__.append('FileEnumerator')
diff --git a/gi/overrides/Makefile.am b/gi/overrides/Makefile.am
index 0e4f6c0..2f860c1 100644
--- a/gi/overrides/Makefile.am
+++ b/gi/overrides/Makefile.am
@@ -7,6 +7,7 @@ pygioverrides_PYTHON = \
 	GLib.py \
 	Gtk.py \
 	Gdk.py \
+	Gio.py \
 	GIMarshallingTests.py \
 	Pango.py \
 	keysyms.py \
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 075ba77..9fb3192 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -10,6 +10,7 @@ from gi.repository import GLib
 from gi.repository import GObject
 from gi.repository import Gdk
 from gi.repository import Gtk
+from gi.repository import Gio
 from gi.repository import Pango
 import gi.overrides as overrides
 import gi.types
@@ -968,3 +969,22 @@ class TestGtk(unittest.TestCase):
         sb = sw.get_vscrollbar()
         self.assertEquals(sw.get_vadjustment(), sb.get_adjustment())
 
+class TestGio(unittest.TestCase):
+    def test_file_enumerator(self):
+        self.assertEquals(Gio.FileEnumerator, overrides.Gio.FileEnumerator)
+        f = Gio.file_new_for_path("./")
+
+        iter_info = []
+        for info in f.enumerate_children("standard::*", 0, None):
+            iter_info.append(info.get_name())
+
+        next_info = []
+        enumerator = f.enumerate_children("standard::*", 0, None)
+        while True:
+            info = enumerator.next_file(None)
+            if info is None:
+                break
+            next_info.append(info.get_name())
+
+        self.assertEquals(iter_info, next_info)
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]