def on_selection_move(self, event: QKeyEvent): if self.selection is None or not np.any(self.selection): if event.key() in (Qt.Key_Right, Qt.Key_Down): x = y = 0 else: x = self.size_x - 1 y = self.size_y - 1 else: x, y = np.nonzero(self.selection) if len(x) > 1: return if event.key() == Qt.Key_Up and y > 0: y -= 1 if event.key() == Qt.Key_Down and y < self.size_y - 1: y += 1 if event.key() == Qt.Key_Left and x: x -= 1 if event.key() == Qt.Key_Right and x < self.size_x - 1: x += 1 x -= self.hexagonal and x == self.size_x - 1 and y % 2 if self.selection is not None and self.selection[x, y]: return selection = np.zeros(self.grid_cells.shape, dtype=bool) selection[x, y] = True self.on_selection_change(selection)
def keyPressEvent(self, event: QKeyEvent) -> None: editing = self.__editing if self.__editTriggers & EditTriggers.EditKeyPressed \ and not editing: if event.key() in self.__editKeys: self.__startEdit(Qt.ShortcutFocusReason) event.accept() return elif self.__editTriggers & EditTriggers.AnyKeyPressed \ and not editing: self.__startEdit(Qt.OtherFocusReason) event.accept() return if editing and self.__returnKeyEndsEditing \ and event.key() in (Qt.Key_Enter, Qt.Key_Return): self.__endEdit() event.accept() return super().keyPressEvent(event)
def keyPressEvent(self, event: QKeyEvent): if event.key() in (Qt.Key_Up, Qt.Key_Down, Qt.Key_Left, Qt.Key_Right): self.selection_moved.emit(event) else: super().keyPressEvent(event)
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)
def keyPressEvent(self, event: QtGui.QKeyEvent): if event.key() == QtCore.Qt.Key_Escape: self.close()