[pitivi] undo: Avoid passing app to TimelineObserver



commit 46a1112e786bcc6d058e82c1bfe8844758affefc
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Mon May 30 10:06:23 2016 +0200

    undo: Avoid passing app to TimelineObserver
    
    Differential Revision: https://phabricator.freedesktop.org/D1032

 pitivi/application.py       |    2 +-
 pitivi/undo/timeline.py     |   36 ++++++++++++++++++++++++------------
 pitivi/undo/undo.py         |    9 +++++++++
 tests/test_undo_timeline.py |    2 +-
 4 files changed, 35 insertions(+), 14 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index b7d2463..27490da 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -267,7 +267,7 @@ class Pitivi(Gtk.Application, Loggable):
         self.action_log.connect("commit", self._actionLogCommit)
         self.action_log.connect("move", self._action_log_move_cb)
 
-        timeline_observer = TimelineObserver(self.action_log, app=self)
+        timeline_observer = TimelineObserver(self.action_log)
         timeline_observer.startObserving(project.timeline)
 
         project_observer = ProjectObserver(project, self.action_log)
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 2677ca0..39b6256 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -24,6 +24,7 @@ from pitivi.effects import PROPS_TO_IGNORE
 from pitivi.undo.undo import FinalizingAction
 from pitivi.undo.undo import GObjectObserver
 from pitivi.undo.undo import MetaContainerObserver
+from pitivi.undo.undo import SimpleUndoableAction
 from pitivi.undo.undo import UndoableAction
 from pitivi.utils.loggable import Loggable
 
@@ -430,6 +431,22 @@ class ActivePropertyChanged(UndoableAction):
         self.active = not self.active
 
 
+class ControlSourceSetAction(SimpleUndoableAction):
+
+    def __init__(self, action_info):
+        SimpleUndoableAction.__init__(self)
+        self.action_info = action_info
+
+    def asScenarioAction(self):
+        st = Gst.Structure.new_empty("set-control-source")
+        for key, value in self.action_info.items():
+            st.set_value(key, value)
+        st.set_value("binding-type", "direct")
+        st.set_value("source-type", "interpolation")
+        st.set_value("interpolation-mode", "linear")
+        return st
+
+
 class TimelineObserver(Loggable):
     """Monitors a project's timeline and reports UndoableActions.
 
@@ -437,10 +454,9 @@ class TimelineObserver(Loggable):
         action_log (UndoableActionLog): The action log where to report actions.
     """
 
-    def __init__(self, action_log, app):
+    def __init__(self, action_log):
         Loggable.__init__(self)
         self.action_log = action_log
-        self.app = app
         self.clip_property_trackers = {}
         self.layer_observers = {}
         self.keyframe_observers = {}
@@ -502,11 +518,14 @@ class TimelineObserver(Loggable):
 
     def _controlBindingAddedCb(self, track_element, binding):
         self._connectToControlSource(track_element, binding)
+        action_info = {"element-name": track_element.get_name(),
+                       "property-name": binding.props.name}
+        action = ControlSourceSetAction(action_info)
+        self.action_log.push(action)
 
     def _connectToTrackElement(self, track_element):
         for prop, binding in track_element.get_all_control_bindings().items():
-            self._connectToControlSource(track_element, binding,
-                                         existed=True)
+            self._connectToControlSource(track_element, binding)
         track_element.connect("control-binding-added",
                               self._controlBindingAddedCb)
         if isinstance(track_element, GES.BaseEffect) or \
@@ -522,7 +541,7 @@ class TimelineObserver(Loggable):
         if observer:
             observer.release()
 
-    def _connectToControlSource(self, track_element, binding, existed=False):
+    def _connectToControlSource(self, track_element, binding):
         control_source = binding.props.control_source
         action_info = {"element-name": track_element.get_name(),
                        "property-name": binding.props.name}
@@ -530,13 +549,6 @@ class TimelineObserver(Loggable):
                                          action_info)
         self.keyframe_observers[control_source] = observer
 
-        if not existed:
-            properties = {"binding-type": "direct",
-                          "source-type": "interpolation",
-                          "interpolation-mode": "linear"}
-            properties.update(action_info)
-            self.app.write_action("set-control-source", properties)
-
     def _disconnectFromControlSource(self, binding):
         control_source = binding.props.control_source
         observer = self.keyframe_observers.pop(control_source)
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 988ddd6..c3409b9 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -61,6 +61,15 @@ class UndoableAction(GObject.Object, Loggable):
         raise NotImplementedError()
 
 
+class SimpleUndoableAction(UndoableAction):
+
+    def do(self):
+        pass
+
+    def undo(self):
+        pass
+
+
 class FinalizingAction:
     """
     Base class for actions to happen when an UndoableActionStack is
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index 62377b3..52bbb20 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -59,7 +59,7 @@ class TestTimelineLogObserver(TestCase):
 
     def setUp(self):
         self.action_log = UndoableActionLog()
-        self.observer = TimelineObserverSpy(self.action_log, app=mock.Mock())
+        self.observer = TimelineObserverSpy(self.action_log)
 
     def testConnectionAndDisconnection(self):
         timeline = GES.Timeline.new_audio_video()


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