pitivi r1335 - in trunk: . pitivi/timeline tests



Author: edwardrv
Date: Thu Oct 16 14:21:35 2008
New Revision: 1335
URL: http://svn.gnome.org/viewvc/pitivi?rev=1335&view=rev

Log:
	* pitivi/timeline/composition.py:
	* pitivi/timeline/objects.py:
	* pitivi/timeline/source.py:
	Use python properties more.
	* tests/test_timeline_composition.py:
	* tests/test_timeline_objects.py:
	* tests/test_timeline_source.py:
	Adapt tests for changes.

Modified:
   trunk/ChangeLog
   trunk/pitivi/timeline/composition.py
   trunk/pitivi/timeline/objects.py
   trunk/pitivi/timeline/source.py
   trunk/tests/test_timeline_composition.py
   trunk/tests/test_timeline_objects.py
   trunk/tests/test_timeline_source.py

Modified: trunk/pitivi/timeline/composition.py
==============================================================================
--- trunk/pitivi/timeline/composition.py	(original)
+++ trunk/pitivi/timeline/composition.py	Thu Oct 16 14:21:35 2008
@@ -433,7 +433,7 @@
 
         # if auto_linked and self.linked, add brother to self.linked with same parameters
         if auto_linked and self.linked:
-            if source.getBrother():
+            if source.brother:
                 self.linked._addSource(source.brother, position)
 
     def insertSourceAfter(self, source, existingsource, push_following=True, auto_linked=True):
@@ -744,7 +744,7 @@
             # return the settings of our only source
             return self.sources[0][2][0].getExportSettings()
         else:
-            if self.isAudio():
+            if self.isaudio:
                 return self._autoAudioSettings()
             else:
                 return self._autoVideoSettings()

Modified: trunk/pitivi/timeline/objects.py
==============================================================================
--- trunk/pitivi/timeline/objects.py	(original)
+++ trunk/pitivi/timeline/objects.py	Thu Oct 16 14:21:35 2008
@@ -30,9 +30,9 @@
 from pitivi.objectfactory import ObjectFactory
 from pitivi.signalinterface import Signallable
 
-MEDIA_TYPE_NONE = 0
-MEDIA_TYPE_AUDIO = 1
-MEDIA_TYPE_VIDEO = 2
+(MEDIA_TYPE_NONE,
+ MEDIA_TYPE_AUDIO,
+ MEDIA_TYPE_VIDEO) = range(3)
 
 ## * Object Hierarchy
 
@@ -58,6 +58,16 @@
     """
     Base class for objects that can have a brother and be linked to something else
 
+    Properties:
+      _ Linked Object
+        _ Can be None
+        _ Must have same duration
+      _ Brother object
+        _ This is the same object but with the other media_type
+
+    Signals:
+      _ 'linked-changed' : new linked object
+
     Save/Load properties:
     * (optional) 'linked' (int) : UID of linked object
     * (optional) 'brother' (int) : UID of brother object
@@ -77,43 +87,46 @@
     __waiting_for_pending_objects__ = {}
 
     def __init__(self, **unused_kw):
-        self.linked = None
-        self.brother = None
+        self._linked = None
+        self._brother = None
         self.uid = -1
 
-    def _unlinkObject(self):
-        # really unlink the objects
-        if self.linked:
-            self.linked = None
-            self.emit("linked-changed", None)
+    ## properties
 
-    def _linkObject(self, obj):
-        # really do the link
-        self.linked = obj
-        self.emit("linked-changed", self.linked)
+    def _get_brother(self):
+        return self.getBrother()
+
+    def _set_brother(self, brother):
+        self.setBrother(brother)
+    brother = property(_get_brother, _set_brother,
+                       doc="Brother object")
+
+    ## read-only properties
+
+    @property
+    def linked(self):
+        """ Linked object """
+        return self._linked
+
+
+    ## public API
 
     def linkObject(self, obj):
         """
         link another object to this one.
         If there already is a linked object ,it will unlink it
         """
-        if self.linked and not self.linked == obj:
+        if self._linked and not self._linked == obj:
             self.unlinkObject()
         self._linkObject(obj)
-        self.linked._linkObject(self)
-
-    def getLinkedObject(self):
-        """
-        Returns the object currently linked to this one.
-        This is NOT guaranteed to be the brother
-        """
-        return self.linked
+        self._linked._linkObject(self)
 
     def unlinkObject(self):
         """
         unlink from the current linked object
         """
-        self.linked._unlinkObject()
+        if self._linked:
+            self._linked._unlinkObject()
         self._unlinkObject()
 
     def relinkBrother(self):
@@ -121,40 +134,57 @@
         links the object back to it's brother
         """
         # if already linked, unlink from previous
-        if self.linked:
+        if self._linked:
             self.unlinkObject()
 
         # link to brother
-        if self.brother:
-            self.linkObject(self.brother)
+        if self._brother:
+            self.linkObject(self._brother)
 
     def getBrother(self, autolink=True):
         """
         returns the brother element if it's possible,
         if autolink, then automatically link it to this element
         """
-        if not self.brother:
-            self.brother = self._makeBrother()
-            if not self.brother:
+        if not self._brother:
+            self._brother = self._makeBrother()
+            if not self._brother:
                 return None
-        if autolink and not self.linked == self.brother:
+        if autolink and not self._linked == self._brother:
             self.relinkBrother()
-        return self.brother
+        return self._brother
 
     def setBrother(self, brother, autolink=True):
         """
         Force a brother on an object.
         This can be useful if it's the parent of the object that knows
         what his brother is.
-        Use with caution
+
+        Use with caution !!!
         """
         gst.log("brother:%r , autolink:%r" % (brother, autolink))
-        self.brother = brother
-        # set ourselves as our brother's brother
-        self.brother.brother = self
+        self._brother = brother
+        if self._brother:
+            # set ourselves as our brother's brother
+            self._brother._brother = self
         if autolink:
             self.relinkBrother()
 
+    # private methods
+
+    def _unlinkObject(self):
+        # really unlink the objects
+        if self._linked:
+            self._linked = None
+            self.emit("linked-changed", None)
+
+    def _linkObject(self, obj):
+        # really do the link
+        self._linked = obj
+        self.emit("linked-changed", self._linked)
+
+    # methods to override in subclasses
+
     def _makeBrother(self):
         """
         Make the exact same object for the other media_type
@@ -167,10 +197,10 @@
     def toDataFormat(self):
         ret = Serializable.toDataFormat(self)
         ret["uid"] = self.getUniqueID()
-        if self.brother:
-            ret["brother-uid"] = self.brother.getUniqueID()
-        if self.linked:
-            ret["linked-uid"] = self.linked.getUniqueID()
+        if self._brother:
+            ret["brother-uid"] = self._brother.getUniqueID()
+        if self._linked:
+            ret["linked-uid"] = self._linked.getUniqueID()
         return ret
 
     def fromDataFormat(self, obj):
@@ -269,6 +299,9 @@
             cls.__waiting_for_pending_objects__[uid] = []
         cls.__waiting_for_pending_objects__[uid].append((weakref.proxy(obj), extra))
 
+
+
+
 class TimelineObject(BrotherObjects):
     """
     Base class for all timeline objects
@@ -277,15 +310,9 @@
       _ Start/Duration Time
       _ Media Type
       _ Gnonlin Object
-      _ Linked Object
-        _ Can be None
-        _ Must have same duration
-      _ Brother object
-        _ This is the same object but with the other media_type
 
     * signals
       _ 'start-duration-changed' : start position, duration position
-      _ 'linked-changed' : new linked object
 
     Save/Load properties
     * 'start' (int) : start position in nanoseconds
@@ -310,57 +337,106 @@
         BrotherObjects.__init__(self, **kwargs)
         self.name = name
         gst.log("new TimelineObject :%s %r" % (name, self))
-        self.start = start
-        self.duration = duration
-        self.factory = None
+        self._start = start
+        self._duration = duration
+        self._factory = None
         # Set factory and media_type and then create the gnlobject
         self.media_type = media_type
         self.gnlobject = None
+        self.factory = factory
+
+    ## properties
+
+    def _get_start(self):
+        return self._start
+
+    def _set_start(self, start):
+        self.setStartDurationTime(start=start)
+    start = property(_get_start, _set_start,
+                     doc="Start position of the object in its container (in nanoseconds)")
+
+    def _get_duration(self):
+        return self._duration
+
+    def _set_duration(self, duration):
+        self.setStartDurationTime(duration=duration)
+    duration = property(_get_duration, _set_duration,
+                        doc="Duration of the object in its container (in nanoseconds)")
+
+    def _get_factory(self):
+        return self._factory
+
+    def _set_factory(self, factory):
         self._setFactory(factory)
+    factory = property(_get_factory, _set_factory,
+                       doc="ObjectFactory used for this object")
 
-    def __repr__(self):
-        if hasattr(self, "name"):
-            return "<%s '%s' at 0x%x>" % (type(self).__name__, self.name, id(self))
-        return "<%s at 0x%x>" % (type(self).__name__, id(self))
+
+    ## read-only properties
+
+    @property
+    def isaudio(self):
+        """ Boolean indicating whether the object produces Audio """
+        return self.media_type == MEDIA_TYPE_AUDIO
+
+    @property
+    def isvideo(self):
+        """ Boolean indicating whether the object produces Video """
+        return self.media_type == MEDIA_TYPE_VIDEO
+
+    ## public API
+
+    def setStartDurationTime(self, start=gst.CLOCK_TIME_NONE, duration=0):
+        """
+        Sets the start and/or duration time
+
+        Only use this method when you wish to modify BOTH start and duration at once
+        """
+        self._setStartDurationTime(start, duration)
+        if self._linked:
+            self._linked._setStartDurationTime(start, duration)
+
+    ## methods to override in subclasses
 
     def _makeGnlObject(self):
         """ create and return the gnl_object """
         raise NotImplementedError
 
+    ## private methods
+
+    def __repr__(self):
+        if hasattr(self, "name"):
+            return "<%s '%s' at 0x%x>" % (type(self).__name__, self.name, id(self))
+        return "<%s at 0x%x>" % (type(self).__name__, id(self))
+
     def _setFactory(self, factory):
-        if self.factory:
-            gst.warning("Can't set a factory, this object already has one : %r" % self.factory)
+        if self._factory:
+            gst.warning("Can't set a factory, this object already has one : %r" % self._factory)
             return
         gst.log("factory:%r requires factory:%r" % (factory, self.__requires_factory__))
-        self.factory = factory
-        if not self.__requires_factory__ or self.factory:
+        self._factory = factory
+        if not self.__requires_factory__ or self._factory:
             gst.log("%r Creating associated gnlobject" % self)
             self.gnlobject = self._makeGnlObject()
-            self.gnlobject.connect("notify::start", self._startDurationChangedCb)
             self.gnlobject.log("got gnlobject !")
+            self.gnlobject.connect("notify::start", self._startDurationChangedCb)
             self.gnlobject.connect("notify::duration", self._startDurationChangedCb)
-            self._setStartDurationTime(self.start, self.duration, True)
+            self._setStartDurationTime(self._start, self._duration, force=True)
 
     def _setStartDurationTime(self, start=gst.CLOCK_TIME_NONE, duration=0, force=False):
         # really modify the start/duration time
         self.gnlobject.info("start:%s , duration:%s" %( gst.TIME_ARGS(start),
                                                         gst.TIME_ARGS(duration)))
-        if duration > 0 and (not self.duration == duration or force):
-            self.duration = duration
+        if duration > 0 and (not self._duration == duration or force):
+            self._duration = duration
             self.gnlobject.set_property("duration", long(duration))
-        if not start == gst.CLOCK_TIME_NONE and (not self.start == start or force):
-            self.start = start
+        if not start == gst.CLOCK_TIME_NONE and (not self._start == start or force):
+            self._start = start
             self.gnlobject.set_property("start", long(start))
 
-    def setStartDurationTime(self, start=gst.CLOCK_TIME_NONE, duration=0):
-        """ sets the start and/or duration time """
-        self._setStartDurationTime(start, duration)
-        if self.linked:
-            self.linked._setStartDurationTime(start, duration)
-
     def _startDurationChangedCb(self, gnlobject, prop):
         """ start/duration time has changed """
-        gst.log("self:%r , gnlobject:%r" % (self, gnlobject))
+        gst.log("self:%r , gnlobject:%r %r" % (self, gnlobject, self.gnlobject))
         if not gnlobject == self.gnlobject:
             gst.warning("We're receiving signals from an object we dont' control (self.gnlobject:%r, gnlobject:%r)" % (self.gnlobject, gnlobject))
         self.gnlobject.debug("property:%s" % prop.name)
@@ -368,22 +444,22 @@
         duration = 0
         if prop.name == "start":
             start = gnlobject.get_property("start")
-            gst.log("start: %s => %s" % (gst.TIME_ARGS(self.start),
+            gst.log("start: %s => %s" % (gst.TIME_ARGS(self._start),
                                          gst.TIME_ARGS(start)))
-            if start == self.start:
+            if start == self._start:
                 start = gst.CLOCK_TIME_NONE
             else:
-                self.start = long(start)
+                self._start = long(start)
         elif prop.name == "duration":
             duration = gnlobject.get_property("duration")
-            gst.log("duration: %s => %s" % (gst.TIME_ARGS(self.duration),
+            gst.log("duration: %s => %s" % (gst.TIME_ARGS(self._duration),
                                             gst.TIME_ARGS(duration)))
-            if duration == self.duration:
+            if duration == self._duration:
                 duration = 0
             else:
                 self.gnlobject.debug("duration changed:%s" % gst.TIME_ARGS(duration))
-                self.duration = long(duration)
-        self.emit("start-duration-changed", self.start, self.duration)
+                self._duration = long(duration)
+        self.emit("start-duration-changed", self._start, self._duration)
 
 
     # Serializable methods
@@ -391,17 +467,17 @@
     def toDataFormat(self):
         ret = BrotherObjects.toDataFormat(self)
         ret["start"] = self.start
-        ret["duration"] = self.duration
+        ret["duration"] = self._duration
         ret["name"] = self.name
-        if self.factory:
-            ret["factory-uid"] = self.factory.getUniqueID()
+        if self._factory:
+            ret["factory-uid"] = self._factory.getUniqueID()
         ret["media_type"] = self.media_type
         return ret
 
     def fromDataFormat(self, obj):
         BrotherObjects.fromDataFormat(self, obj)
-        self.start = obj["start"]
-        self.duration = obj["duration"]
+        self._start = obj["start"]
+        self._duration = obj["duration"]
 
         self.name = obj["name"]
 
@@ -420,13 +496,3 @@
             self._setFactory(obj)
         else:
             BrotherObjects.pendingObjectCreated(self, obj, field)
-
-    # FIXME : Should be made into properties
-
-    def isAudio(self):
-        """ Does the object provide audio """
-        return self.media_type == MEDIA_TYPE_AUDIO
-
-    def isVideo(self):
-        """ Does the object provide video """
-        return self.media_type == MEDIA_TYPE_VIDEO

Modified: trunk/pitivi/timeline/source.py
==============================================================================
--- trunk/pitivi/timeline/source.py	(original)
+++ trunk/pitivi/timeline/source.py	Thu Oct 16 14:21:35 2008
@@ -51,10 +51,10 @@
 
     def _makeGnlObject(self):
         gst.debug("Making a source for %r" % self)
-        if self.isAudio():
+        if self.isaudio:
             caps = gst.caps_from_string("audio/x-raw-int;audio/x-raw-float")
             postfix = "audio"
-        elif self.isVideo():
+        elif self.isvideo:
             caps = gst.caps_from_string("video/x-raw-yuv;video/x-raw-rgb")
             postfix = "video"
         else:
@@ -159,11 +159,11 @@
         TimelineSource.__init__(self, **kwargs)
 
     def makeGnlSourceContents(self):
-        if self.isAudio():
+        if self.isaudio:
             # silent audiotestsrc
             src = gst.element_factory_make("audiotestsrc")
             src.set_property("volume", 0)
-        elif self.isVideo():
+        elif self.isvideo:
             # black videotestsrc
             src = gst.element_factory_make("videotestsrc")
             src.props.pattern = 2
@@ -204,14 +204,14 @@
         return gnlobject
 
     def makeGnlSourceContents(self):
-        if self.isAudio():
+        if self.isaudio:
             caps = gst.caps_from_string("audio/x-raw-int;audio/x-raw-float")
-        elif self.isVideo():
+        elif self.isvideo:
             caps = gst.caps_from_string("video/x-raw-yuv;video/x-raw-rgb")
         else:
             raise NameError, "media type is NONE !"
         self.decodebin = SingleDecodeBin(caps=caps, uri=self.factory.name)
-        if self.isAudio():
+        if self.isaudio:
             self.volume_element = gst.element_factory_make("volume", "internal-volume")
             self.audioconv = gst.element_factory_make("audioconvert", "audioconv")
             self.volumebin = gst.Bin("volumebin")
@@ -248,7 +248,7 @@
 
     def setVolume(self, level):
         """ Set the volume to the given level """
-        if self.isAudio():
+        if self.isaudio:
             self._setVolume(level)
         elif self.linked:
             self.linked._setVolume(level)
@@ -259,7 +259,7 @@
         # find out if the factory provides the other element type
         if self.media_type == MEDIA_TYPE_NONE:
             return None
-        if self.isVideo():
+        if self.isvideo:
             if not self.factory.is_audio:
                 return None
             brother = TimelineFileSource(media_start=self.media_start,
@@ -268,7 +268,7 @@
                                          duration=self.duration,
                                          media_type=MEDIA_TYPE_AUDIO,
                                          name=self.name + "-brother")
-        elif self.isAudio():
+        elif self.isaudio:
             if not self.factory.is_video:
                 return None
             brother = TimelineFileSource(media_start=self.media_start,
@@ -291,7 +291,7 @@
         ret = TimelineSource.toDataFormat(self)
         ret["media-start"] = self.media_start
         ret["media-duration"] = self.media_duration
-        if self.isAudio() and hasattr(self, "volume_element"):
+        if self.isaudio and hasattr(self, "volume_element"):
             ret["volume"] = self.volume_element.get_property("volume")
         return ret
 

Modified: trunk/tests/test_timeline_composition.py
==============================================================================
--- trunk/tests/test_timeline_composition.py	(original)
+++ trunk/tests/test_timeline_composition.py	Thu Oct 16 14:21:35 2008
@@ -19,7 +19,7 @@
         self.assert_(self.othercomposition)
 
         self.composition.linkObject(self.othercomposition)
-        self.assertEquals(self.composition.getLinkedObject(),
+        self.assertEquals(self.composition.linked,
                           self.othercomposition)
 
         self.sigid = self.composition.connect("start-duration-changed",

Modified: trunk/tests/test_timeline_objects.py
==============================================================================
--- trunk/tests/test_timeline_objects.py	(original)
+++ trunk/tests/test_timeline_objects.py	Thu Oct 16 14:21:35 2008
@@ -35,16 +35,16 @@
     def testLinkedObject(self):
         # Link object1 to object2
         self.object1.linkObject(self.object2)
-        self.assertEquals(self.object1.getLinkedObject(),
+        self.assertEquals(self.object1.linked,
                           self.object2)
-        self.assertEquals(self.object2.getLinkedObject(),
+        self.assertEquals(self.object2.linked,
                           self.object1)
 
         # and now unlink them
         self.object1.unlinkObject()
-        self.assertEquals(self.object1.getLinkedObject(),
+        self.assertEquals(self.object1.linked,
                           None)
-        self.assertEquals(self.object2.getLinkedObject(),
+        self.assertEquals(self.object2.linked,
                           None)
 
     def testBrotherNotLinked(self):
@@ -56,7 +56,7 @@
                           brother1)
 
         # the linked object should be None since it was not autolinked
-        self.assertEquals(self.object1.getLinkedObject(),
+        self.assertEquals(self.object1.linked,
                           None)
 
     def testBrotherLinked(self):
@@ -68,18 +68,18 @@
                           brother1)
 
         # the linked object should be brother1 since it was autolinked
-        self.assertEquals(self.object1.getLinkedObject(),
+        self.assertEquals(self.object1.linked,
                           brother1)
 
         # unlink the objects
         self.object1.unlinkObject()
 
         # object1 shouldn't be linked anymore
-        self.assertEquals(self.object1.getLinkedObject(),
+        self.assertEquals(self.object1.linked,
                           None)
 
     def testSingleSerialization(self):
-        self.assertEquals(self.object1.brother, None)
+        self.assertEquals(self.object1._brother, None)
         data1 = self.object1.toDataFormat()
         del self.object1
         self.object1 = None
@@ -93,14 +93,14 @@
         self.assertEquals(obj1.media_type, MEDIA_TYPE_VIDEO)
         self.assertEquals(obj1.name, "test1")
         self.assertEquals(obj1.linked, None)
-        self.assertEquals(obj1.brother, None)
+        self.assertEquals(obj1._brother, None)
         self.assert_(not obj1.gnlobject == None)
 
     def testLinkedBrotherSerialization(self):
         # get the brother of object1
         brother1 = self.object1.getBrother()
 
-        self.assertEquals(self.object1.brother, brother1)
+        self.assertEquals(self.object1._brother, brother1)
         self.assertEquals(self.object1.linked, brother1)
         self.assertEquals(brother1.linked, self.object1)
 
@@ -115,14 +115,14 @@
 
         # create object...
         pobj = to_object_from_data_type(data1)
-        self.assertEquals(pobj.brother, None)
+        self.assertEquals(pobj._brother, None)
         self.assertEquals(pobj.linked, None)
 
         # ... and brother
         pbro = to_object_from_data_type(brotherdata1)
 
         # check it's really the linked brother
-        self.assertEquals(pobj.brother, pbro)
+        self.assertEquals(pobj._brother, pbro)
         self.assertEquals(pobj.linked, pbro)
         self.assertEquals(pbro.linked, pobj)
 
@@ -171,7 +171,7 @@
 
         del brother
         self.object1.brother = None
-        self.object1.linked = None
+        self.object1.unlinkObject()
         gc.collect()
         self.assertEquals(len(BrotherObjects.__instances__), 2)
 

Modified: trunk/tests/test_timeline_source.py
==============================================================================
--- trunk/tests/test_timeline_source.py	(original)
+++ trunk/tests/test_timeline_source.py	Thu Oct 16 14:21:35 2008
@@ -80,7 +80,7 @@
         brother = self.source.getBrother()
 
         # Make sure it's the right brother
-        self.assertEquals(self.source.brother, brother)
+        self.assertEquals(self.source._brother, brother)
         self.assertEquals(self.source.linked, brother)
         self.assertEquals(brother.media_type, MEDIA_TYPE_AUDIO)
         self.assertEquals(self.source.media_start, brother.media_start)
@@ -131,14 +131,14 @@
         self.assertEquals(source.factory, self.factory)
         self.assertEquals(source.media_type, MEDIA_TYPE_VIDEO)
         self.assertEquals(source.linked, None)
-        self.assertEquals(source.brother, None)
+        self.assertEquals(source._brother, None)
 
     def testBrotherSerialization(self):
         brother = self.source.getBrother()
 
         self.assertEquals(len(BrotherObjects.__instances__), 0)
 
-        self.assertEquals(self.source.brother, brother)
+        self.assertEquals(self.source._brother, brother)
         self.assertEquals(self.source.linked, brother)
         self.assertEquals(brother.linked, self.source)
 
@@ -169,7 +169,7 @@
     def testLinkedBrotherSerialization(self):
         # create a brother and check all values are properly set
         brother = self.source.getBrother()
-        self.assertEquals(self.source.brother, brother)
+        self.assertEquals(self.source._brother, brother)
         self.assertEquals(self.source.linked, brother)
         self.assertEquals(brother.linked, self.source)
 
@@ -188,7 +188,7 @@
         # recreate object
         gst.log("recreating source !")
         source = to_object_from_data_type(data1)
-        self.assertEquals(source.brother, None)
+        self.assertEquals(source._brother, None)
         self.assertEquals(source.linked, None)
 
         # recreate brother
@@ -204,7 +204,7 @@
         self.assertEquals(source.factory, self.factory)
         self.assertEquals(source.media_type, MEDIA_TYPE_VIDEO)
         self.assertEquals(source.linked, brothernew)
-        self.assertEquals(source.brother, brothernew)
+        self.assertEquals(source._brother, brothernew)
 
         self.assertEquals(brothernew.start, 0)
         self.assertEquals(brothernew.duration, gst.SECOND)
@@ -213,7 +213,7 @@
         self.assertEquals(brothernew.factory, self.factory)
         self.assertEquals(brothernew.media_type, MEDIA_TYPE_AUDIO)
         self.assertEquals(brothernew.linked, source)
-        self.assertEquals(brothernew.brother, source)
+        self.assertEquals(brothernew._brother, source)
 
     # uniqueness tests
 



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