[pitivi] timeline: Move the zoom_fitted field to Timeline



commit 1c1e57a93e9ef1e3196475ea91c4cd9acd4f3560
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Oct 13 20:50:16 2016 +0200

    timeline: Move the zoom_fitted field to Timeline
    
    It does not make sense to keep it in the TimelineContainer since the
    Timeline is zoom fitted, not the container. Moreover, this allows
    getting rid of Timeline.parent which is not needed anymore.
    
    When setting the best zoom ratio the Timeline is always scrolled to the
    start. This was not the case when inserting clips.
    
    Reviewed-by: Thibault Saunier <tsaunier gnome org>
    Differential Revision: https://phabricator.freedesktop.org/D1389

 pitivi/timeline/elements.py     |    2 +-
 pitivi/timeline/timeline.py     |  122 ++++++++++++++++++---------------------
 pitivi/utils/validate.py        |   10 ++--
 pitivi/utils/widgets.py         |    2 +-
 tests/common.py                 |   19 ++++++
 tests/test_timeline_elements.py |   28 +++++----
 tests/test_timeline_layer.py    |    2 +-
 tests/test_timeline_timeline.py |   95 ++++++++++++++----------------
 tests/test_undo_timeline.py     |    4 +-
 9 files changed, 146 insertions(+), 138 deletions(-)
---
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 766106d..d7081b2 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -1023,7 +1023,7 @@ class Clip(Gtk.EventBox, Zoomable, Loggable):
 
         # TODO : Let's be more specific, masks etc ..
         mode = SELECT
-        if self.timeline.parent._controlMask:
+        if self.timeline.get_parent()._controlMask:
             if not self.get_state_flags() & Gtk.StateFlags.SELECTED:
                 mode = SELECT_ADD
                 self.timeline.current_group.add(
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 35b3ece..960273f 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -265,18 +265,16 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
     """Container for the the layers controls and representation.
 
     Attributes:
-        parent (TimelineContainer): The parent widget.
         _project (Project): The project.
     """
 
     __gtype_name__ = "PitiviTimeline"
 
-    def __init__(self, container, app, size_group=None):
+    def __init__(self, app, size_group=None):
         Gtk.EventBox.__init__(self)
         Zoomable.__init__(self)
         Loggable.__init__(self)
 
-        self.parent = container
         self.app = app
         self._project = None
         self.ges_timeline = None
@@ -320,6 +318,10 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         # A lot of operations go through these callbacks.
         self.add_events(Gdk.EventType.BUTTON_PRESS | Gdk.EventType.BUTTON_RELEASE)
 
+        # Whether the entire timeline content is in view and
+        # it should be kept that way if it makes sense.
+        self.zoomed_fitted = True
+
         self._layers = []
         # Whether the user is dragging a layer.
         self.__moving_layer = None
@@ -854,7 +856,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
     def _drag_drop_cb(self, unused_widget, context, x, y, timestamp):
         # Same as in insertEnd: this value changes during insertion, snapshot
         # it
-        zoom_was_fitted = self.parent.zoomed_fitted
+        zoom_was_fitted = self.zoomed_fitted
 
         target = self.drag_dest_find_target(context, None).name()
         success = True
@@ -875,7 +877,8 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
                         layer.add_clip(clip)
 
                 if zoom_was_fitted:
-                    self.parent._setBestZoomRatio()
+                    self.set_best_zoom_ratio()
+
                 self.dragEnd()
         else:
             success = False
@@ -961,9 +964,50 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
     # Interface Zoomable
     def zoomChanged(self):
+        if not self.ges_timeline:
+            # Probably the app starts and there is no project/timeline yet.
+            return
+
+        self.ges_timeline.set_snapping_distance(
+            Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband))
+        self.zoomed_fitted = False
+
         self.updatePosition()
         self.queue_draw()
 
+    def set_best_zoom_ratio(self, allow_zoom_in=False):
+        """Sets the zoom level so that the entire timeline is in view."""
+        duration = 0 if not self.ges_timeline else self.ges_timeline.get_duration()
+        if not duration:
+            return
+
+        # Add Gst.SECOND - 1 to the timeline duration to make sure the
+        # last second of the timeline will be in view.
+        timeline_duration = duration + Gst.SECOND - 1
+        timeline_duration_s = int(timeline_duration / Gst.SECOND)
+        self.debug("Adjusting zoom for a timeline duration of %s secs",
+                   timeline_duration_s)
+
+        zoom_ratio = self.layout.get_allocation().width / timeline_duration_s
+        nearest_zoom_level = Zoomable.computeZoomLevel(zoom_ratio)
+        if nearest_zoom_level >= Zoomable.getCurrentZoomLevel():
+            # This means if we continue we'll zoom in.
+            if not allow_zoom_in:
+                # For example when the user zoomed out and is adding clips
+                # to the timeline, zooming in would be confusing.
+                self.log("The entire timeline is already visible")
+                return
+
+        Zoomable.setZoomLevel(nearest_zoom_level)
+        self.ges_timeline.set_snapping_distance(
+            Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband))
+
+        # Only do this at the very end, after updating the other widgets.
+        self.log("Setting 'zoomed_fitted' to True")
+        self.zoomed_fitted = True
+
+        self.hadj.set_value(0)
+
     def __getEditingMode(self):
         if not self.editing_context:
             is_handle = False
@@ -1174,10 +1218,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         self._shiftMask = False
         self._controlMask = False
 
-        # Whether the entire content is in the timeline view, in which case
-        # it should be kept that way if it makes sense.
-        self.zoomed_fitted = True
-
         self._project = None
         self.ges_timeline = None
         self.__copiedGroup = None
@@ -1234,9 +1274,8 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
 
         # We need to snapshot this value, because we only do the zoom fit at the
         # end of clip insertion, but inserting multiple clips eventually changes
-        # the value of self.zoomed_fitted as clips get progressively
-        # inserted...
-        zoom_was_fitted = self.zoomed_fitted
+        # the value of zoomed_fitted as clips get progressively inserted.
+        zoom_was_fitted = self.timeline.zoomed_fitted
 
         initial_position = self.__getInsertPosition(position)
         clip_position = initial_position
@@ -1265,7 +1304,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
                 clip_position += duration
 
         if zoom_was_fitted:
-            self._setBestZoomRatio()
+            self.timeline.set_best_zoom_ratio()
         else:
             self.scrollToPixel(Zoomable.nsToPixel(initial_position))
 
@@ -1285,12 +1324,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
                     layer.remove_clip(clip)
         self._project.pipeline.commit_timeline()
 
-    def zoomFit(self):
-        self.app.write_action("zoom-fit", {"optional-action-type": True})
-
-        self._setBestZoomRatio(allow_zoom_in=True)
-        self.timeline.hadj.set_value(0)
-
     def scrollToPixel(self, x):
         if x > self.timeline.hadj.props.upper:
             # We can't scroll yet, because the canvas needs to be updated
@@ -1333,7 +1366,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         zoom_box = ZoomBox(self)
         left_size_group.add_widget(zoom_box)
 
-        self.timeline = Timeline(self, self.app, left_size_group)
+        self.timeline = Timeline(self.app, left_size_group)
 
         vscrollbar = Gtk.VScrollbar(adjustment=self.timeline.vadj)
         vscrollbar.get_style_context().add_class("background")
@@ -1499,40 +1532,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
                                ["<Shift>Right"],
                                _("Seek forward one second"))
 
-    def _setBestZoomRatio(self, allow_zoom_in=False):
-        """Sets the zoom level so that the entire timeline is in view."""
-        ruler_width = self.ruler.get_allocation().width
-        duration = 0 if not self.ges_timeline else self.ges_timeline.get_duration()
-        if not duration:
-            return
-
-        # Add Gst.SECOND - 1 to the timeline duration to make sure the
-        # last second of the timeline will be in view.
-        timeline_duration = duration + Gst.SECOND - 1
-        timeline_duration_s = int(timeline_duration / Gst.SECOND)
-        self.debug(
-            "Adjusting zoom for a timeline duration of %s secs", timeline_duration_s)
-
-        ideal_zoom_ratio = float(ruler_width) / timeline_duration_s
-        nearest_zoom_level = Zoomable.computeZoomLevel(ideal_zoom_ratio)
-        if nearest_zoom_level >= Zoomable.getCurrentZoomLevel():
-            # This means if we continue we'll zoom in.
-            if not allow_zoom_in:
-                # For example when the user zoomed out and is adding clips
-                # to the timeline, zooming in would be confusing.
-                self.log(
-                    "Zoom not changed because the entire timeline is already visible")
-
-                return
-
-        Zoomable.setZoomLevel(nearest_zoom_level)
-        self.ges_timeline.set_snapping_distance(
-            Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
-
-        # Only do this at the very end, after updating the other widgets.
-        self.log("Setting 'zoomed_fitted' to True")
-        self.zoomed_fitted = True
-
     def _scrollToPixel(self, x):
         hadj = self.timeline.hadj
         self.log("Scroll to: %s %s %s", x, hadj.props.lower, hadj.props.upper)
@@ -1696,15 +1695,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
     def _playPauseCb(self, unused_action, unused_parameter):
         self._project.pipeline.togglePlayback()
 
-    # Zoomable
-
-    def zoomChanged(self):
-        if self.ges_timeline:
-            # zoomChanged might be called various times before the UI is ready
-            self.ges_timeline.set_snapping_distance(
-                Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
-        self.zoomed_fitted = False
-
     # Gtk widget virtual methods
 
     def do_key_press_event(self, event):
@@ -1791,7 +1781,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
             self.ruler.zoomChanged()
 
             self._renderingSettingsChangedCb(project, None, None)
-            self._setBestZoomRatio()
+            self.timeline.set_best_zoom_ratio()
             if self.ges_timeline:
                 self.ges_timeline.set_snapping_distance(
                     Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
@@ -1803,7 +1793,9 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         Zoomable.zoomOut()
 
     def _zoomFitCb(self, unused_action, unused_parameter):
-        self.zoomFit()
+        self.app.write_action("zoom-fit", {"optional-action-type": True})
+
+        self.timeline.set_best_zoom_ratio(allow_zoom_in=True)
 
     def _selectionChangedCb(self, selection):
         """Handles selection changing."""
diff --git a/pitivi/utils/validate.py b/pitivi/utils/validate.py
index 2cb1c86..7a5c37c 100644
--- a/pitivi/utils/validate.py
+++ b/pitivi/utils/validate.py
@@ -371,19 +371,19 @@ def editContainer(scenario, action):
 #     return True
 
 
-def splitClip(scenario, action):
+def split_clip(scenario, action):
     timeline = scenario.pipeline.props.timeline.ui
-    timeline.parent._splitCb(None)
+    timeline.get_parent()._splitCb(None, None)
 
     return True
 
 
 def zoom(scenario, action):
-    timeline = scenario.pipeline.props.timeline.ui
+    timeline = scenario.pipeline.props.timeline
 
     GstValidate.print_action(action, action.type.replace('-', ' ') + "\n")
 
-    {"zoom-fit": timeline.parent.zoomFit,
+    {"zoom-fit": timeline.ui.set_best_zoom_ratio,
      "zoom-out": Zoomable.zoomOut,
      "zoom-in": Zoomable.zoomIn}[action.type]()
 
@@ -534,7 +534,7 @@ def init():
                                          GstValidate.ActionTypeFlags.NONE)
 
         GstValidate.register_action_type("split-clip", "pitivi",
-                                         splitClip, None,
+                                         split_clip, None,
                                          "Split a clip",
                                          GstValidate.ActionTypeFlags.NONE)
 
diff --git a/pitivi/utils/widgets.py b/pitivi/utils/widgets.py
index 26d7d4a..55bf453 100644
--- a/pitivi/utils/widgets.py
+++ b/pitivi/utils/widgets.py
@@ -1075,7 +1075,7 @@ class ZoomBox(Gtk.Grid, Zoomable):
             self.timeline.timeline.scrollToPlayhead()
 
     def _zoomFitCb(self, unused_button):
-        self.timeline.zoomFit()
+        self.timeline.timeline.set_best_zoom_ratio()
 
     def _zoomSliderScrollCb(self, unused, event):
         delta = 0
diff --git a/tests/common.py b/tests/common.py
index 1afe84a..f221a15 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -34,6 +34,7 @@ from pitivi import check
 from pitivi.application import Pitivi
 from pitivi.project import ProjectManager
 from pitivi.settings import GlobalSettings
+from pitivi.timeline.timeline import TimelineContainer
 from pitivi.utils.loggable import Loggable
 from pitivi.utils.proxy import ProxyingStrategy
 from pitivi.utils.proxy import ProxyManager
@@ -86,6 +87,24 @@ def create_pitivi(**settings):
     return app
 
 
+def create_timeline_container():
+    app = create_pitivi_mock()
+    project_manager = ProjectManager(app)
+    project_manager.newBlankProject()
+    project = project_manager.current_project
+
+    timeline_container = TimelineContainer(app)
+    timeline_container.setProject(project)
+
+    timeline = timeline_container.timeline
+    timeline.app.project_manager.current_project = project
+    timeline.get_parent = mock.MagicMock(return_value=timeline_container)
+
+    timeline.app.settings.leftClickAlsoSeeks = False
+
+    return timeline_container
+
+
 def create_main_loop():
     mainloop = GLib.MainLoop()
     timed_out = False
diff --git a/tests/test_timeline_elements.py b/tests/test_timeline_elements.py
index 0e804ee..6b8ff48 100644
--- a/tests/test_timeline_elements.py
+++ b/tests/test_timeline_elements.py
@@ -20,19 +20,21 @@ from unittest import mock
 
 from gi.repository import GES
 
-from tests import common
+from tests.common import create_test_clip
+from tests.common import create_timeline_container
 from tests.test_timeline_timeline import BaseTestTimeline
 
 
 class TestKeyframeCurve(BaseTestTimeline):
 
     def test_keyframe_toggle(self):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         pipeline = timeline._project.pipeline
         self.addClipsSimple(timeline, 2)
         ges_layer = timeline.ges_timeline.get_layers()[0]
         # For variety, add TitleClip to the list of clips.
-        ges_clip = common.create_test_clip(GES.TitleClip)
+        ges_clip = create_test_clip(GES.TitleClip)
         ges_clip.props.duration = 4.5
         ges_layer.add_clip(ges_clip)
 
@@ -52,7 +54,7 @@ class TestKeyframeCurve(BaseTestTimeline):
             for offset in offsets:
                 position = start + offset
                 pipeline.getPosition = mock.Mock(return_value=position)
-                timeline.parent._keyframe_cb(None, None)
+                timeline_container._keyframe_cb(None, None)
                 values = [item.timestamp for item in control_source.get_all()]
                 self.assertIn(offset, values)
 
@@ -60,7 +62,7 @@ class TestKeyframeCurve(BaseTestTimeline):
             for offset in offsets:
                 position = start + offset
                 pipeline.getPosition = mock.Mock(return_value=position)
-                timeline.parent._keyframe_cb(None, None)
+                timeline_container._keyframe_cb(None, None)
                 values = [item.timestamp for item in control_source.get_all()]
                 self.assertNotIn(offset, values)
 
@@ -71,7 +73,7 @@ class TestKeyframeCurve(BaseTestTimeline):
                 pipeline.getPosition = mock.Mock(return_value=position)
                 values = [item.timestamp for item in control_source.get_all()]
                 self.assertIn(offset, values)
-                timeline.parent._keyframe_cb(None, None)
+                timeline_container._keyframe_cb(None, None)
                 values = [item.timestamp for item in control_source.get_all()]
                 self.assertIn(offset, values)
 
@@ -80,20 +82,22 @@ class TestKeyframeCurve(BaseTestTimeline):
                 position = min(max(0, start + offset),
                                timeline.ges_timeline.props.duration)
                 pipeline.getPosition = mock.Mock(return_value=position)
-                timeline.parent._keyframe_cb(None, None)
+                timeline_container._keyframe_cb(None, None)
                 values = [item.timestamp for item in control_source.get_all()]
                 self.assertEqual(values, [0, ges_clip.props.duration])
 
     def test_no_clip_selected(self):
         # When no clip is selected, pressing key should yield no action.
         # Make sure this does not raise any exception
-        timeline = self.createTimeline()
-        timeline.parent._keyframe_cb(None, None)
+        timeline_container = create_timeline_container()
+        timeline_container._keyframe_cb(None, None)
 
 
 class TestVideoSourceScaling(BaseTestTimeline):
+
     def test_video_source_scaling(self):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         project = timeline.app.project_manager.current_project
 
         clip = self.addClipsSimple(timeline, 1)[0]
@@ -147,8 +151,8 @@ class TestVideoSourceScaling(BaseTestTimeline):
                          expected_default_position)
 
     def test_rotation(self):
-        timeline = self.createTimeline()
-        project = timeline.app.project_manager.current_project
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
 
         clip = self.addClipsSimple(timeline, 1)[0]
 
diff --git a/tests/test_timeline_layer.py b/tests/test_timeline_layer.py
index 0ffe4ba..b09e650 100644
--- a/tests/test_timeline_layer.py
+++ b/tests/test_timeline_layer.py
@@ -58,5 +58,5 @@ class TestLayer(common.TestCase):
         video_clip = GES.UriClipAsset.request_sync(png).extract()
         self.assertTrue(ges_layer.add_clip(video_clip))
         self.assertEqual(len(ges_layer.get_clips()), 1)
-        timeline = Timeline(container=None, app=None)
+        timeline = Timeline(app=None)
         layer = Layer(ges_layer, timeline)
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index 0469670..7efe92b 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -22,11 +22,9 @@ from gi.repository import Gdk
 from gi.repository import GES
 from gi.repository import Gtk
 
-from pitivi.project import ProjectManager
-from pitivi.timeline.timeline import TimelineContainer
 from pitivi.utils import ui
 from tests import common
-
+from tests.common import create_timeline_container
 
 SEPARATOR_HEIGHT = 4
 THIN = ui.LAYER_HEIGHT / 2
@@ -35,23 +33,6 @@ THICK = ui.LAYER_HEIGHT
 
 class BaseTestTimeline(common.TestCase):
 
-    def createTimeline(self):
-        app = common.create_pitivi_mock()
-        project_manager = ProjectManager(app)
-        project_manager.newBlankProject()
-        project = project_manager.current_project
-
-        timeline_container = TimelineContainer(app)
-        timeline_container.setProject(project)
-
-        timeline = timeline_container.timeline
-        timeline.app.project_manager.current_project = project
-        timeline.get_parent = mock.MagicMock(return_value=timeline_container)
-
-        timeline.app.settings.leftClickAlsoSeeks = False
-
-        return timeline
-
     def addClipsSimple(self, timeline, num_clips):
         layer = timeline.ges_timeline.append_layer()
         asset = GES.UriClipAsset.request_sync(
@@ -95,7 +76,8 @@ class TestLayers(BaseTestTimeline):
                              [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2])
 
     def checkGetLayerAt(self, heights, preferred, past_middle_when_adjacent, expectations):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
 
         y = 0
         for priority, height in enumerate(heights):
@@ -151,7 +133,8 @@ class TestLayers(BaseTestTimeline):
         assertLayerAt(ges_layers[expectations[15]], h[0] + s + h[1] + s + h[2] - 1)
 
     def testSetSeparatorsPrelight(self):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         timeline.__on_separators = [mock.Mock()]
         timeline._setSeparatorsPrelight(False)
         self.assertEqual(len(timeline.__on_separators), 1,
@@ -160,13 +143,14 @@ class TestLayers(BaseTestTimeline):
 
 class TestGrouping(BaseTestTimeline):
 
-    def group_clips(self, timeline, clips):
+    def group_clips(self, timeline_container, clips):
+        timeline = timeline_container.timeline
         timeline.app.settings.leftClickAlsoSeeks = False
 
         # Press <ctrl> so selecting in ADD mode
         event = mock.Mock()
         event.keyval = Gdk.KEY_Control_L
-        timeline.parent.do_key_press_event(event)
+        timeline_container.do_key_press_event(event)
 
         # Select the 2 clips
         for clip in clips:
@@ -177,7 +161,7 @@ class TestGrouping(BaseTestTimeline):
         for clip in clips:
             self.assertEqual(clip.get_parent(), timeline.current_group)
 
-        timeline.parent.group_action.emit("activate", None)
+        timeline_container.group_action.emit("activate", None)
 
         self.assertNotEqual(timeline.current_group, before_grouping_timeline_group)
         for clip in clips:
@@ -197,15 +181,17 @@ class TestGrouping(BaseTestTimeline):
         self.assertEqual(len(group.get_children(False)), len(clips))
 
     def testGroup(self):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         clips = self.addClipsSimple(timeline, 2)
-        self.group_clips(timeline, clips)
+        self.group_clips(timeline_container, clips)
 
     def testGroupSelection(self):
         num_clips = 2
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         clips = self.addClipsSimple(timeline, num_clips)
-        self.group_clips(timeline, clips)
+        self.group_clips(timeline_container, clips)
         layer = timeline.ges_timeline.get_layers()[0]
         clips = layer.get_clips()
         self.assertEqual(len(clips), num_clips)
@@ -220,13 +206,14 @@ class TestGrouping(BaseTestTimeline):
 
     def testGroupUngroup(self):
         num_clips = 2
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         clips = self.addClipsSimple(timeline, num_clips)
-        self.group_clips(timeline, clips)
+        self.group_clips(timeline_container, clips)
 
         self.assertEqual(len(timeline.selection.selected), num_clips)
 
-        timeline.parent.ungroup_action.emit("activate", None)
+        timeline_container.ungroup_action.emit("activate", None)
         layer = timeline.ges_timeline.get_layers()[0]
         clips = layer.get_clips()
         self.assertEqual(len(clips), num_clips)
@@ -237,7 +224,8 @@ class TestGrouping(BaseTestTimeline):
     def testGroupSplittedClipAndSelectGroup(self):
         position = 5
 
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         clips = self.addClipsSimple(timeline, 1)
         self.toggle_clip_selection(clips[0], expect_selected=True)
 
@@ -245,7 +233,7 @@ class TestGrouping(BaseTestTimeline):
         layer = timeline.ges_timeline.get_layers()[0]
 
         # Split
-        timeline.parent.split_action.emit("activate", None)
+        timeline_container.split_action.emit("activate", None)
         clips = layer.get_clips()
         self.assertEqual(len(clips), 2)
 
@@ -256,25 +244,26 @@ class TestGrouping(BaseTestTimeline):
 
         event = mock.Mock()
         event.keyval = Gdk.KEY_Control_L
-        timeline.parent.do_key_press_event(event)
+        timeline_container.do_key_press_event(event)
         self.toggle_clip_selection(clips[1], expect_selected=True)
-        timeline.parent.do_key_release_event(event)
+        timeline_container.do_key_release_event(event)
 
         for clip in clips:
             self.assertTrue(clip.selected.selected)
 
         # Group the two parts
-        timeline.parent.group_action.emit("activate", None)
+        timeline_container.group_action.emit("activate", None)
 
         self.toggle_clip_selection(clips[1], expect_selected=True)
 
     def testUngroupClip(self):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         ges_clip, = self.addClipsSimple(timeline, 1)
 
         self.toggle_clip_selection(ges_clip, expect_selected=True)
 
-        timeline.parent.ungroup_action.emit("activate", None)
+        timeline_container.ungroup_action.emit("activate", None)
         layer = timeline.ges_timeline.get_layers()[0]
         ges_clip0, ges_clip1 = layer.get_clips()
 
@@ -301,7 +290,8 @@ class TestGrouping(BaseTestTimeline):
 
     def test_dragging_group_on_separator(self):
         # Create two clips on different layers and group them.
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         clip1, = self.addClipsSimple(timeline, 1)
         layer1 = clip1.get_layer()
 
@@ -309,7 +299,7 @@ class TestGrouping(BaseTestTimeline):
         clip2, = self.addClipsSimple(timeline, 1)
         self.assertEqual(len(timeline.ges_timeline.get_layers()), 2)
 
-        self.group_clips(timeline, [clip1, clip2])
+        self.group_clips(timeline_container, [clip1, clip2])
 
         # Click the first clip in the group.
         with mock.patch.object(Gtk, 'get_event_widget') as get_event_widget:
@@ -341,30 +331,32 @@ class TestGrouping(BaseTestTimeline):
 class TestCopyPaste(BaseTestTimeline):
 
     def copyClips(self, num_clips):
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
 
         clips = self.addClipsSimple(timeline, num_clips)
 
         # Press <ctrl> so selecting in ADD mode
         event = mock.Mock()
         event.keyval = Gdk.KEY_Control_L
-        timeline.parent.do_key_press_event(event)
+        timeline_container.do_key_press_event(event)
 
         # Select the 2 clips
         for clip in clips:
             self.toggle_clip_selection(clip, expect_selected=True)
 
-        self.assertTrue(timeline.parent.copy_action.props.enabled)
-        self.assertFalse(timeline.parent.paste_action.props.enabled)
-        timeline.parent.copy_action.emit("activate", None)
-        self.assertTrue(timeline.parent.paste_action.props.enabled)
+        self.assertTrue(timeline_container.copy_action.props.enabled)
+        self.assertFalse(timeline_container.paste_action.props.enabled)
+        timeline_container.copy_action.emit("activate", None)
+        self.assertTrue(timeline_container.paste_action.props.enabled)
 
-        return timeline
+        return timeline_container
 
     def testCopyPaste(self):
         position = 20
 
-        timeline = self.copyClips(2)
+        timeline_container = self.copyClips(2)
+        timeline = timeline_container.timeline
 
         layer = timeline.ges_timeline.get_layers()[0]
         # Monkey patching the pipeline.getPosition method
@@ -374,7 +366,7 @@ class TestCopyPaste(BaseTestTimeline):
         clips = layer.get_clips()
         self.assertEqual(len(clips), 2)
 
-        timeline.parent.paste_action.emit("activate", None)
+        timeline_container.paste_action.emit("activate", None)
 
         n_clips = layer.get_clips()
         self.assertEqual(len(n_clips), 4)
@@ -389,7 +381,8 @@ class TestEditing(BaseTestTimeline):
 
     def test_trimming_on_layer_separator(self):
         # Create a clip
-        timeline = self.createTimeline()
+        timeline_container = create_timeline_container()
+        timeline = timeline_container.timeline
         clip, = self.addClipsSimple(timeline, 1)
         layer = clip.get_layer()
 
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index de2306b..b221e7c 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -82,7 +82,7 @@ class BaseTestUndoTimeline(TestCase):
 class TestTimelineObserver(BaseTestUndoTimeline):
 
     def test_layer_removed(self):
-        timeline_ui = Timeline(container=None, app=None)
+        timeline_ui = Timeline(app=None)
         timeline_ui.setProject(self.app.project_manager.current_project)
 
         layer1 = self.layer
@@ -163,7 +163,7 @@ class TestLayerObserver(BaseTestUndoTimeline):
         layer3 = self.timeline.append_layer()
         self.assertEqual(self.timeline.get_layers(), [layer1, layer2, layer3])
 
-        timeline_ui = Timeline(container=None, app=self.app)
+        timeline_ui = Timeline(app=self.app)
         timeline_ui.setProject(self.app.project_manager.current_project)
 
         # Click and drag a layer control box to move the layer.


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