python: Add a Timeline.iter_clips() helper to iterate clips

This commit is contained in:
Thibault Saunier 2020-03-02 19:06:17 -03:00
parent 9ec1ebfbdf
commit 3b182342e0
2 changed files with 19 additions and 0 deletions

View 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

View 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()