pitivi r1211 - in branches/SOC_2008_BLEWIS: . pitivi pitivi/timeline pitivi/ui tests



Author: edwardrv
Date: Tue Jul 22 19:02:52 2008
New Revision: 1211
URL: http://svn.gnome.org/viewvc/pitivi?rev=1211&view=rev

Log:
* pitivi/objectfactory.py:
Add intermediary SourceFactory class adding the getDuration() and
getDefaultDuration() getters.
Make FileSourceFactory.length and duration private.
* pitivi/bin.py:
* pitivi/discoverer.py:
* pitivi/timeline/composition.py:
* pitivi/timeline/source.py:
* pitivi/ui/complexsource.py:
* pitivi/ui/sourcefactories.py:
* pitivi/ui/timelineobjects.py:
* pitivi/ui/viewer.py:
* tests/common.py:
Update code for API update in SourceFactory and FileSourceFactory


Modified:
   branches/SOC_2008_BLEWIS/ChangeLog
   branches/SOC_2008_BLEWIS/pitivi/bin.py
   branches/SOC_2008_BLEWIS/pitivi/discoverer.py
   branches/SOC_2008_BLEWIS/pitivi/objectfactory.py
   branches/SOC_2008_BLEWIS/pitivi/timeline/composition.py
   branches/SOC_2008_BLEWIS/pitivi/timeline/source.py
   branches/SOC_2008_BLEWIS/pitivi/ui/complexsource.py
   branches/SOC_2008_BLEWIS/pitivi/ui/sourcefactories.py
   branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py
   branches/SOC_2008_BLEWIS/pitivi/ui/viewer.py
   branches/SOC_2008_BLEWIS/tests/common.py

Modified: branches/SOC_2008_BLEWIS/pitivi/bin.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/bin.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/bin.py	Tue Jul 22 19:02:52 2008
@@ -396,7 +396,7 @@
                           has_video = factory.is_video,
                           has_audio = factory.is_audio,
                           width = width, height = height,
-                          length = factory.length)
+                          length = factory.getDuration())
 
     def _addSource(self):
         self.add(self.source)

Modified: branches/SOC_2008_BLEWIS/pitivi/discoverer.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/discoverer.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/discoverer.py	Tue Jul 22 19:02:52 2008
@@ -80,7 +80,6 @@
         self.current = None
         self.currentTags = []
         self.pipeline = None
-        self.thumbnailing = False
         self.thisdone = False
         self.prerolled = False
         self.nomorepads = False
@@ -156,7 +155,7 @@
             self.currentfactory.addMediaTags(self.currentTags)
             if self.isimage:
                 self.currentfactory.setThumbnail(gst.uri_get_location(self.current))
-            if not self.currentfactory.length and not self.isimage:
+            if not self.currentfactory.getDuration() and not self.isimage:
                 self.emit('not_media_file', self.current,
                           _("Could not establish the duration of the file."),
                           _("This clip seems to be in a format which cannot be accessed in a random fashion."))
@@ -329,7 +328,7 @@
                     self.currentfactory.setAudioInfo(caps)
                 elif caps.to_string().startswith("video/x-raw") and not self.currentfactory.video_info:
                     self.currentfactory.setVideoInfo(caps)
-            if not self.currentfactory.length:
+            if not self.currentfactory.getDuration():
                 try:
                     length, format = pad.query_duration(gst.FORMAT_TIME)
                 except:

Modified: branches/SOC_2008_BLEWIS/pitivi/objectfactory.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/objectfactory.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/objectfactory.py	Tue Jul 22 19:02:52 2008
@@ -270,7 +270,35 @@
 
 gobject.type_register(ObjectFactory)
 
-class FileSourceFactory(ObjectFactory):
+class SourceFactory(ObjectFactory):
+    """
+    Provides sources usable in a timeline
+    """
+
+    __data_type__ = "source-factory"
+
+    def getDuration(self):
+        """
+        Returns the maximum duration of the source in nanoseconds
+
+        If the source doesn't have a maximum duration (like an image), subclasses
+        should implement this by returning 2**63 - 1 (MAX_LONG).
+        """
+        pass
+
+    def getDefaultDuration(self):
+        """
+        Returns the default duration of a file in nanoseconds,
+        this should be used when using sources initially.
+
+        Most sources will return the same as getDuration(), but can be overriden
+        for sources that have an infinite duration.
+        """
+        return self.getDuration()
+
+gobject.type_register(SourceFactory)
+
+class FileSourceFactory(SourceFactory):
     """
     Provides File sources useable in a timeline
     """
@@ -294,27 +322,31 @@
 
     def __init__(self, filename="", project=None, **kwargs):
         gst.info("filename:%s , project:%s" % (filename, project))
-        ObjectFactory.__init__(self, **kwargs)
+        SourceFactory.__init__(self, **kwargs)
         self.project = project
         self.name = filename
         self.displayname = os.path.basename(unquote(self.name))
         self.lastbinid = 0
-        self.length = 0
-        self.thumbnail = ""
-        self.thumbnails = []
+        self._length = 0
+        self._thumbnail = ""
+        self._thumbnails = []
         self.settings = None
 
+    ## SourceFactory implementation
+    def getDuration(self):
+        return self._length
+
     def do_set_property(self, property, value):
         if property.name == "length":
-            if self.length and self.length != value:
+            if self._length and self._length != value:
                 gst.warning("%s : Trying to set a new length (%s) different from previous one (%s)" % (self.name,
-                                                                                                       gst.TIME_ARGS(self.length),
+                                                                                                       gst.TIME_ARGS(self._length),
                                                                                                        gst.TIME_ARGS(value)))
-            self.length = value
+            self._length = value
         elif property.name == "thumbnail":
             gst.debug("thumbnail : %s" % value)
             if os.path.isfile(value):
-                self.thumbnail = value
+                self._thumbnail = value
             else:
                 gst.warning("Thumbnail path is invalid !")
         else:
@@ -383,6 +415,9 @@
         """ Sets the thumbnail filename of the element """
         self.set_property("thumbnail", thumbnail)
 
+    def getThumbnail(self):
+        return self._thumbnail
+
     def getExportSettings(self):
         """ Returns the ExportSettings corresponding to this source """
         if self.settings:
@@ -411,13 +446,13 @@
     def toDataFormat(self):
         ret = ObjectFactory.toDataFormat(self)
         ret["filename"] = self.name
-        ret["length"] = self.length
+        ret["length"] = self._length
         return ret
 
     def fromDataFormat(self, obj):
         ObjectFactory.fromDataFormat(self, obj)
         self.name = obj["filename"]
-        self.length = obj["length"]
+        self._length = obj["length"]
 
 
 class OperationFactory(ObjectFactory):

Modified: branches/SOC_2008_BLEWIS/pitivi/timeline/composition.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/timeline/composition.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/timeline/composition.py	Tue Jul 22 19:02:52 2008
@@ -485,15 +485,15 @@
         gst.info("start=%s, position=%d, existorder=%d, sourcelength=%s" % (gst.TIME_ARGS(start),
                                                                             position,
                                                                             existorder,
-                                                                            gst.TIME_ARGS(source.factory.length)))
+                                                                            gst.TIME_ARGS(source.factory.getDuration())))
         # set the correct start/duration time
-        duration = source.factory.length
+        duration = source.factory.getDuration()
         source.setStartDurationTime(start, duration)
 
         # pushing following
         if push_following and not position in [-1, 0]:
             #print self.gnlobject, "pushing following", existorder, len(self.sources[position - 1][2])
-            self.shiftSources(source.factory.length, existorder, len(self.sources[position - 1][2]))
+            self.shiftSources(source.factory.getDuration(), existorder, len(self.sources[position - 1][2]))
 
         self.addSource(source, position, auto_linked=auto_linked)
 

Modified: branches/SOC_2008_BLEWIS/pitivi/timeline/source.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/timeline/source.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/timeline/source.py	Tue Jul 22 19:02:52 2008
@@ -192,14 +192,14 @@
         if self.media_start == gst.CLOCK_TIME_NONE:
             self.media_start = 0
         if self.media_duration == 0:
-            self.media_duration = self.factory.length
+            self.media_duration = self.factory.getDuration()
 
         gnlobject = TimelineSource._makeGnlObject(self)
         if gnlobject == None:
             return None
 
         # we override start/duration
-        gnlobject.set_property("duration", long(self.factory.length))
+        gnlobject.set_property("duration", long(self.factory.getDuration()))
         gnlobject.set_property("start", long(0))
 
         return gnlobject

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/complexsource.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/complexsource.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/complexsource.py	Tue Jul 22 19:02:52 2008
@@ -49,8 +49,8 @@
         self.layerInfo = layerInfo
         self.source = source
         self.source.connect("start-duration-changed", self._startDurationChangedCb)
-        if self.source.factory.thumbnail:
-            self.thumbnailsurface = cairo.ImageSurface.create_from_png(self.source.factory.thumbnail)
+        if self.source.factory.getThumbnail():
+            self.thumbnailsurface = cairo.ImageSurface.create_from_png(self.source.factory.getThumbnail())
         else:
             self.thumbnailsurface = cairo.ImageSurface.create_from_png(os.path.join(get_pixmap_dir(), "pitivi-video.png"))
         self.pixmap = None

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/sourcefactories.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/sourcefactories.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/sourcefactories.py	Tue Jul 22 19:02:52 2008
@@ -337,9 +337,9 @@
 
     def _addFactory(self, factory):
         try:
-            pixbuf = gtk.gdk.pixbuf_new_from_file(factory.thumbnail)
+            pixbuf = gtk.gdk.pixbuf_new_from_file(factory.getThumbnail())
         except:
-            gst.error("Failure to create thumbnail from file %s" % factory.thumbnail)
+            gst.error("Failure to create thumbnail from file %s" % factory.getThumbnail())
             if factory.is_video:
                 thumbnail = self.videofilepixbuf
             elif factory.is_audio:
@@ -356,7 +356,7 @@
                                 factory.getPrettyInfo(),
                                 factory,
                                 factory.name,
-                                factory.length and "<b>%s</b>" % beautify_length(factory.length) or ""])
+                                factory.getDuration() and "<b>%s</b>" % beautify_length(factory.getDuration()) or ""])
         self._displayTreeView()
 
     # sourcelist callbacks

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py	Tue Jul 22 19:02:52 2008
@@ -587,7 +587,7 @@
             gst.log("end frame rewind")
             duration = self._mediaDuration - gst.SECOND
 
-        duration_max = self._source.factory.length - self._mediaStart
+        duration_max = self._source.factory.getDuration() - self._mediaStart
         duration = min(duration, duration_max)
 
         self._mediaDuration = duration
@@ -622,7 +622,7 @@
             self.startRewindButton.set_sensitive(True)
 
         end = self._mediaDuration + self._mediaStart
-        assert end <= self._source.factory.length 
+        assert end <= self._source.factory.getDuration()
 
         if (self._mediaStart + gst.SECOND) >= end:
             self.startAdvanceButton.set_sensitive(False)
@@ -634,7 +634,7 @@
         else:
             self.endRewindButton.set_sensitive(True)
 
-        if end >= self._source.factory.length:
+        if end >= self._source.factory.getDuration():
             self.endAdvanceButton.set_sensitive(False)
         else:
             self.endAdvanceButton.set_sensitive(True)
@@ -941,7 +941,7 @@
         editing.pack_start(edit, False, True)
         self.duration = gtk.Label()
         self.duration.set_markup("<small>%s</small>" %
-                beautify_length(self.filesource.factory.length))
+                beautify_length(self.filesource.factory.getDuration()))
         editing.pack_end(self.duration, False, False)
         edit.connect("clicked", self._editMenuItemCb)
 

Modified: branches/SOC_2008_BLEWIS/pitivi/ui/viewer.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/viewer.py	(original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/viewer.py	Tue Jul 22 19:02:52 2008
@@ -394,7 +394,7 @@
                 self._timelineDurationChangedSigId = (smartbin.project.timeline.videocomp,
                                                       sigid)
             else:
-                self.posadjust.upper = float(smartbin.factory.length)
+                self.posadjust.upper = float(smartbin.factory.getDuration())
                 if not self._timelineDurationChangedSigId == (None, None):
                     obj, sigid = self._timelineDurationChangedSigId
                     obj.disconnect(sigid)

Modified: branches/SOC_2008_BLEWIS/tests/common.py
==============================================================================
--- branches/SOC_2008_BLEWIS/tests/common.py	(original)
+++ branches/SOC_2008_BLEWIS/tests/common.py	Tue Jul 22 19:02:52 2008
@@ -123,3 +123,5 @@
         TestObjectFactory.__init__(self, *args, **kwargs)
         self.length = duration
 
+    def getDuration(self):
+        return self.length



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