[pitivi] track: add track.max_priority + tests.
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] track: add track.max_priority + tests.
- Date: Tue, 17 Mar 2009 06:48:28 -0400 (EDT)
commit c0dcb816fca9bc80725d134e8de39e784431afed
Author: Alessandro Decina <alessandro decina collabora co uk>
Date: Mon Mar 16 16:34:46 2009 +0100
track: add track.max_priority + tests.
---
pitivi/timeline/track.py | 58 ++++++++++++++++++++++++++++++++++++++--------
tests/test_track.py | 38 +++++++++++++++++++++++++++++-
2 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index b65ae60..a9fe944 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -299,16 +299,18 @@ class Track(object, Signallable):
'start-changed': ['start'],
'duration-changed': ['duration'],
'track-object-added': ['track_object'],
- 'track-object-removed': ['track_object']
+ 'track-object-removed': ['track_object'],
+ 'max-priority-changed': ['track_object']
}
def __init__(self, stream):
self.stream = stream
self.composition = gst.element_factory_make('gnlcomposition')
- self.composition.connect('notify::start', self._startChangedCb)
- self.composition.connect('notify::duration', self._durationChangedCb)
+ self.composition.connect('notify::start', self._compositionStartChangedCb)
+ self.composition.connect('notify::duration', self._compositionDurationChangedCb)
self.track_objects = []
self.default_track_object = None
+ self._max_priority = 0
default_track_object = self._getDefaultTrackObjectForStream(stream)
if default_track_object:
@@ -344,8 +346,12 @@ class Track(object, Signallable):
self.default_track_object = None
# FIXME: implement TrackObject.priority
track_object.gnl_object.props.priority = 2**32-1
- self.addTrackObject(track_object)
self.default_track_object = track_object
+ try:
+ self.addTrackObject(track_object)
+ except:
+ self.default_track_object = None
+ raise
start = property(_getStart)
@@ -354,13 +360,10 @@ class Track(object, Signallable):
duration = property(_getDuration)
- def _startChangedCb(self, composition, pspec):
- start = composition.props.start
- self.emit('start-changed', start)
+ def _getMaxPriority(self):
+ return self._max_priority
- def _durationChangedCb(self, composition, pspec):
- duration = composition.props.duration
- self.emit('duration-changed', duration)
+ max_priority = property(_getMaxPriority)
def addTrackObject(self, track_object):
if track_object.track is not None:
@@ -376,6 +379,9 @@ class Track(object, Signallable):
track_object.makeBin()
+ self._updateMaxPriority()
+ self._connectToTrackObject(track_object)
+
self.emit('track-object-added', track_object)
def removeTrackObject(self, track_object):
@@ -388,13 +394,45 @@ class Track(object, Signallable):
except gst.RemoveError:
raise TrackError()
+ self._disconnectFromTrackObject(track_object)
track_object.release()
self.track_objects.remove(track_object)
track_object.track = None
+ self._updateMaxPriority()
+
self.emit('track-object-removed', track_object)
def removeAllTrackObjects(self):
for track_object in list(self.track_objects):
self.removeTrackObject(track_object)
+
+ def _updateMaxPriority(self):
+ priorities = [track_object.priority for track_object in
+ self.track_objects if track_object is not self.default_track_object]
+ if not priorities:
+ max_priority = 0
+ else:
+ max_priority = max(priorities)
+ if max_priority != self._max_priority:
+ self._max_priority = max_priority
+ self.emit('max-priority-changed', self._max_priority)
+
+ def _compositionStartChangedCb(self, composition, pspec):
+ start = composition.props.start
+ self.emit('start-changed', start)
+
+ def _compositionDurationChangedCb(self, composition, pspec):
+ duration = composition.props.duration
+ self.emit('duration-changed', duration)
+
+ def _trackObjectPriorityChangedCb(self, track_object, priority):
+ self._updateMaxPriority()
+
+ def _connectToTrackObject(self, track_object):
+ track_object.connect('priority-changed',
+ self._trackObjectPriorityChangedCb)
+
+ def _disconnectFromTrackObject(self, track_object):
+ track_object.disconnect_by_function(self._trackObjectPriorityChangedCb)
diff --git a/tests/test_track.py b/tests/test_track.py
index 5c47493..d1e9e56 100644
--- a/tests/test_track.py
+++ b/tests/test_track.py
@@ -273,7 +273,7 @@ class TestTrackObject(TestCase):
self.failUnlessEqual(monitor.duration_changed_count, 1)
-class TestTrackAddRemoveObjects(TestCase):
+class TestTrack(TestCase):
def setUp(self):
TestCase.setUp(self)
self.factory = StubFactory()
@@ -343,3 +343,39 @@ class TestTrackAddRemoveObjects(TestCase):
for obj in objs:
self.failUnlessEqual(obj.track, None)
+
+ def testMaxPriority(self):
+ track = self.track1
+ factory = self.factory
+
+ obj1 = SourceTrackObject(factory)
+ obj1.priority = 10
+
+ self.failUnlessEqual(track.max_priority, 0)
+ track.addTrackObject(obj1)
+ self.failUnlessEqual(track.max_priority, 10)
+
+ obj2 = SourceTrackObject(factory)
+ obj2.priority = 5
+ track.addTrackObject(obj2)
+ self.failUnlessEqual(track.max_priority, 10)
+
+ obj3 = SourceTrackObject(factory)
+ obj3.priority = 14
+ track.addTrackObject(obj3)
+ self.failUnlessEqual(track.max_priority, 14)
+
+ obj3.priority = 9
+ self.failUnlessEqual(track.max_priority, 10)
+
+ obj2.priority = 11
+ self.failUnlessEqual(track.max_priority, 11)
+
+ track.removeTrackObject(obj1)
+ self.failUnlessEqual(track.max_priority, 11)
+
+ track.removeTrackObject(obj2)
+ self.failUnlessEqual(track.max_priority, 9)
+
+ track.removeTrackObject(obj3)
+ self.failUnlessEqual(track.max_priority, 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]