Ejemplo n.º 1
0
 def keyPressEvent(self, event: QKeyEvent):
     event.ignore()
     pass
Ejemplo n.º 2
0
    def keyReleaseEvent(self, event:  QKeyEvent):
        self.key_release_event(event)

        if self._selected is not None:
            modifier = int(event.modifiers())

            # Move the event (or the pointer) left
            if modifier == QtCore.Qt.ControlModifier and event.key() == QtCore.Qt.Key_Left:
                self._selected.move(-1, 0)
                event.ignore()
                self.repaint()

            # Move the event (or the pointer) right
            if modifier == QtCore.Qt.ControlModifier and event.key() == QtCore.Qt.Key_Right:
                self._selected.move(1, 0)
                event.ignore()
                self.repaint()

            if self._selected != self._pointer:
                # Delete the selected event
                if event.key() == QtCore.Qt.Key_Delete:
                    self.remove_selected_event()

                # Lock or unlock an event
                if event.key() == QtCore.Qt.Key_L:
                    self.toggle_selected_event_lock()

                # Lock or unlock an event
                if event.key() == QtCore.Qt.Key_E:
                    index = self.selected_row.events.index(self._selected)
                    if index < len(self.selected_row.events)-1:
                        self._selected = self.selected_row.events[index+1]
                        self.position = self._selected.begin

                # Move to the previous event
                if event.key() == QtCore.Qt.Key_Q:
                    index = self.selected_row.events.index(self._selected)
                    if index > 0:
                        self._selected = self.selected_row.events[index - 1]
                        self.position = self._selected.begin

                # Move the event up
                if modifier == QtCore.Qt.ControlModifier and event.key() == QtCore.Qt.Key_Up:
                    self._selected.move(0, self._selected.top_coordinate - self.TRACK_HEIGHT)
                    self.repaint()

                # Move the event down
                if modifier == QtCore.Qt.ControlModifier and event.key() == QtCore.Qt.Key_Down:
                    self._selected.move(0, self._selected.top_coordinate + self.TRACK_HEIGHT)
                    self.repaint()

                # Move the event end left
                if modifier == int(
                        QtCore.Qt.ShiftModifier | QtCore.Qt.ControlModifier) and event.key() == QtCore.Qt.Key_Left:
                    self._selected.move_end(-1)
                    self.repaint()

                # Move the event end right
                if modifier == int(
                        QtCore.Qt.ShiftModifier | QtCore.Qt.ControlModifier) and event.key() == QtCore.Qt.Key_Right:
                    self._selected.move_end(1)
                    self.repaint()

                # Move the event begin left
                if modifier == QtCore.Qt.ShiftModifier and event.key() == QtCore.Qt.Key_Left:
                    self._selected.move_begin(-1)
                    self.repaint()

                # Move the event begin right
                if modifier == QtCore.Qt.ShiftModifier and event.key() == QtCore.Qt.Key_Right:
                    self._selected.move_begin(1)
                    self.repaint()

        else:
            # Keybinds to create an event at current frame
            if event.key() == QtCore.Qt.Key_S and not self._creating_event:
                # Start
                self._creating_event_start = self._pointer.frame
                self._creating_event = True

                # TODO Add some indicator that an event is being recorded, like
                # using the track selector circle to become red

                return

            elif event.key() == QtCore.Qt.Key_S and self._creating_event:
                # End, must be followed right after Start key and have no
                # effect otherwise
                self._creating_event_end = self._pointer.frame

                start = self._creating_event_start
                end = self._creating_event_end
                comment = ""

                if end > start:
                    track = self._selected_track
                    if track is None and len(self.tracks)>0:
                        track = self.tracks[0]
                    if track is None:
                        track = self.add_track()

                    self.add_event(start, end, comment, track=track )
                    self.repaint()
                    self._creating_event = False
                else:
                    self._creating_event = False

            # walk backwards 1 step
            elif event.key() == QtCore.Qt.Key_A:
                self.position = self.position - 1

            # forward 1 step
            elif event.key() == QtCore.Qt.Key_D:
                self.position = self.position + 1

        super(TimelineWidget, self).keyReleaseEvent(event)