def test_paste_undo(self): """Checks a paste operation can be undone.""" self.setup_timeline_container() timeline = self.timeline_container.timeline project = timeline.ges_timeline.get_asset() # Create test clip clip = common.create_test_clip(GES.TitleClip) clip.props.start = 0 clip.props.duration = 10 self.layer.add_clip(clip) self.assertEqual(len(self.layer.get_clips()), 1) # Select the test clip event = mock.Mock() event.get_button.return_value = (True, 1) with mock.patch.object(Gtk, "get_event_widget") as get_event_widget: get_event_widget.return_value = clip.ui clip.ui.timeline._button_press_event_cb(None, event) clip.ui._button_release_event_cb(None, event) self.timeline_container.copy_action.emit("activate", None) position = 10 project.pipeline.getPosition = mock.Mock(return_value=position) self.timeline_container.paste_action.emit("activate", None) self.assertEqual(len(self.layer.get_clips()), 2) self.action_log.undo() self.assertEqual(len(self.layer.get_clips()), 1) self.action_log.redo() self.assertEqual(len(self.layer.get_clips()), 2)
def test_keyframe_toggle(self): """Checks keyframes toggling at the playhead position.""" timeline_container = common.create_timeline_container() timeline_container.app.action_log = UndoableActionLog() timeline = timeline_container.timeline ges_layer = timeline.ges_timeline.append_layer() ges_clip1 = self.add_clip(ges_layer, 0, duration=Gst.SECOND) ges_clip2 = self.add_clip(ges_layer, Gst.SECOND, duration=Gst.SECOND) ges_clip3 = self.add_clip(ges_layer, 2 * Gst.SECOND, inpoint=Gst.SECOND, duration=Gst.SECOND) # For variety, add TitleClip to the list of clips. ges_clip4 = common.create_test_clip(GES.TitleClip) ges_clip4.props.start = 3 * Gst.SECOND ges_clip4.props.duration = Gst.SECOND self.assertTrue(ges_layer.add_clip(ges_clip4)) self.check_keyframe_toggle(ges_clip1, timeline_container) self.check_keyframe_toggle(ges_clip2, timeline_container) self.check_keyframe_toggle(ges_clip3, timeline_container) self.check_keyframe_toggle(ges_clip4, timeline_container) self.check_keyframe_ui_toggle(ges_clip1, timeline_container) self.check_keyframe_ui_toggle(ges_clip2, timeline_container) self.check_keyframe_ui_toggle(ges_clip3, timeline_container) self.check_keyframe_ui_toggle(ges_clip4, timeline_container)
def test_keyframe_toggle(self): """Checks keyframes toggling at the playhead position.""" timeline_container = create_timeline_container() timeline_container.app.action_log = UndoableActionLog() timeline = timeline_container.timeline ges_layer = timeline.ges_timeline.append_layer() ges_clip1 = self.add_clip(ges_layer, 0, duration=2 * Gst.SECOND) ges_clip2 = self.add_clip(ges_layer, 10, duration=2 * Gst.SECOND) ges_clip3 = self.add_clip(ges_layer, 20, inpoint=100, duration=2 * Gst.SECOND) # For variety, add TitleClip to the list of clips. ges_clip4 = create_test_clip(GES.TitleClip) ges_clip4.props.start = 30 ges_clip4.props.duration = int(0.9 * Gst.SECOND) ges_layer.add_clip(ges_clip4) self.check_keyframe_toggle(ges_clip1, timeline_container) self.check_keyframe_toggle(ges_clip2, timeline_container) self.check_keyframe_toggle(ges_clip3, timeline_container) self.check_keyframe_toggle(ges_clip4, timeline_container) for ges_clip in [ges_clip1, ges_clip2, ges_clip3, ges_clip4]: self.check_keyframe_ui_toggle(ges_clip, timeline_container)
def test_can_group_ungroup(self): clip1 = common.create_test_clip(GES.UriClip) clip2 = common.create_test_clip(GES.UriClip) selection = Selection() self.assertFalse(selection) selection.setSelection([clip1], SELECT) self.assertFalse(selection.can_ungroup) self.assertFalse(selection.can_group) selection.setSelection([clip2], SELECT_ADD) self.assertTrue(selection.can_group) self.assertFalse(selection.can_ungroup) selection.setSelection([], SELECT) self.assertFalse(selection.can_group) self.assertFalse(selection.can_ungroup)
def test_keyframe_toggle(self): timeline = self.createTimeline() 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.props.duration = 4.5 ges_layer.add_clip(ges_clip) for ges_clip in ges_layer.get_clips(): start = ges_clip.props.start offsets = list(range(1, int(ges_clip.props.duration))) timeline.selection.select([ges_clip]) ges_video_source = None for child in ges_clip.get_children(recursive=False): if isinstance(child, GES.VideoSource): ges_video_source = child binding = ges_video_source.get_control_binding("alpha") control_source = binding.props.control_source # Test adding of keyframes. for offset in offsets: position = start + offset pipeline.getPosition = mock.Mock(return_value=position) timeline.parent._keyframe_cb(None, None) values = [item.timestamp for item in control_source.get_all()] self.assertIn(offset, values) # Test removing of keyframes. for offset in offsets: position = start + offset pipeline.getPosition = mock.Mock(return_value=position) timeline.parent._keyframe_cb(None, None) values = [item.timestamp for item in control_source.get_all()] self.assertNotIn(offset, values) # Make sure the keyframes at the start and end of the clip # cannot be toggled. for offset in [0, ges_clip.props.duration]: position = start + offset 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) values = [item.timestamp for item in control_source.get_all()] self.assertIn(offset, values) # Test out of clip range. for offset in [-1, ges_clip.props.duration + 1]: position = min(max(0, start + offset), timeline.ges_timeline.props.duration) pipeline.getPosition = mock.Mock(return_value=position) timeline.parent._keyframe_cb(None, None) values = [item.timestamp for item in control_source.get_all()] self.assertEqual(values, [0, ges_clip.props.duration])
def testGetSingleClip(self): selection = Selection() clip1 = common.create_test_clip(GES.UriClip) clip2 = common.create_test_clip(GES.TitleClip) # Selection empty. self.assertFalse(selection.getSingleClip(GES.TitleClip)) # Selection contains only a non-requested-type clip. selection.setSelection([clip1], SELECT) self.assertFalse(selection.getSingleClip(GES.TitleClip)) # Selection contains only requested-type clip. selection.setSelection([clip2], SELECT) self.assertEqual(clip2, selection.getSingleClip(GES.TitleClip)) # Selection contains more than one clip. selection.setSelection([clip1, clip2], SELECT) self.assertFalse(selection.getSingleClip(GES.UriClip))
def testGetSingleClip(self): selection = Selection() clip1 = common.create_test_clip(GES.UriClip) clip2 = common.create_test_clip(GES.TitleClip) # Selection empty. self.assertIsNone(selection.getSingleClip()) self.assertIsNone(selection.getSingleClip(GES.UriClip)) self.assertIsNone(selection.getSingleClip(GES.TitleClip)) selection.setSelection([clip1], SELECT) self.assertEqual(selection.getSingleClip(), clip1) self.assertEqual(selection.getSingleClip(GES.UriClip), clip1) self.assertIsNone(selection.getSingleClip(GES.TitleClip)) selection.setSelection([clip2], SELECT) self.assertEqual(selection.getSingleClip(), clip2) self.assertIsNone(selection.getSingleClip(GES.UriClip)) self.assertEqual(selection.getSingleClip(GES.TitleClip), clip2) selection.setSelection([clip1, clip2], SELECT) self.assertIsNone(selection.getSingleClip()) self.assertIsNone(selection.getSingleClip(GES.UriClip)) self.assertIsNone(selection.getSingleClip(GES.TitleClip))
def test_group_ungroup_clips(self): self.setup_timeline_container() clip1 = common.create_test_clip(GES.TitleClip) clip1.set_start(0 * Gst.SECOND) clip1.set_duration(1 * Gst.SECOND) uri = common.get_sample_uri("tears_of_steel.webm") asset = GES.UriClipAsset.request_sync(uri) clip2 = asset.extract() clip2.props.start = 1 * Gst.SECOND self.assertTrue(self.layer.add_clip(clip1)) self.assertTrue(self.layer.add_clip(clip2)) # The selection does not care about GES.Groups, only about GES.Clips. self.timeline_container.timeline.selection.select([clip1, clip2]) self.assertEqual(clip1.props.timeline, self.layer.get_timeline()) self.assertEqual(clip2.props.timeline, self.layer.get_timeline()) self.timeline_container.group_action.activate(None) self.assertTrue(isinstance(clip1.get_parent(), GES.Group)) self.assertEqual(clip1.get_parent(), clip2.get_parent()) self.timeline_container.ungroup_action.activate(None) self.assertIsNone(clip1.get_parent()) self.assertIsNone(clip2.get_parent()) for i in range(4): # Undo ungrouping. self.action_log.undo() self.assertTrue(isinstance(clip1.get_parent(), GES.Group)) self.assertEqual(clip1.get_parent(), clip2.get_parent()) # Undo grouping. self.action_log.undo() self.assertIsNone(clip1.get_parent()) self.assertIsNone(clip2.get_parent()) # Redo grouping. self.action_log.redo() self.assertTrue(isinstance(clip1.get_parent(), GES.Group)) self.assertEqual(clip1.get_parent(), clip2.get_parent()) # Redo ungrouping. self.action_log.redo() self.assertIsNone(clip1.get_parent()) self.assertIsNone(clip2.get_parent())
def test_keyframe_toggle(self): """Checks keyframes toggling at the playhead position.""" timeline_container = create_timeline_container() timeline = timeline_container.timeline ges_layer = timeline.ges_timeline.append_layer() ges_clip1 = self.add_clip(ges_layer, 0) ges_clip2 = self.add_clip(ges_layer, 10) ges_clip3 = self.add_clip(ges_layer, 20, inpoint=100) # For variety, add TitleClip to the list of clips. ges_clip4 = create_test_clip(GES.TitleClip) ges_clip4.props.start = 30 ges_clip4.props.duration = 4.5 ges_layer.add_clip(ges_clip4) self.check_keyframe_toggle(ges_clip1, timeline_container) self.check_keyframe_toggle(ges_clip2, timeline_container) self.check_keyframe_toggle(ges_clip3, timeline_container) self.check_keyframe_toggle(ges_clip4, timeline_container)
def test_insert_on_first_layer(self): self.setup_timeline_container() uri = common.get_sample_uri("tears_of_steel.webm") asset = GES.UriClipAsset.request_sync(uri) clip1 = asset.extract() self.timeline_container.insert_clips_on_first_layer(clips=[clip1], position=0) clips = list(self.getTimelineClips()) self.assertEqual(len(clips), 1, clips) # Undo insert on first layer self.action_log.undo() clips = list(self.getTimelineClips()) self.assertEqual(len(clips), 0, clips) # Redo insert on first layer self.action_log.redo() clips = list(self.getTimelineClips()) self.assertEqual(len(clips), 1, clips) # Insert new clip to create a layer clip2 = common.create_test_clip(GES.TitleClip) clip2.set_start(0 * Gst.SECOND) clip2.set_duration(1 * Gst.SECOND) self.timeline_container.insert_clips_on_first_layer(clips=[clip2], position=0) layers = self.timeline.get_layers() self.check_layers([layers[0], self.layer]) self.assertEqual(layers[0].get_clips(), [clip2]) self.assertEqual(layers[1].get_clips(), [clip1]) # Undo insert to create a layer self.action_log.undo() layers = self.timeline.get_layers() self.check_layers([self.layer]) self.assertEqual(layers[0].get_clips(), [clip1]) # Redo insert to create a layer self.action_log.redo() layers = self.timeline.get_layers() self.check_layers([layers[0], self.layer]) self.assertEqual(layers[0].get_clips(), [clip2]) self.assertEqual(layers[1].get_clips(), [clip1])
def test_keyframe_toggle(self): """Checks keyframes toggling at the playhead position.""" timeline_container = create_timeline_container() timeline_container.app.action_log = UndoableActionLog() timeline = timeline_container.timeline ges_layer = timeline.ges_timeline.append_layer() ges_clip1 = self.add_clip(ges_layer, 0, duration=2*Gst.SECOND) ges_clip2 = self.add_clip(ges_layer, 10, duration=2*Gst.SECOND) ges_clip3 = self.add_clip(ges_layer, 20, inpoint=100, duration=2*Gst.SECOND) # For variety, add TitleClip to the list of clips. ges_clip4 = create_test_clip(GES.TitleClip) ges_clip4.props.start = 30 ges_clip4.props.duration = int(0.9 * Gst.SECOND) ges_layer.add_clip(ges_clip4) self.check_keyframe_toggle(ges_clip1, timeline_container) self.check_keyframe_toggle(ges_clip2, timeline_container) self.check_keyframe_toggle(ges_clip3, timeline_container) self.check_keyframe_toggle(ges_clip4, timeline_container) for ges_clip in [ges_clip1, ges_clip2, ges_clip3, ges_clip4]: self.check_keyframe_ui_toggle(ges_clip, timeline_container)