overrides: implement the python iterator protocol for Gst.Iterator
authorAlessandro Decina <alessandro.d@gmail.com>
Mon, 15 Oct 2012 07:10:25 +0000 (09:10 +0200)
committerAlessandro Decina <alessandro.d@gmail.com>
Mon, 15 Oct 2012 07:29:06 +0000 (09:29 +0200)
So that you can use: for value in gst_iterator: ...

gi/overrides/Gst.py

index 1e3cca5..392fd31 100644 (file)
@@ -77,6 +77,26 @@ class Caps(Gst.Caps):
 Caps = override(Caps)
 __all__.append('Caps')
 
+class IteratorError(Exception):
+    pass
+__all__.append('IteratorError')
+
+class Iterator(Gst.Iterator):
+    def __iter__(self):
+        while True:
+            result, value = self.next()
+            if result == Gst.IteratorResult.DONE:
+                break
+
+            if result != Gst.IteratorResult.OK:
+                raise IteratorError(result)
+
+            yield value
+
+Iterator = override(Iterator)
+__all__.append('Iterator')
+
+
 class ElementFactory(Gst.ElementFactory):
 
     # ElementFactory