python: Add a Timeline.iter_clips() helper to iterate clips
authorThibault Saunier <tsaunier@igalia.com>
Mon, 2 Mar 2020 22:06:17 +0000 (19:06 -0300)
committerThibault Saunier <tsaunier@igalia.com>
Mon, 2 Mar 2020 22:14:01 +0000 (19:14 -0300)
bindings/python/gi/overrides/GES.py
tests/check/python/test_timeline.py

index 1bd170e241eba7cb26da024c89aaf9d804568abf..bca0b296a9d3b8bbe66a6aece3d14e11a07dbc29 100644 (file)
@@ -98,6 +98,16 @@ class Asset(GES.Asset):
 Asset = override(Asset)
 __all__.append('Asset')
 
+class Timeline(GES.Timeline):
+    def iter_clips(self):
+        """Iterate all clips in a timeline"""
+        for layer in self.get_layers():
+            for clip in layer.get_clips():
+                yield clip
+
+Timeline = override(Timeline)
+__all__.append('Timeline')
+
 try:
     from gi.repository import Gst
     Gst
index 919b068de4b74ac8f31494b9d3e1d6b62a73a836..44af97290811b2e8f484d8553b1b2dccb5202871 100644 (file)
@@ -102,6 +102,15 @@ class TestTimeline(common.GESSimpleTimelineTest):
         self.assertEqual(timeline.get_asset(), project)
         self.assertEqual(len(project.list_assets(GES.Extractable)), 2)
 
+    def test_iter_timeline(self):
+        all_clips = set()
+        for l in range(5):
+            self.timeline.append_layer()
+            for _ in range(5):
+                all_clips.add(self.append_clip(l))
+        self.assertEqual(set(self.timeline.iter_clips()), all_clips)
+
+
     def test_nested_serialization(self):
         nested_timeline = common.create_project(with_group=True, saved=True)
         nested_project = nested_timeline.get_asset()