[pitivi] timeline: Fix unsetting of __on_separators
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] timeline: Fix unsetting of __on_separators
- Date: Thu, 6 Oct 2016 09:57:51 +0000 (UTC)
commit 564550e5d5869873f882c729f401ce86ce1b466a
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Mon Oct 3 15:58:49 2016 +0200
timeline: Fix unsetting of __on_separators
Should have been part of c72e8c1fdc646b9ad5dfb1b121437e3b3ea21651
Reviewed-by: Thibault Saunier <tsaunier gnome org>
Differential Revision: https://phabricator.freedesktop.org/D1344
pitivi/timeline/timeline.py | 9 +++++-
tests/test_timeline_timeline.py | 58 +++++++++++++++++++++++++++++++++------
tests/test_undo_timeline.py | 18 ++++--------
3 files changed, 62 insertions(+), 23 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index e7e542b..ec2265f 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -278,9 +278,14 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
self.editing_context = None
# Whether draggingElement really got dragged.
self.__got_dragged = False
+ # The x of the event which starts the drag operation.
self.__drag_start_x = 0
- self.__on_separators = []
+ # The current layer on which the operation is performed.
self._on_layer = None
+ # The one or two separators immediately above or below _on_layer
+ # on which the operation will be performed.
+ # Implies a new layer will be created.
+ self.__on_separators = []
# Drag & dropping assets from outside.
@@ -1077,7 +1082,7 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
self.current_group.props.height > 1):
# When dragging clips from more than one layer, do not allow
# them to be dragged between layers to create a new layer.
- on_separators = []
+ self.__on_separators = []
self._setSeparatorsPrelight(True)
priority = self._on_layer.props.priority
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index 0a5bb55..dc87c03 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -161,10 +161,8 @@ class TestLayers(BaseTestTimeline):
class TestGrouping(BaseTestTimeline):
- def groupClips(self, num_clips):
- timeline = self.createTimeline()
+ def group_clips(self, timeline, clips):
timeline.app.settings.leftClickAlsoSeeks = False
- clips = self.addClipsSimple(timeline, num_clips)
# Press <ctrl> so selecting in ADD mode
timeline.sendFakeEvent(Event(event_type=Gdk.EventType.KEY_PRESS,
@@ -196,16 +194,18 @@ class TestGrouping(BaseTestTimeline):
self.assertTrue(clip.selected.selected)
group = clips[0].get_parent()
- self.assertEqual(len(group.get_children(False)), num_clips)
-
- return timeline
+ self.assertEqual(len(group.get_children(False)), len(clips))
def testGroup(self):
- self.groupClips(2)
+ timeline = self.createTimeline()
+ clips = self.addClipsSimple(timeline, 2)
+ self.group_clips(timeline, clips)
def testGroupSelection(self):
num_clips = 2
- timeline = self.groupClips(num_clips)
+ timeline = self.createTimeline()
+ clips = self.addClipsSimple(timeline, num_clips)
+ self.group_clips(timeline, clips)
layer = timeline.ges_timeline.get_layers()[0]
clips = layer.get_clips()
self.assertEqual(len(clips), num_clips)
@@ -220,7 +220,9 @@ class TestGrouping(BaseTestTimeline):
def testGroupUngroup(self):
num_clips = 2
- timeline = self.groupClips(num_clips)
+ timeline = self.createTimeline()
+ clips = self.addClipsSimple(timeline, num_clips)
+ self.group_clips(timeline, clips)
self.assertEqual(len(timeline.selection.selected), num_clips)
@@ -297,6 +299,44 @@ class TestGrouping(BaseTestTimeline):
self.assertEqual(aclip._audioSource, atrackelem)
self.assertEqual(vclip._videoSource, vtrackelem)
+ def test_dragging_group_on_separator(self):
+ # Create two clips on different layers and group them.
+ timeline = self.createTimeline()
+ clip1, = self.addClipsSimple(timeline, 1)
+ layer1 = clip1.get_layer()
+
+ # Add another clip on a new layer.
+ clip2, = self.addClipsSimple(timeline, 1)
+ self.assertEqual(len(timeline.ges_timeline.get_layers()), 2)
+
+ self.group_clips(timeline, [clip1, clip2])
+
+ # Click the first clip in the group.
+ with mock.patch.object(timeline, 'get_event_widget') as get_event_widget:
+ event = mock.Mock()
+ event.x = 0
+ event.get_button.return_value = True, 1
+ get_event_widget.return_value = clip1.ui
+ timeline._button_press_event_cb(None, event)
+ self.assertIsNotNone(timeline.draggingElement)
+
+ # Move it to the right, on the separator below.
+ event = mock.Mock()
+ event.get_state.return_value = Gdk.ModifierType.BUTTON1_MASK
+ with mock.patch.object(clip1.ui, "translate_coordinates") as translate_coordinates:
+ translate_coordinates.return_value = (40, 0)
+ with mock.patch.object(timeline, "_get_layer_at") as _get_layer_at:
+ _get_layer_at.return_value = layer1, [layer1.ui.after_sep]
+ timeline._motion_notify_event_cb(None, event)
+ self.assertTrue(timeline.got_dragged)
+
+ # Release the mouse button.
+ event = mock.Mock()
+ event.get_button.return_value = True, 1
+ timeline._button_release_event_cb(None, event)
+ self.assertEqual(len(timeline.ges_timeline.get_layers()), 2,
+ "No new layer should have been created")
+
class TestCopyPaste(BaseTestTimeline):
diff --git a/tests/test_undo_timeline.py b/tests/test_undo_timeline.py
index 70287e4..57229b8 100644
--- a/tests/test_undo_timeline.py
+++ b/tests/test_undo_timeline.py
@@ -661,16 +661,14 @@ class TestGObjectObserver(BaseTestUndoTimeline):
class TestDragDropUndo(BaseTestUndoTimeline):
def test_clip_dragged_to_create_layer(self):
+ self.setup_timeline_container()
+ timeline_ui = self.timeline_container.timeline
layers = self.timeline.get_layers()
self.assertEqual(len(layers), 1)
clip = GES.TitleClip()
self.layer.add_clip(clip)
- timeline_ui = Timeline(None, self.app)
- timeline_ui.setProject(self.app.project_manager.current_project)
- timeline_ui.get_parent = mock.MagicMock()
-
# Drag a clip on a separator to create a layer.
timeline_ui.get_event_widget = mock.Mock(return_value=clip.ui)
event = mock.Mock()
@@ -709,20 +707,16 @@ class TestDragDropUndo(BaseTestUndoTimeline):
def test_media_library_asset_dragged_on_separator(self):
"""Simulate dragging an asset from the media library to the timeline."""
+ self.setup_timeline_container()
+ timeline_ui = self.timeline_container.timeline
project = self.app.project_manager.current_project
+ layers = self.timeline.get_layers()
+ self.assertEqual(len(layers), 1)
uri = common.get_sample_uri("tears_of_steel.webm")
asset = GES.UriClipAsset.request_sync(uri)
self.assertTrue(project.add_asset(asset))
- timeline_ui = Timeline(container=None, app=self.app)
- timeline_ui.setProject(project)
- timeline_ui.get_parent = mock.MagicMock()
- timeline_ui.parent = mock.MagicMock()
-
- layers = self.timeline.get_layers()
- self.assertEqual(len(layers), 1)
-
# Events emitted while dragging an asset on a separator in the timeline:
# motion, receive, motion, leave, drop.
with mock.patch.object(Gdk, "drag_status") as drag_status_mock:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]