Ejemplo n.º 1
0
    def test_clip_deselect(self):
        timeline_container = common.create_timeline_container()
        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)

        # Select clip1 to show its keyframes widget.
        timeline.selection.select([ges_clip1])
        # Select both clips. Now clip1 still has the keyframes visible.
        timeline.selection.select([ges_clip1, ges_clip2])

        ges_video_source = ges_clip1.find_track_element(None, GES.VideoSource)
        binding = ges_video_source.get_control_binding("alpha")
        control_source = binding.props.control_source
        keyframe_curve = ges_video_source.ui.keyframe_curve

        # Simulate a mouse click.
        xdata, ydata = 1, LAYER_HEIGHT // 2
        x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

        event = MouseEvent(name="button_press_event",
                           canvas=keyframe_curve,
                           x=x,
                           y=y,
                           button=1)
        keyframe_curve.translate_coordinates = mock.Mock(return_value=(1,
                                                                       None))

        with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
            get_event_widget.return_value = keyframe_curve
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)

            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)

        self.assertListEqual(
            [item.timestamp for item in control_source.get_all()],
            [0, 1000000000])
Ejemplo n.º 2
0
    def check_keyframe_ui_toggle(self, ges_clip, timeline_container):
        """Checks keyframes toggling by click events."""
        timeline = timeline_container.timeline

        start = ges_clip.props.start
        start_px = Zoomable.nsToPixel(start)
        inpoint = ges_clip.props.in_point
        duration = ges_clip.props.duration
        duration_px = Zoomable.nsToPixel(duration)
        offsets_px = (1, int(duration_px / 2), int(duration_px) - 1)
        timeline.selection.select([ges_clip])

        ges_video_source = ges_clip.find_track_element(None, GES.VideoSource)
        binding = ges_video_source.get_control_binding("alpha")
        control_source = binding.props.control_source
        keyframe_curve = ges_video_source.ui.keyframe_curve

        values = [item.timestamp for item in control_source.get_all()]
        self.assertEqual(values, [inpoint, inpoint + duration])

        # Add keyframes by simulating mouse clicks.
        for offset_px in offsets_px:
            offset = Zoomable.pixelToNs(start_px + offset_px) - start
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(name="button_press_event",
                               canvas=keyframe_curve,
                               x=x,
                               y=y,
                               button=1)
            keyframe_curve.translate_coordinates = \
                mock.Mock(return_value=(start_px + offset_px, None))

            with mock.patch.object(Gtk,
                                   "get_event_widget") as get_event_widget:
                get_event_widget.return_value = keyframe_curve
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.name = "button_release_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
                keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertIn(inpoint + offset, values)

        # Remove keyframes by simulating mouse double-clicks.
        for offset_px in offsets_px:
            offset = Zoomable.pixelToNs(start_px + offset_px) - start
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(name="button_press_event",
                               canvas=keyframe_curve,
                               x=x,
                               y=y,
                               button=1)
            keyframe_curve.translate_coordinates = \
                mock.Mock(return_value=(start_px + offset_px, None))
            with mock.patch.object(Gtk,
                                   "get_event_widget") as get_event_widget:
                get_event_widget.return_value = keyframe_curve
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.name = "button_release_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
                keyframe_curve._mpl_button_release_event_cb(event)
                event.name = "button_press_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.guiEvent = Gdk.Event.new(Gdk.EventType._2BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.name = "button_release_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
                keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertNotIn(inpoint + offset, values)
Ejemplo n.º 3
0
    def check_keyframe_ui_toggle(self, ges_clip, timeline_container):
        """Checks keyframes toggling by click events."""
        timeline = timeline_container.timeline

        start = ges_clip.props.start
        start_px = Zoomable.nsToPixel(start)
        inpoint = ges_clip.props.in_point
        duration = ges_clip.props.duration
        duration_px = Zoomable.nsToPixel(duration)
        offsets_px = (1, int(duration_px / 2), int(duration_px) - 1)
        timeline.selection.select([ges_clip])

        ges_video_source = ges_clip.find_track_element(None, GES.VideoSource)
        binding = ges_video_source.get_control_binding("alpha")
        control_source = binding.props.control_source
        keyframe_curve = ges_video_source.ui.keyframe_curve

        values = [item.timestamp for item in control_source.get_all()]
        self.assertEqual(values, [inpoint, inpoint + duration])

        # Add keyframes by simulating mouse clicks.
        for offset_px in offsets_px:
            offset = Zoomable.pixelToNs(start_px + offset_px) - start
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(
                name="button_press_event",
                canvas=keyframe_curve,
                x=x,
                y=y,
                button=1
            )
            keyframe_curve.translate_coordinates = \
                mock.Mock(return_value=(start_px+offset_px, None))

            with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
                get_event_widget.return_value = keyframe_curve
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.name = "button_release_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
                keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertIn(inpoint + offset, values)

        # Remove keyframes by simulating mouse double-clicks.
        for offset_px in offsets_px:
            offset = Zoomable.pixelToNs(start_px + offset_px) - start
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(
                name="button_press_event",
                canvas=keyframe_curve,
                x=x,
                y=y,
                button=1
            )
            keyframe_curve.translate_coordinates = \
                mock.Mock(return_value=(start_px + offset_px, None))
            with mock.patch.object(Gtk, "get_event_widget") as get_event_widget:
                get_event_widget.return_value = keyframe_curve
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.name = "button_release_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
                keyframe_curve._mpl_button_release_event_cb(event)
                event.name = "button_press_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.guiEvent = Gdk.Event.new(Gdk.EventType._2BUTTON_PRESS)
                keyframe_curve._mpl_button_press_event_cb(event)
                event.name = "button_release_event"
                event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
                keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertNotIn(inpoint + offset, values)
Ejemplo n.º 4
0
    def check_keyframe_ui_toggle(self, ges_clip, timeline_container):
        """Checks keyframes toggling by click events."""
        timeline = timeline_container.timeline

        inpoint = ges_clip.props.in_point
        duration = ges_clip.props.duration
        offsets = (1, int(duration / 2), int(duration) - 1)
        timeline.selection.select([ges_clip])

        ges_video_source = ges_clip.find_track_element(None, GES.VideoSource)
        binding = ges_video_source.get_control_binding("alpha")
        control_source = binding.props.control_source
        keyframe_curve = ges_video_source.ui.keyframe_curve

        values = [item.timestamp for item in control_source.get_all()]
        self.assertEqual(values, [inpoint, inpoint + duration])

        # Add keyframes.
        for offset in offsets:
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(name="button_press_event",
                               canvas=keyframe_curve,
                               x=x,
                               y=y,
                               button=1)
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertIn(inpoint + offset, values)

        # Remove keyframes.
        for offset in offsets:
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(name="button_press_event",
                               canvas=keyframe_curve,
                               x=x,
                               y=y,
                               button=1)
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)
            event.name = "button_press_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.guiEvent = Gdk.Event.new(Gdk.EventType._2BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertNotIn(inpoint + offset, values)
Ejemplo n.º 5
0
    def test_axis_lock(self):
        """Checks keyframes moving."""
        timeline_container = common.create_timeline_container()
        timeline_container.app.action_log = UndoableActionLog()
        timeline = timeline_container.timeline
        timeline.get_window = mock.Mock()
        pipeline = timeline._project.pipeline
        ges_layer = timeline.ges_timeline.append_layer()
        ges_clip = self.add_clip(ges_layer, 0, duration=Gst.SECOND)

        start = ges_clip.props.start
        inpoint = ges_clip.props.in_point
        duration = ges_clip.props.duration
        timeline.selection.select([ges_clip])

        ges_video_source = ges_clip.find_track_element(None, GES.VideoSource)
        binding = ges_video_source.get_control_binding("alpha")
        control_source = binding.props.control_source
        keyframe_curve = ges_video_source.ui.keyframe_curve
        values = [item.timestamp for item in control_source.get_all()]
        self.assertEqual(values, [inpoint, inpoint + duration])

        # Add a keyframe.
        position = start + int(duration / 2)
        with mock.patch.object(pipeline, "get_position") as get_position:
            get_position.return_value = position
            timeline_container._keyframe_cb(None, None)

        # Start dragging the keyframe.
        x, y = keyframe_curve._ax.transData.transform((position, 1))
        event = MouseEvent(
            name="button_press_event",
            canvas=keyframe_curve,
            x=x,
            y=y,
            button=MouseButton.LEFT
        )
        event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
        self.assertIsNone(keyframe_curve._offset)
        keyframe_curve._mpl_button_press_event_cb(event)
        self.assertIsNotNone(keyframe_curve._offset)

        # Drag and make sure x and y are not locked.
        timeline_container.control_mask = False
        event = mock.Mock(
            x=x + 1,
            y=y + 1,
            xdata=position + 1,
            ydata=0.9,
        )
        with mock.patch.object(keyframe_curve,
                               "_move_keyframe") as _move_keyframe:
            keyframe_curve._mpl_motion_event_cb(event)
            # Check the keyframe is moved exactly where the cursor is.
            _move_keyframe.assert_called_once_with(position, position + 1, 0.9)

        # Drag locked horizontally.
        timeline_container.control_mask = True
        event = mock.Mock(
            x=x + 1,
            y=y + 2,
            xdata=position + 2,
            ydata=0.8,
        )
        with mock.patch.object(keyframe_curve,
                               "_move_keyframe") as _move_keyframe:
            keyframe_curve._mpl_motion_event_cb(event)
            # Check the keyframe is kept on the same timestamp.
            _move_keyframe.assert_called_once_with(position + 1, position, 0.8)

        # Drag locked vertically.
        timeline_container.control_mask = True
        event = mock.Mock(
            x=x + 2,
            y=y + 1,
            xdata=position + 3,
            ydata=0.7,
        )
        with mock.patch.object(keyframe_curve,
                               "_move_keyframe") as _move_keyframe:
            keyframe_curve._mpl_motion_event_cb(event)
            # Check the keyframe is kept on the same value.
            _move_keyframe.assert_called_once_with(position, position + 3, 1)
Ejemplo n.º 6
0
    def check_keyframe_ui_toggle(self, ges_clip, timeline_container):
        """Checks keyframes toggling by click events."""
        timeline = timeline_container.timeline

        inpoint = ges_clip.props.in_point
        duration = ges_clip.props.duration
        offsets = (1, int(duration / 2), int(duration) - 1)
        timeline.selection.select([ges_clip])

        ges_video_source = ges_clip.find_track_element(None, GES.VideoSource)
        binding = ges_video_source.get_control_binding("alpha")
        control_source = binding.props.control_source
        keyframe_curve = ges_video_source.ui.keyframe_curve

        values = [item.timestamp for item in control_source.get_all()]
        self.assertEqual(values, [inpoint, inpoint + duration])

        # Add keyframes.
        for offset in offsets:
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(
                name = "button_press_event",
                canvas = keyframe_curve,
                x = x,
                y = y,
                button = 1
            )
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertIn(inpoint + offset, values)

        # Remove keyframes.
        for offset in offsets:
            xdata, ydata = inpoint + offset, 1
            x, y = keyframe_curve._ax.transData.transform((xdata, ydata))

            event = MouseEvent(
                name="button_press_event",
                canvas=keyframe_curve,
                x=x,
                y=y,
                button=1
            )
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)
            event.name = "button_press_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.guiEvent = Gdk.Event.new(Gdk.EventType._2BUTTON_PRESS)
            keyframe_curve._mpl_button_press_event_cb(event)
            event.name = "button_release_event"
            event.guiEvent = Gdk.Event.new(Gdk.EventType.BUTTON_RELEASE)
            keyframe_curve._mpl_button_release_event_cb(event)

            values = [item.timestamp for item in control_source.get_all()]
            self.assertNotIn(inpoint + offset, values)