[pitivi] First effects UI representation



commit f2dbbf1f85491afa9dc6aa8e2094ca1360abd59f
Author: Thibault Saunier <tsaunier src gnome org>
Date:   Mon Jun 7 23:23:47 2010 -0300

    First effects UI representation

 pitivi/timeline/timeline.py |   18 +++++++++----
 pitivi/ui/timeline.py       |    6 ++--
 pitivi/ui/trackobject.py    |   56 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 9 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 83e9fcd..7c152ef 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1676,13 +1676,16 @@ class Timeline(Signallable, Loggable):
         self.addTimelineObject(timeline_object)
         return timeline_object
 
-    def addEffectFactory(self, factory):
+    def addEffectFactory(self, factory, start=0):
         """
         Creates a TimelineObject for the given EffectFactory and adds it to the timeline.
 
         @param factory: The EffectFactory to add.
         @type factory: L{EffectFactory}
-        @raises TimelineError: if C{strict} is True and no exact mapping could be calculated.
+        @param factory: The EffectFactory to add.
+        @ivar start: The position of the effect on a timeline (nanoseconds)
+        @type start: L{long}
+        @raises TimelineError: if the factory doesn't have input or output streams
         """
         self.debug("factory:%r", factory)
 
@@ -1696,7 +1699,7 @@ class Timeline(Signallable, Loggable):
             raise TimelineError()
         input_stream = input_stream[0]
 
-        track = self._getEffectTrack(input_stream)
+        track = self.getEffectTrack(factory)
         if track is None:
           raise TimelineError()
 
@@ -1705,12 +1708,15 @@ class Timeline(Signallable, Loggable):
         track.addTrackObject(track_object)
         timeline_object.addTrackObject(track_object)
 
-        timeline_object.duration = track.duration #FIXME
         self.addTimelineObject(timeline_object)
+
+        timeline_object.start = start
+        timeline_object.setDuration(track.duration - start)
+
         return timeline_object
 
-    def _getEffectTrack(self, stream):
-        return [track for track in self.tracks if type (track.stream) == type(stream)][0]
+    def getEffectTrack(self, factory):
+        return [track for track in self.tracks if type (track.stream) == type(factory.input_streams[0])][0]
 
     def _getSourceFactoryStreamMap(self, factory):
         # track.stream -> track
diff --git a/pitivi/ui/timeline.py b/pitivi/ui/timeline.py
index 7057fe3..632a4f1 100644
--- a/pitivi/ui/timeline.py
+++ b/pitivi/ui/timeline.py
@@ -422,7 +422,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             # actual drag-and-drop
             if not self._temp_objects:
                 self.timeline.disableUpdates()
-                self._add_temp_source()
+                self._add_temp_source(x,y)
                 focus = self._temp_objects[0]
                 self._move_context = MoveContext(self.timeline,
                         focus, set(self._temp_objects[1:]))
@@ -480,9 +480,9 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         context.drag_status(gtk.gdk.ACTION_COPY, timestamp)
         return True
 
-    def _add_temp_source(self):
+    def _add_temp_source(self, x, y):
         if isinstance (self._factories[0], EffectFactory):
-            self._temp_objects = [self.timeline.addEffectFactory(factory)
+            self._temp_objects = [self.timeline.addEffectFactory(factory, Zoomable.pixelToNs(x))
                 for factory in self._factories]
         else:
             self._temp_objects = [self.timeline.addSourceFactory(factory)
diff --git a/pitivi/ui/trackobject.py b/pitivi/ui/trackobject.py
index 2c397f6..a099145 100644
--- a/pitivi/ui/trackobject.py
+++ b/pitivi/ui/trackobject.py
@@ -252,6 +252,9 @@ class TrackObject(View, goocanvas.Group, Zoomable):
         #be shown on existing track?)
         if not isinstance(element, TrackEffect):
             self.content = Preview(self.app, element)
+        else:
+            w = Effect(element)
+            self.add_child(w)
 
         self.name = goocanvas.Text(
             x= NAME_HOFFSET + NAME_PADDING,
@@ -428,3 +431,56 @@ class TrackObject(View, goocanvas.Group, Zoomable):
                 self.namebg.props.visibility = goocanvas.ITEM_VISIBLE
             else:
                 self.namebg.props.visibility = goocanvas.ITEM_INVISIBLE
+
+class Effect(goocanvas.Rect, Zoomable):
+
+    def __init__(self, element):
+        goocanvas.Rect.__init__(self)
+        Zoomable.__init__(self)
+        self.props.fill_color = "blue"
+        self.props.stroke_color = "black"
+        self.set_simple_transform(0, -LAYER_SPACING + 3, 1.0, 0)
+        self.props.height = LAYER_SPACING - 6
+        self.props.pointer_events = goocanvas.EVENTS_NONE
+        self.props.radius_x = 2
+        self.props.radius_y = 2
+        self.props.y = 0 #We keep the effect up
+        self.element = element
+
+    def _setEffect(self):
+        if self.element:
+            self._updateAll()
+
+    def _updateAll(self):
+        element = self.element
+        start = element.start
+        duration = element.factory.duration
+        self._updateStart(element, start)
+        self._updateDuration(element, duration)
+        self._updatePriority(element, duration)
+
+    element = receiver(_setEffect)
+
+    @handler(element, "start-changed")
+    def _updateStart(self, element, start):
+        if self.element.timeline_object is not None:
+            element.setStart(start, True)
+            track_duration = element.timeline_object.timeline.getEffectTrack(element.factory).duration
+            x = self.nsToPixel(start)
+            self.element.setDuration(track_duration - start, True)
+
+    @handler(element, "duration-changed")
+    def _updateDuration(self, element, duration):
+        width = max(0, self.nsToPixel(duration) - self.props.x)
+        if width == 0:
+            self.props.visibility = goocanvas.ITEM_INVISIBLE
+        else:
+            self.props.visibility = goocanvas.ITEM_VISIBLE
+        self.props.width = width
+
+    @handler(element, "priority-changed")
+    def _updatePriority(self, transition, priority):
+        self.props.y = 0
+
+    def zoomChanged(self):
+        self._updateAll()



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