Python PyQt5.QtCore.Qt.Key_Enter() Examples

The following are 25 code examples of PyQt5.QtCore.Qt.Key_Enter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore.Qt , or try the search function .
Example #1
Source File: keyutils.py    From qutebrowser with GNU General Public License v3.0 9 votes vote down vote up
def text(self) -> str:
        """Get the text which would be displayed when pressing this key."""
        control = {
            Qt.Key_Space: ' ',
            Qt.Key_Tab: '\t',
            Qt.Key_Backspace: '\b',
            Qt.Key_Return: '\r',
            Qt.Key_Enter: '\r',
            Qt.Key_Escape: '\x1b',
        }

        if self.key in control:
            return control[self.key]
        elif not _is_printable(self.key):
            return ''

        text = QKeySequence(self.key).toString()
        if not self.modifiers & Qt.ShiftModifier:  # type: ignore[operator]
            text = text.lower()
        return text 
Example #2
Source File: test_panes.py    From mu with GNU General Public License v3.0 6 votes vote down vote up
def test_PythonProcessPane_parse_input_newline_ignore_empty_input_in_history(
    qtapp,
):
    """
    Newline causes the input line to be written to the child process's stdin,
    but if the resulting line is either empty or only contains whitespace, do
    not add it to the input_history.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.toPlainText = mock.MagicMock(return_value="   \n")
    ppp.start_of_current_line = 0
    ppp.write_to_stdin = mock.MagicMock()
    key = Qt.Key_Enter
    text = "\r"
    modifiers = None
    ppp.parse_input(key, text, modifiers)
    ppp.write_to_stdin.assert_called_once_with(b"   \n")
    assert len(ppp.input_history) == 0
    assert ppp.history_position == 0 
Example #3
Source File: test_panes.py    From mu with GNU General Public License v3.0 6 votes vote down vote up
def test_PythonProcessPane_parse_input_newline(qtapp):
    """
    Newline causes the input line to be written to the child process's stdin.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.toPlainText = mock.MagicMock(return_value="abc\n")
    ppp.start_of_current_line = 0
    ppp.textCursor = mock.MagicMock()
    ppp.textCursor().position.return_value = 666
    ppp.setTextCursor = mock.MagicMock()
    ppp.insert = mock.MagicMock()
    ppp.write_to_stdin = mock.MagicMock()
    key = Qt.Key_Enter
    text = "\r"
    modifiers = None
    ppp.parse_input(key, text, modifiers)
    ppp.write_to_stdin.assert_called_once_with(b"abc\n")
    assert b"abc" in ppp.input_history
    assert ppp.history_position == 0
    # On newline, the start of the current line should be set correctly.
    assert ppp.start_of_current_line == 4  # len('abc\n') 
Example #4
Source File: ModulatorDialog.py    From urh with GNU General Public License v3.0 6 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            return
        else:
            super().keyPressEvent(event) 
Example #5
Source File: settings.py    From uPyLoader with MIT License 5 votes vote down vote up
def __init__(self):
        self.version = 100  # Assume oldest config
        self.root_dir = QDir().currentPath()
        self.send_sleep = 0.1
        self.read_sleep = 0.1
        self.use_transfer_scripts = True
        self.use_custom_transfer_scripts = False
        self.external_transfer_scripts_folder = None
        self.wifi_presets = []
        self.python_flash_executable = None
        self.last_firmware_directory = None
        self.debug_mode = False
        self._geometries = {}
        self.external_editor_path = None
        self.external_editor_args = None
        self.new_line_key = QKeySequence(Qt.SHIFT + Qt.Key_Return, Qt.SHIFT + Qt.Key_Enter)
        self.send_key = QKeySequence(Qt.Key_Return, Qt.Key_Enter)
        self.terminal_tab_spaces = 4
        self.mpy_cross_path = None
        self.preferred_port = None
        self.auto_transfer = False

        if not self.load():
            if not self.load_old():
                # No config found, init at newest version
                self.version = Settings.newest_version
                return

        self._update_config() 
Example #6
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_PythonProcessPane_parse_input_newline_with_cursor_midline(qtapp):
    """
    Ensure that when the cursor is placed in the middle of a line and enter is
    pressed the whole line is sent to std_in.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.write_to_stdin = mock.MagicMock()
    ppp.parse_input(None, "abc", None)
    ppp.parse_input(Qt.Key_Left, None, None)
    ppp.parse_input(Qt.Key_Enter, "\r", None)
    ppp.write_to_stdin.assert_called_with(b"abc\n") 
Example #7
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_PythonProcessPane_parse_paste_final_character(qtapp):
    """
    As above, but ensure that if there a no more remaining characters to parse
    in the pasted text, then don't schedule any more recursive calls.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.parse_input = mock.MagicMock()
    mock_timer = mock.MagicMock()
    with mock.patch("mu.interface.panes.QTimer", mock_timer):
        ppp.parse_paste("\n")
    ppp.parse_input.assert_called_once_with(Qt.Key_Enter, "\n", None)
    assert mock_timer.singleShot.call_count == 0 
Example #8
Source File: test_panes.py    From mu with GNU General Public License v3.0 5 votes vote down vote up
def test_PythonProcessPane_parse_paste_newline(qtapp):
    """
    As above, but ensure the correct handling of a newline character.
    """
    ppp = mu.interface.panes.PythonProcessPane()
    ppp.parse_input = mock.MagicMock()
    mock_timer = mock.MagicMock()
    with mock.patch("mu.interface.panes.QTimer", mock_timer):
        ppp.parse_paste("\nhello")
    ppp.parse_input.assert_called_once_with(Qt.Key_Enter, "\n", None)
    assert mock_timer.singleShot.call_count == 1 
Example #9
Source File: test_analysis_tab_GUI.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def test_analyze_button_enocean(self):
        self.add_signal_to_form("enocean.complex")
        w = self.form.signal_tab_controller.signal_frames[1].ui.spinBoxCenterOffset
        w.setValue(0)
        QTest.keyClick(w, Qt.Key_Enter)
        w = self.form.signal_tab_controller.signal_frames[1].ui.spinBoxNoiseTreshold
        w.setValue(0.0111)
        QTest.keyClick(w, Qt.Key_Enter)
        self.cfc.assign_labels_action.setChecked(True)
        self.cfc.assign_message_type_action.setChecked(True)
        self.cfc.assign_participants_action.setChecked(True)
        self.cfc.ui.btnAnalyze.click()
        self.assertTrue(True) 
Example #10
Source File: GeneratorListView.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.key() in (Qt.Key_Enter, Qt.Key_Return):
            selected = [index.row() for index in self.selectedIndexes()]
            if len(selected) > 0:
                self.edit_on_item_triggered.emit(min(selected))
        else:
            super().keyPressEvent(event) 
Example #11
Source File: ProtocolLabelDialog.py    From urh with GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Enter:
            event.ignore()
        else:
            event.accept() 
Example #12
Source File: test_{{cookiecutter.application_name}}.py    From cookiecutter-pyqt5 with MIT License 5 votes vote down vote up
def test_about_dialog(window, qtbot, mock):
    """Test the About item of the Help submenu.

    Qtbot clicks on the help sub menu and then navigates to the About item. Mock creates
    a QDialog object to be used for the test.
    """
    qtbot.mouseClick(window.help_sub_menu, Qt.LeftButton)
    qtbot.keyClick(window.help_sub_menu, Qt.Key_Down)
    mock.patch.object(QDialog, 'exec_', return_value='accept')
    qtbot.keyClick(window.help_sub_menu, Qt.Key_Enter) 
Example #13
Source File: test_{{cookiecutter.application_name}}.py    From cookiecutter-pyqt5 with MIT License 5 votes vote down vote up
def test_open_file(window, qtbot, mock):
    """Test the Open File item of the File submenu.

    Qtbot clicks on the file sub menu and then navigates to the Open File item. Mock creates
    an object to be passed to the QFileDialog.
    """
    qtbot.mouseClick(window.file_sub_menu, Qt.LeftButton)
    qtbot.keyClick(window.file_sub_menu, Qt.Key_Down)
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=('', ''))
    qtbot.keyClick(window.file_sub_menu, Qt.Key_Enter) 
Example #14
Source File: code_editor.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event):
        tc = self.textCursor()

        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return or event.key() == Qt.Key_Tab:
            if self.completer and self.completer.popup().isVisible():
                self.completer.insertText.emit(self.completer.getSelected())
                self.completer.setCompletionMode(QCompleter.PopupCompletion)
                event.ignore()
                return

        super().keyPressEvent(event)

        tc.select(QTextCursor.WordUnderCursor)
        cr = self.cursorRect()

        if self.completer:
            if tc.selectedText():
                self.completer.setCompletionPrefix(tc.selectedText())
                popup = self.completer.popup()
                #popup.setCurrentIndex(self.completer.completionModel().index(0, 0))

                cr.setWidth(
                    self.completer.popup().sizeHintForColumn(0) +
                    self.completer.popup().verticalScrollBar().sizeHint().width())
                self.completer.complete(cr)
            else:
                self.completer.popup().hide() 
Example #15
Source File: widget_console.py    From Dwarf with GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event):
        # when codecompletion popup dont respond to enter
        if self.completer and self.completer.popup() and self.completer.popup(
        ).isVisible():
            event.ignore()
            return super().keyPressEvent(event)

        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            cmd = self.toPlainText()
            l = len(self.cmds)
            if l > 0:
                if l > 100:
                    self.cmds.pop(0)
                if cmd != self.cmds[l - 1]:
                    self.cmds.append(cmd)
            else:
                self.cmds.append(cmd)
            self.cmd_index = 0
            self.onEnterKeyPressed.emit(cmd)
            self.setPlainText('')
        elif event.key() == Qt.Key_Up:
            l = len(self.cmds)
            try:
                self.setPlainText(self.cmds[l - 1 - self.cmd_index])
                if self.cmd_index < l - 1:
                    self.cmd_index += 1
            except:
                pass
        elif event.key() == Qt.Key_Down:
            try:
                if self.cmd_index >= 0:
                    self.cmd_index -= 1
                self.setPlainText(
                    self.cmds[len(self.cmds) - 1 - self.cmd_index])
            except:
                self.setPlainText('')
                self.cmd_index = 0
        else:
            return super().keyPressEvent(event) 
Example #16
Source File: test_mainwin.py    From QssStylesheetEditor with GNU General Public License v3.0 5 votes vote down vote up
def test_fileop_and_clrpic(self, qapp, qtbot, sharedwin, tmpdir):
        """Test file new and save, test color pick, this test will effect CodeEditor text
        """
        mainwin = sharedwin["main"]
        def file():
            mainwin.new()
            f = tmpdir.join("new.qsst").ensure()
            mainwin.file = str(f)
            mainwin.save()
            assert not mainwin.editor.text()

        file()
        mainwin.newFromTemplate()
        mainwin.editor.setModified(False)

        import sys
        if sys.platform.startswith('win'):
            class DialogCloseThread(QThread):
                def __init__(self, parent=None):
                    super().__init__(parent)

                def run(self):
                    while not qapp.activeModalWidget():
                        qtbot.wait(10)
                    dial = qapp.activeModalWidget()
                    qtbot.keyPress(dial, Qt.Key_Enter)

            t1 = DialogCloseThread()
            t1.finished.connect(lambda: print("t1 finished"))
            t1.start()
            qtbot.mouseClick(mainwin.clrBtnDict["text"], Qt.LeftButton)
            t1.wait()
            t1.quit()
            del t1
            assert mainwin.clrBtnDict["text"].text() == "#222222" or mainwin.clrBtnDict["text"].text() == "#222" 
Example #17
Source File: mainwin.py    From QssStylesheetEditor with GNU General Public License v3.0 5 votes vote down vote up
def textChanged(self, e):  # QKeyEvent(QEvent.KeyPress, Qt.Key_Enter, Qt.NoModifier)
        # if (32<e.key()<96 or 123<e.key()<126 or 0x1000001<e.key()<0x1000005 or e.key==Qt.Key_Delete):
        # 大键盘为Ret小键盘为Enter
        if (e.key() in (Qt.Key_Return, Qt.Key_Enter, Qt.Key_Semicolon, Qt.Key_BraceRight, Qt.Key_Up, Qt.Key_Down,
                        Qt.Key_Left, Qt.Key_Right, Qt.Key_Tab, Qt.Key_Delete, Qt.Key_Backspace)):
            self.renderStyle()
            self.loadColorPanel()

        self.actions["undo"].setEnabled(self.editor.isUndoAvailable())
        self.actions["redo"].setEnabled(self.editor.isRedoAvailable()) 
Example #18
Source File: textclient.py    From bluesky with GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event):
        ''' Handle Enter keypress to send a command to BlueSky. '''
        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            if bsclient is not None:
                bsclient.stack(self.toPlainText())
                echobox.echo(self.toPlainText())
            self.setText('')
        else:
            super().keyPressEvent(event) 
Example #19
Source File: Main.py    From COMTool with GNU Lesser General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event):
        if event.key() == Qt.Key_Control:
            self.keyControlPressed = True
        elif event.key() == Qt.Key_Return or event.key()==Qt.Key_Enter:
            if self.keyControlPressed:
                self.sendData()
        elif event.key() == Qt.Key_L:
            if self.keyControlPressed:
                self.sendArea.clear()
        elif event.key() == Qt.Key_K:
            if self.keyControlPressed:
                self.receiveArea.clear() 
Example #20
Source File: QtKeyDevice.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _qtKeyToUMKey(self, key):
        if key == Qt.Key_Shift:
            return KeyEvent.ShiftKey
        elif key == Qt.Key_Control:
            return KeyEvent.ControlKey
        elif key == Qt.Key_Alt:
            return KeyEvent.AltKey
        elif key == Qt.Key_Space:
            return KeyEvent.SpaceKey
        elif key == Qt.Key_Meta:
            return KeyEvent.MetaKey
        elif key == Qt.Key_Enter or key == Qt.Key_Return:
            return KeyEvent.EnterKey
        elif key == Qt.Key_Up:
            return KeyEvent.UpKey
        elif key == Qt.Key_Down:
            return KeyEvent.DownKey
        elif key == Qt.Key_Left:
            return KeyEvent.LeftKey
        elif key == Qt.Key_Right:
            return KeyEvent.RightKey
        elif key == Qt.Key_Minus:
            return KeyEvent.MinusKey
        elif key == Qt.Key_Underscore:
            return KeyEvent.UnderscoreKey
        elif key == Qt.Key_Plus:
            return KeyEvent.PlusKey
        elif key == Qt.Key_Equal:
            return KeyEvent.EqualKey

        return key 
Example #21
Source File: filter_widget.py    From execution-trace-viewer with MIT License 5 votes vote down vote up
def on_filter_combo_box_key_pressed(self, event):
        """Checks if enter is pressed on filterEdit"""
        key = event.key()
        if key in (Qt.Key_Return, Qt.Key_Enter):
            self.on_filter_btn_clicked()
        QComboBox.keyPressEvent(self.filter_combo_box, event) 
Example #22
Source File: qcheckcombobox.py    From artisan with GNU General Public License v3.0 4 votes vote down vote up
def eventFilter(self, obj, event):
        """Reimplemented."""
        if self.__popupIsShown and \
                event.type() == QEvent.MouseMove and \
                self.view().isVisible() and self.__initialMousePos is not None:
            diff = obj.mapToGlobal(event.pos()) - self.__initialMousePos
            if diff.manhattanLength() > 9 and \
                    self.__blockMouseReleaseTimer.isActive():
                self.__blockMouseReleaseTimer.stop()
            # pass through

        if self.__popupIsShown and \
                event.type() == QEvent.MouseButtonRelease and \
                self.view().isVisible() and \
                self.view().rect().contains(event.pos()) and \
                self.view().currentIndex().isValid() and \
                self.view().currentIndex().flags() & Qt.ItemIsSelectable and \
                self.view().currentIndex().flags() & Qt.ItemIsEnabled and \
                self.view().currentIndex().flags() & Qt.ItemIsUserCheckable and \
                self.view().visualRect(self.view().currentIndex()).contains(event.pos()) and \
                not self.__blockMouseReleaseTimer.isActive():
            model = self.model()
            index = self.view().currentIndex()
            state = model.data(index, Qt.CheckStateRole)
            model.setData(index,
                          Qt.Checked if state == Qt.Unchecked else Qt.Unchecked,
                          Qt.CheckStateRole)
            self.view().update(index)
            self.update()
            self.flagChanged.emit(index.row(),state == Qt.Unchecked)
            return True

        if self.__popupIsShown and event.type() == QEvent.KeyPress:
            if event.key() == Qt.Key_Space:
                # toogle the current items check state
                model = self.model()
                index = self.view().currentIndex()
                flags = model.flags(index)
                state = model.data(index, Qt.CheckStateRole)
                if flags & Qt.ItemIsUserCheckable and \
                        flags & Qt.ItemIsTristate:
                    state = Qt.CheckState((int(state) + 1) % 3)
                elif flags & Qt.ItemIsUserCheckable:
                    state = Qt.Checked if state != Qt.Checked else Qt.Unchecked
                model.setData(index, state, Qt.CheckStateRole)
                self.view().update(index)
                self.update()
                self.flagChanged.emit(index.row(),state != Qt.Unchecked)
                return True
            # TODO: handle Qt.Key_Enter, Key_Return?

        return super(CheckComboBox, self).eventFilter(obj, event) 
Example #23
Source File: console.py    From bluesky with GNU General Public License v3.0 4 votes vote down vote up
def keyPressEvent(self, event):
        ''' Handle keyboard input for bluesky. '''
        # Enter-key: enter command
        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            if self.command_line:
                # emit a signal with the command for the simulation thread
                self.stack(self.command_line)
                # Clear any shape command preview on the radar display
                # self.radarwidget.previewpoly(None)
                return

        newcmd = self.command_line
        cursorpos = None
        if event.key() >= Qt.Key_Space and event.key() <= Qt.Key_AsciiTilde:
            pos = self.lineEdit.cursor_pos()
            newcmd = newcmd[:pos] + event.text() + newcmd[pos:]
            # Update the cursor position with the length of the added text
            cursorpos = pos + len(event.text())
        elif event.key() == Qt.Key_Backspace:
            pos = self.lineEdit.cursor_pos()
            newcmd = newcmd[:pos - 1] + newcmd[pos:]
            cursorpos = pos - 1
        elif event.key() == Qt.Key_Tab:
            if newcmd:
                newcmd, displaytext = autocomplete.complete(newcmd)
                if displaytext:
                    self.echo(displaytext)
        elif not event.modifiers() & (Qt.ControlModifier | Qt.ShiftModifier | 
                                        Qt.AltModifier | Qt.MetaModifier):
            if event.key() == Qt.Key_Up:
                if self.history_pos == 0:
                    self.command_mem = newcmd
                if len(self.command_history) >= self.history_pos + 1:
                    self.history_pos += 1
                    newcmd = self.command_history[-self.history_pos]

            elif event.key() == Qt.Key_Down:
                if self.history_pos > 0:
                    self.history_pos -= 1
                    if self.history_pos == 0:
                        newcmd = self.command_mem
                    else:
                        newcmd = self.command_history[-self.history_pos]

            elif event.key() == Qt.Key_Left:
                self.lineEdit.cursor_left()

            elif event.key() == Qt.Key_Right:
                self.lineEdit.cursor_right()
            else:
                # Remaining keys are things like sole modifier keys, and function keys
                super(Console, self).keyPressEvent(event)
        else:
            event.ignore()
            return

        # Final processing of the command line
        self.set_cmdline(newcmd, cursorpos) 
Example #24
Source File: Content.py    From Hydra with GNU General Public License v3.0 4 votes vote down vote up
def keyPressEvent(self, event):

        if (
            self.completer
            and self.completer.popup()
            and self.completer.popup().isVisible()
        ):
            if event.key() in (
                Qt.Key_Enter,
                Qt.Key_Return,
                Qt.Key_Escape,
                Qt.Key_Tab,
                Qt.Key_Backtab,
            ):
                event.ignore()
                return

        isShortcut = event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_B

        if not self.completer or not isShortcut:
            QPlainTextEdit.keyPressEvent(self.editor, event)

        completionPrefix = self.textUnderCursor()

        if not isShortcut:
            if self.completer.popup():
                self.completer.popup().hide()
            return

        self.completer.setCompletionPrefix(completionPrefix)

        popup = self.completer.popup()

        popup.setFont(self.font)
        popup.setCurrentIndex(self.completer.completionModel().index(0, 0))

        cr = self.editor.cursorRect()
        cr.translate(QPoint(10, 10))
        cr.setWidth(
            self.completer.popup().sizeHintForColumn(0)
            + self.completer.popup().verticalScrollBar().sizeHint().width()
        )
        self.completer.complete(cr) 
Example #25
Source File: forward_keyboard.py    From MaixPy_scripts with MIT License 4 votes vote down vote up
def keyPressEvent(self, event):
        print(event.key())
        if event.key() == Qt.Key_M:
            self.send_flag = False
            self.com.write(b"m")
            self.send_flag = False
        elif event.key() == Qt.Key_Return or event.key()==Qt.Key_Enter:
            self.send_flag = False
            self.com.write(b"m")
            self.send_flag = False
        elif event.key() == Qt.Key_N or event.key() == 92:
            self.send_flag = False
            self.com.write(b"n")
            self.send_flag = False
        elif event.key() == Qt.Key_Minus:
            self.send_flag = False
            self.com.write(b"-")
            self.send_flag = False
        elif event.key() == Qt.Key_Equal:
            self.send_flag = False
            self.com.write(b"=")
            self.send_flag = False
        elif event.key() == Qt.Key_W or event.key() == Qt.Key_Up:
            self.send_flag = True
            self.key.append(b"w")
        elif event.key() == Qt.Key_A or event.key() == Qt.Key_Left:
            self.send_flag = True
            self.key.append(b"a")
        elif event.key() == Qt.Key_S or event.key() == Qt.Key_Down:
            self.send_flag = True
            self.key.append(b"s")
        elif event.key() == Qt.Key_D or event.key() == Qt.Key_Right:
            self.send_flag = True
            self.key.append(b"d")
        elif event.key() == Qt.Key_J:
            self.send_flag = True
            self.key.append(b"j")
        elif event.key() == Qt.Key_K:
            self.send_flag = True
            self.key.append(b"k")
        elif event.key() == Qt.Key_Escape:
            self.send_flag = False
            self.com.write(b"\x03")
        elif event.key() == Qt.Key_Control:
            self.keyControlPressed = True
        elif event.key() == Qt.Key_C:
            if self.keyControlPressed:
                self.send_flag = False
                self.com.write(b"\x03")
        # self.key_label.setText(self.key.decode())