def button_signal_for_key_event(self, event: QtGui.QKeyEvent,
                                    signal_name: str):
        if event.isAutoRepeat():
            return None

        button = None

        if event.key() == Qt.Key_Up:
            if event.modifiers() == Qt.ShiftModifier:
                button = self.tele_fast
            elif event.modifiers() == Qt.NoModifier:
                button = self.tele_normal
        elif event.key() == Qt.Key_Down:
            if event.modifiers() == Qt.ShiftModifier:
                button = self.wide_fast
            elif event.modifiers() == Qt.NoModifier:
                button = self.wide_normal
        elif event.key() == Qt.Key_End and event.modifiers() == Qt.NoModifier:
            button = self.zoomstop

        if button is None:
            return

        getattr(button, signal_name).emit()
Exemple #2
0
    def handle_wordcheck_key_events(self, e: QKeyEvent):
        """
        Remaps key events to their Wordcheck mode equivalents. Only handles NoModifier and ShiftModifier events.

        :param e: The key event to remap.
        :return:
        """
        if e.key() in [
                Qt.Key_Delete, Qt.Key_Backspace, Qt.Key_Comma, Qt.Key_Period,
                Qt.Key_Semicolon, Qt.Key_Colon, Qt.Key_Less, Qt.Key_Greater
        ]:
            if e.type() == QKeyEvent.KeyPress:
                super().keyPressEvent(e)
            elif e.type() == QKeyEvent.KeyRelease:
                super().keyReleaseEvent(e)

        elif e.modifiers() == Qt.NoModifier:
            if e.key() in [Qt.Key_S, Qt.Key_H]:
                mapped_e = QKeyEvent(e.type(),
                                     Qt.Key_Left,
                                     Qt.AltModifier,
                                     autorep=e.isAutoRepeat(),
                                     count=e.count())
                QApplication.sendEvent(self, mapped_e)
            elif e.key() in [Qt.Key_G, Qt.Key_L]:
                mapped_e = QKeyEvent(e.type(),
                                     Qt.Key_Right,
                                     Qt.AltModifier,
                                     autorep=e.isAutoRepeat(),
                                     count=e.count())
                QApplication.sendEvent(self, mapped_e)
            elif e.key() in [Qt.Key_F, Qt.Key_J]:
                mapped_e = QKeyEvent(e.type(),
                                     Qt.Key_Down,
                                     Qt.KeypadModifier,
                                     autorep=e.isAutoRepeat(),
                                     count=e.count())
                QApplication.sendEvent(self, mapped_e)
            elif e.key() in [Qt.Key_D, Qt.Key_K]:
                mapped_e = QKeyEvent(e.type(),
                                     Qt.Key_Up,
                                     Qt.KeypadModifier,
                                     autorep=e.isAutoRepeat(),
                                     count=e.count())
                QApplication.sendEvent(self, mapped_e)
            elif e.key() in [Qt.Key_C, Qt.Key_N]:
                mapped_e = QKeyEvent(e.type(),
                                     Qt.Key_Left,
                                     Qt.KeypadModifier,
                                     autorep=e.isAutoRepeat(),
                                     count=e.count())
                QApplication.sendEvent(self, mapped_e)
            elif e.key() in [Qt.Key_V, Qt.Key_M]:
                mapped_e = QKeyEvent(e.type(),
                                     Qt.Key_Right,
                                     Qt.KeypadModifier,
                                     autorep=e.isAutoRepeat(),
                                     count=e.count())
                QApplication.sendEvent(self, mapped_e)

            elif e.key() in [Qt.Key_R, Qt.Key_U
                             ] and e.type() == QKeyEvent.KeyPress:
                if self.wordcheck_entry is not None:
                    self.entry_idx += 1
                    self.next_word_replace()
            elif e.key() in [Qt.Key_E, Qt.Key_I
                             ] and e.type() == QKeyEvent.KeyPress:
                if self.wordcheck_entry is not None:
                    self.entry_idx -= 1
                    self.next_word_replace()

            elif e.key() in [Qt.Key_W, Qt.Key_O
                             ] and e.type() == QKeyEvent.KeyPress:
                self.set_wordcheck_word_as_default()

            elif e.key() in [Qt.Key_A, Qt.Key_Z, Qt.Key_X]:
                if e.key() == Qt.Key_A:
                    mapped_e = QKeyEvent(e.type(),
                                         Qt.Key_Semicolon,
                                         Qt.NoModifier,
                                         text=';',
                                         autorep=e.isAutoRepeat(),
                                         count=e.count())
                    QApplication.sendEvent(self, mapped_e)
                elif e.key() == Qt.Key_Z:
                    mapped_e = QKeyEvent(e.type(),
                                         Qt.Key_Period,
                                         Qt.NoModifier,
                                         text='.',
                                         autorep=e.isAutoRepeat(),
                                         count=e.count())
                    QApplication.sendEvent(self, mapped_e)
                else:  # Key_X
                    mapped_e = QKeyEvent(e.type(),
                                         Qt.Key_Comma,
                                         Qt.NoModifier,
                                         text=',',
                                         autorep=e.isAutoRepeat(),
                                         count=e.count())
                    QApplication.sendEvent(self, mapped_e)

        elif e.modifiers() == Qt.ShiftModifier:
            if e.key() in [Qt.Key_A, Qt.Key_Z, Qt.Key_X]:
                if e.key() == Qt.Key_A:
                    mapped_e = QKeyEvent(e.type(),
                                         Qt.Key_Colon,
                                         Qt.ShiftModifier,
                                         text=':',
                                         autorep=e.isAutoRepeat(),
                                         count=e.count())
                    QApplication.sendEvent(self, mapped_e)
                elif e.key() == Qt.Key_Z:
                    mapped_e = QKeyEvent(e.type(),
                                         Qt.Key_Greater,
                                         Qt.ShiftModifier,
                                         text='>',
                                         autorep=e.isAutoRepeat(),
                                         count=e.count())
                    QApplication.sendEvent(self, mapped_e)
                else:  # Key_X
                    mapped_e = QKeyEvent(e.type(),
                                         Qt.Key_Less,
                                         Qt.ShiftModifier,
                                         text='<',
                                         autorep=e.isAutoRepeat(),
                                         count=e.count())
                    QApplication.sendEvent(self, mapped_e)