[pitivi] timeline: Add a method for updating the snapping distance
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] timeline: Add a method for updating the snapping distance
- Date: Wed, 9 Nov 2016 13:12:47 +0000 (UTC)
commit a5524ec23d45e93afa886a8b2802c06382487db0
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Thu Oct 20 22:59:54 2016 +0200
timeline: Add a method for updating the snapping distance
Had to update two unit tests.
Reviewed-by: Thibault Saunier <tsaunier gnome org>
Differential Revision: https://phabricator.freedesktop.org/D1396
pitivi/timeline/timeline.py | 31 +++++++++++++++----------------
tests/test_timeline_layer.py | 24 +++++++++++++++---------
tests/test_undo_timeline.py | 3 +--
3 files changed, 31 insertions(+), 27 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 960273f..69db480 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -380,6 +380,9 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
self.connect("drag-drop", self._drag_drop_cb)
self.connect("drag-data-received", self._drag_data_received_cb)
+ self.app.settings.connect("edgeSnapDeadbandChanged",
+ self.__snap_distance_changed_cb)
+
def resetSelectionGroup(self):
self.debug("Reset selection group")
if self.current_group:
@@ -475,7 +478,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
if not pipeline.playing():
self.update_visible_overlays()
- # snapping indicator
def _snapCb(self, unused_timeline, unused_obj1, unused_obj2, position):
"""Handles a clip snap update operation."""
self.layout.snap_position = position
@@ -486,6 +488,15 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
self.layout.snap_position = 0
self.layout.queue_draw()
+ def update_snapping_distance(self):
+ """Updates the snapping distance of self.ges_timeline."""
+ self.ges_timeline.set_snapping_distance(
+ Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband))
+
+ def __snap_distance_changed_cb(self, unused_settings):
+ """Handles the change of the snapping distance by the user."""
+ self.update_snapping_distance()
+
# Gtk.Widget virtual methods implementation
def do_get_preferred_height(self):
natural_height = max(1, len(self._layers)) * (LAYER_HEIGHT + 20)
@@ -968,8 +979,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
# 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.update_snapping_distance()
self.zoomed_fitted = False
self.updatePosition()
@@ -999,8 +1009,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
return
Zoomable.setZoomLevel(nearest_zoom_level)
- self.ges_timeline.set_snapping_distance(
- Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband))
+ self.update_snapping_distance()
# Only do this at the very end, after updating the other widgets.
self.log("Setting 'zoomed_fitted' to True")
@@ -1225,9 +1234,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
self._createUi()
self._createActions()
- self._settings.connect("edgeSnapDeadbandChanged",
- self._snapDistanceChangedCb)
-
self.app.project_manager.connect("new-project-loaded",
self._projectLoadedCb)
@@ -1754,11 +1760,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
if item == "width" or item == "height" or item == "videorate":
project.update_restriction_caps()
- def _snapDistanceChangedCb(self, unused_settings):
- if self.ges_timeline:
- self.ges_timeline.set_snapping_distance(
- Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
-
def _projectLoadedCb(self, unused_project_manager, project):
"""Connects to the project's timeline and pipeline."""
if self._project:
@@ -1782,9 +1783,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
self._renderingSettingsChangedCb(project, None, None)
self.timeline.set_best_zoom_ratio()
- if self.ges_timeline:
- self.ges_timeline.set_snapping_distance(
- Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
+ self.timeline.update_snapping_distance()
def _zoomInCb(self, unused_action, unused_parameter):
Zoomable.zoomIn()
diff --git a/tests/test_timeline_layer.py b/tests/test_timeline_layer.py
index b09e650..911b80b 100644
--- a/tests/test_timeline_layer.py
+++ b/tests/test_timeline_layer.py
@@ -21,13 +21,14 @@ from unittest import mock
from gi.repository import GES
from pitivi.timeline.layer import Layer
-from pitivi.timeline.timeline import Timeline
-from tests import common
+from tests.common import create_timeline_container
+from tests.common import get_sample_uri
+from tests.common import TestCase
-class TestLayerControl(common.TestCase):
+class TestLayerControl(TestCase):
- def testName(self):
+ def test_name(self):
timeline = mock.MagicMock()
ges_layer = GES.Layer()
layer = Layer(ges_layer, timeline)
@@ -50,13 +51,18 @@ class TestLayerControl(common.TestCase):
self.assertEqual(layer.getName(), "Layer 0x")
-class TestLayer(common.TestCase):
+class TestLayer(TestCase):
- def testCheckMediaTypesWhenNoUI(self):
+ def test_check_media_types_when_no_control_ui(self):
ges_layer = GES.Layer()
- png = common.get_sample_uri("flat_colour1_640x480.png")
+ png = get_sample_uri("flat_colour1_640x480.png")
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(app=None)
- layer = Layer(ges_layer, timeline)
+ timeline_container = create_timeline_container()
+ timeline = timeline_container.timeline
+ # This will add widgets for the clips in ges_layer and
+ # the layer will use checkMediaTypes which updates the
+ # height of layer.control_ui, which now it should not be set.
+ self.assertFalse(hasattr(ges_layer, "control_ui"))
+ unused_layer = Layer(ges_layer, timeline)
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index b221e7c..c31eb0f 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -82,8 +82,7 @@ class BaseTestUndoTimeline(TestCase):
class TestTimelineObserver(BaseTestUndoTimeline):
def test_layer_removed(self):
- timeline_ui = Timeline(app=None)
- timeline_ui.setProject(self.app.project_manager.current_project)
+ self.setup_timeline_container()
layer1 = self.layer
layer2 = self.timeline.append_layer()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]