[pitivi/ges] track: Subclass TrackObject for transitions and filesources



commit 7c177774d40b4021abaaf7bfb7840e7b012f7e53
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Thu Apr 19 13:28:26 2012 -0400

    track: Subclass TrackObject for transitions and filesources

 pitivi/timeline/track.py |   69 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 55 insertions(+), 14 deletions(-)
---
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index d752e69..06e205f 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -337,7 +337,7 @@ class TrackObject(View, goocanvas.Group, Zoomable):
                 self._view.app.current.seeker.seek(Zoomable.pixelToNs(x))
                 timeline.selection.setToObj(element, SELECT)
 
-    def __init__(self, instance, element, track, timeline, utrack, is_transition=False):
+    def __init__(self, instance, element, track, timeline, utrack):
         goocanvas.Group.__init__(self)
         View.__init__(self)
         Zoomable.__init__(self)
@@ -348,8 +348,6 @@ class TrackObject(View, goocanvas.Group, Zoomable):
         self.timeline = timeline
         self.namewidth = 0
         self.nameheight = 0
-        self.is_transition = is_transition
-
         self.snapped_before = False
         self.snapped_after = False
         self._element = None
@@ -381,15 +379,6 @@ class TrackObject(View, goocanvas.Group, Zoomable):
             line_width=0.0,
             height=self.height)
 
-        if not self.is_transition:
-            self.preview = Preview(self.app, element)
-            for thing in (self.bg, self.preview, self._selec_indic,
-                self.start_handle, self.end_handle, self.namebg, self.name):
-                self.add_child(thing)
-        else:
-            for thing in (self.bg, self.name):
-                self.add_child(thing)
-
         self.element = element
         element.max_duration = element.props.duration
         element.starting_start = element.props.start
@@ -441,6 +430,9 @@ class TrackObject(View, goocanvas.Group, Zoomable):
 
     expanded = property(getExpanded, setExpanded)
 
+    def _getColor(self):
+        raise NotImplementedError
+
 ## Public API
 
     def focus(self):
@@ -582,6 +574,55 @@ class TrackObject(View, goocanvas.Group, Zoomable):
 TRACK_CONTROL_WIDTH = 75
 
 
+class TrackTransition(TrackObject):
+    """
+    Subclass of TrackObject to account for the differences of transition objects
+    """
+    def __init__(self, instance, element, track, timeline, utrack):
+        TrackObject.__init__(self, instance, element, track, timeline, utrack)
+        for thing in (self.bg, self.name):
+            self.add_child(thing)
+
+    def _setElement(self, element):
+        # FIXME: add the transition name as the label
+        pass
+
+    def _getColor(self):
+        # Transitions are bright blue, independent of the user color settings
+        return 0x0089CFF0
+
+
+class TrackFileSource(TrackObject):
+    """
+    Subclass of TrackObject to allow thumbnailing of objects with URIs
+    """
+    def __init__(self, instance, element, track, timeline, utrack):
+        TrackObject.__init__(self, instance, element, track, timeline, utrack)
+        self.preview = Preview(self.app, element)
+        for thing in (self.bg, self.preview, self._selec_indic,
+            self.start_handle, self.end_handle, self.namebg, self.name):
+            self.add_child(thing)
+
+    def _setElement(self, element):
+        """
+        Set the human-readable file name as the clip's text label
+        """
+        if self.element:
+            uri = self.element.props.uri
+            info = self.app.current.medialibrary.getInfoFromUri(uri)
+            self.name.props.text = info_name(info)
+            twidth, theight = text_size(self.name)
+            self.namewidth = twidth
+            self.nameheight = theight
+            self._update()
+
+    def _getColor(self):
+        if self.element.get_track().props.track_type == ges.TRACK_TYPE_AUDIO:
+            return self.settings.audioClipBg
+        else:
+            return self.settings.videoClipBg
+
+
 class TrackControls(gtk.Label, Loggable):
     """Contains a timeline track name.
 
@@ -743,7 +784,7 @@ class Track(goocanvas.Group, Zoomable, Loggable):
 
     def check(self, tr_obj):
         if tr_obj.get_timeline_object():
-            w = TrackObject(self.app, tr_obj, self.track, self.timeline, self)
+            w = TrackFileSource(self.app, tr_obj, self.track, self.timeline, self)
             self.widgets[tr_obj] = w
             self.add_child(w)
             self.app.gui.setBestZoomRatio()
@@ -760,7 +801,7 @@ class Track(goocanvas.Group, Zoomable, Loggable):
         Zoomable.removeInstance(w)
 
     def _transitionAdded(self, transition):
-        w = TrackObject(self.app, transition, self.track, self.timeline, self, True)
+        w = TrackTransition(self.app, transition, self.track, self.timeline, self)
         self.widgets[transition] = w
         self.add_child(w)
         self.transitions.append(w)



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