Python PyQt5.QtGui.QKeyEvent() Examples

The following are code examples for showing how to use PyQt5.QtGui.QKeyEvent(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: kucher   Author: Zubax   File: little_bobby_tables_widget.py    GNU General Public License v3.0 6 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.matches(QKeySequence.Copy):
            selected_rows = [x.row() for x in self._table.selectionModel().selectedIndexes()]
            _logger.info('Copying the following rows to the clipboard: %r', selected_rows)

            if len(selected_rows) == 1:
                out_strings = [self._table.item(selected_rows[0], 0).text()]
            else:
                out_strings = []
                for row in selected_rows:
                    header = self._table.verticalHeaderItem(row).text()
                    data = self._table.item(row, 0).text()
                    out_strings.append(f'{header}\t{data}')

            if out_strings:
                QApplication.clipboard().setText(os.linesep.join(out_strings))
        else:
            super(LittleBobbyTablesWidget, self).keyPressEvent(event) 
Example 2
Project: kucher   Author: Zubax   File: __init__.py    GNU General Public License v3.0 6 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.matches(QKeySequence.Copy):
            selected_indexes = [(x.row(), x.column()) for x in self.selectionModel().selectedIndexes()]
            _logger.info('Copying the following items to the clipboard: %r', selected_indexes)

            # Dicts are ordered now. Yay!
            by_row = {}
            for row, column in sorted(selected_indexes):
                by_row.setdefault(row, []).append(column)

            out_strings = []
            for row, column_list in by_row.items():
                out_strings.append('\t'.join([self._model.render_item_for_clipboard(self._model.index(row, col))
                                             for col in column_list]))

            if out_strings:
                QApplication.clipboard().setText(os.linesep.join(out_strings))
        else:
            super(_TableView, self).keyPressEvent(event) 
Example 3
Project: bw-model-viewer   Author: RenolY2   File: bw_model_viewer.py    MIT License 6 votes vote down vote up
def keyReleaseEvent(self, event: QtGui.QKeyEvent):
        if event.key() == Qt.Key_Shift:
            self.waterbox_renderer.shift_is_pressed = False

        if event.key() == Qt.Key_W:
            self.waterbox_renderer.MOVE_FORWARD = 0
        elif event.key() == Qt.Key_S:
            self.waterbox_renderer.MOVE_BACKWARD = 0
        elif event.key() == Qt.Key_A:
            self.waterbox_renderer.MOVE_LEFT = 0
        elif event.key() == Qt.Key_D:
            self.waterbox_renderer.MOVE_RIGHT = 0
        elif event.key() == Qt.Key_Q:
            self.waterbox_renderer.MOVE_UP = 0
        elif event.key() == Qt.Key_E:
            self.waterbox_renderer.MOVE_DOWN = 0
        elif event.key() == Qt.Key_R:
            self.waterbox_renderer.ROTATE_LEFT = 0
        elif event.key() == Qt.Key_T:
            self.waterbox_renderer.ROTATE_RIGHT = 0 
Example 4
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 6 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        """Handle key press event for the widget."""
        api.status.clear("KeyPressEvent")
        try:
            keysequence = keyevent_to_sequence(event)
        except ValueError:  # Only modifier pressed
            _logger.debug("KeyPressEvent: only modifier pressed")
            return
        mode = api.modes.current()
        keyname = "".join(keysequence)
        # Handle escape separately as it affects multiple widgets and must clear partial
        # matches instead of checking for them
        if keyname == "<escape>" and mode in api.modes.GLOBALS:
            _logger.debug("KeyPressEvent: handling <escape> key specially")
            self.partial_handler.clear_keys()
            search.search.clear()
            api.status.update("escape pressed")
        # Count
        elif keyname and keyname in string.digits and mode != api.modes.COMMAND:
            _logger.debug("KeyPressEvent: adding digits to count")
            self.partial_handler.count.add_keys(keyname)
        elif not self._process_event(keysequence, mode=mode):
            super().keyPressEvent(event)  # type: ignore 
Example 5
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 6 votes vote down vote up
def keyevent_to_sequence(event: QKeyEvent) -> SequenceT:
    """Convert QKeyEvent to meaningful string sequence."""
    modifiers = (
        Qt.Key_Control,
        Qt.Key_Alt,
        Qt.Key_Shift,
        Qt.Key_Meta,
        Qt.Key_AltGr,
        Qt.Key_Super_L,
        Qt.Key_Super_R,
        Qt.Key_Hyper_L,
        Qt.Key_Hyper_R,
        Qt.Key_Direction_L,
        Qt.Key_Direction_R,
    )
    if event.key() in modifiers:  # Only modifier pressed
        raise ValueError("Modifiers do not have a stand-alone name")
    return (*_get_modifier_names(event), *_get_base_keysequence(event)) 
Example 6
Project: programming_with_python   Author: royqh1979   File: moveSphere.py    MIT License 6 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        global Xvalue,Yvalue,Angle
        if event.key() == QtCore.Qt.Key_R:
            Xvalue = Yvalue = Angle = 0.0
            self.update()
        elif event.key() == QtCore.Qt.Key_Space:
            Angle += 10.0
            self.update()
        elif event.key() == QtCore.Qt.Key_Up:
            Yvalue += 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_Down:
            Yvalue -= 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_Left:
            Xvalue -= 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_Right:
            Xvalue += 0.1
            self.update() 
Example 7
Project: CvStudio   Author: haruiz   File: image_viewer.py    MIT License 6 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        row = self.images_list_widget.currentRow()
        last_index = self.images_list_widget.count() - 1
        if event.key() == QtCore.Qt.Key_A:
            self.save_annotations()
            if row > 0:
                self.images_list_widget.setCurrentRow(row-1)
            else:
                self.images_list_widget.setCurrentRow(last_index)
        if event.key() == QtCore.Qt.Key_D:
            self.save_annotations()
            if row < last_index:
                self.images_list_widget.setCurrentRow(row+1)
            else:
                self.images_list_widget.setCurrentRow(0)
        if event.key() == QtCore.Qt.Key_W:
            self.viewer.selection_mode=SELECTION_MODE.POLYGON
        if event.key() == QtCore.Qt.Key_S:
            self.viewer.selection_mode=SELECTION_MODE.BOX
        super(ImageViewerWidget,self).keyPressEvent(event) 
Example 8
Project: barion   Author: xaratustrah   File: mainwindow.py    GNU General Public License v2.0 6 votes vote down vote up
def keyPressEvent(self, event):
        """
        Keypress event handler
        :return:
        """
        if type(event) == QKeyEvent:
            # here accept the event and do something
            if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:  # code enter key
                # self.do_calculate()
                self.on_pushButton_calculate()
                event.accept()
            if event.key() == Qt.Key_Space:
                # self.on_pushButton_table_data()
                event.accept()
            if event.key() == Qt.Key_Up:
                print('up')
                event.accept()
        else:
            event.ignore() 
Example 9
Project: cct   Author: awacha   File: scripteditor.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def eventFilter(self, obj: QtCore.QObject, event: QtCore.QEvent):
        if obj == self.scriptEdit and isinstance(event, QtGui.QKeyEvent):
            if event.key() == QtCore.Qt.Key_Tab and event.type()==QtCore.QEvent.KeyPress:
                self.scriptEdit.insertPlainText('    ')
                return True
            return super().eventFilter(obj, event)
        else:
            return super().eventFilter(obj, event) 
Example 10
Project: PyQt-multifunctional-uart-helper   Author: IronSublimate   File: widgetpainter.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, a0: QtGui.QKeyEvent):
        if a0.key() == Qt.Key_P:
            # print("Key press")
            self.pause = not self.pause
            if self.pause:
                self.label_pause.setText("已暂停")
            else:
                self.label_pause.clear() 
Example 11
Project: bw-model-viewer   Author: RenolY2   File: bw_model_viewer.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent):
        if event.key() == Qt.Key_Shift:
            self.waterbox_renderer.shift_is_pressed = True

        if event.key() == Qt.Key_W:
            self.waterbox_renderer.MOVE_FORWARD = 1
        elif event.key() == Qt.Key_S:
            self.waterbox_renderer.MOVE_BACKWARD = 1
        elif event.key() == Qt.Key_A:
            self.waterbox_renderer.MOVE_LEFT = 1
        elif event.key() == Qt.Key_D:
            self.waterbox_renderer.MOVE_RIGHT = 1
        elif event.key() == Qt.Key_Q:
            self.waterbox_renderer.MOVE_UP = 1
        elif event.key() == Qt.Key_E:
            self.waterbox_renderer.MOVE_DOWN = 1
        elif event.key() == Qt.Key_R:
            self.waterbox_renderer.ROTATE_LEFT = 1
        elif event.key() == Qt.Key_T:
            self.waterbox_renderer.ROTATE_RIGHT = 1

        elif event.key() == Qt.Key_Up:
            row = self.model_list.currentRow()-1
            if row < 0:
                row = 0
            self.model_list.setCurrentRow(row)

        elif event.key() == Qt.Key_Down:
            row = self.model_list.currentRow()+1
            if self.res_file is None:
                row = 0
            elif row >= len(self.res_file.models):
                row = len(self.res_file.models)-1
            self.model_list.setCurrentRow(row) 
Example 12
Project: openspectra   Author: openspectra   File: plotdisplay.py    Apache License 2.0 5 votes vote down vote up
def keyPressEvent(self, event:QKeyEvent):
        # http://doc.qt.io/qt-5/qt.html#Key-enum
        # LimitValueLineEdit.__LOG.debug("{0} edit key press, key: {1}",
        #     self.__name, event.key())
        super().keyPressEvent(event)
        if event.key() == Qt.Key_Return and self.hasAcceptableInput():
            self.value_changed.emit(float(self.text())) 
Example 13
Project: lyric-grabber   Author: aaronhktan   File: detail_dialog.py    MIT License 5 votes vote down vote up
def undoEvent(self):
    undoEvent = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Z, QtCore.Qt.ControlModifier)
    QtCore.QCoreApplication.sendEvent(self._lyricsQLabel, undoEvent) 
Example 14
Project: lyric-grabber   Author: aaronhktan   File: detail_dialog.py    MIT License 5 votes vote down vote up
def redoEvent(self):
    redoEvent = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Z, QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier)
    QtCore.QCoreApplication.sendEvent(self._lyricsQLabel, redoEvent) 
Example 15
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def _get_modifier_names(event: Union[QKeyEvent, QMouseEvent]) -> List[str]:
    """Return the names of all modifiers pressed in the event."""
    modmask2str = {
        Qt.ControlModifier: "<ctrl>",
        Qt.AltModifier: "<alt>",
        Qt.MetaModifier: "<meta>",
    }
    modifiers = event.modifiers()
    return [
        mod_name
        for mask, mod_name in modmask2str.items()
        if modifiers & mask  # type: ignore
    ] 
Example 16
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def _get_base_keysequence(event: QKeyEvent) -> SequenceT:
    """Get main keyname part of QKeyEvent.

    Converts special keys to usable names and uses event.text() otherwise. Is a sequence
    to allow prepending <shift> to special keys.

    Args:
        event: The emitted QKeyEvent.
    Returns:
        Name of the main key press escaping special keys.
    """
    special_keys = {
        Qt.Key_Space: "<space>",
        Qt.Key_Backtab: "<tab>",
        Qt.Key_Tab: "<tab>",
        Qt.Key_Escape: "<escape>",
        Qt.Key_Enter: "<enter>",
        Qt.Key_Return: "<return>",
        Qt.Key_Backspace: "<backspace>",
        Qt.Key_Left: "<left>",
        Qt.Key_Right: "<right>",
        Qt.Key_Up: "<up>",
        Qt.Key_Down: "<down>",
        Qt.Key_Home: "<home>",
        Qt.Key_End: "<end>",
        Qt.Key_PageUp: "<page-up>",
        Qt.Key_PageDown: "<page-down>",
        Qt.Key_Home: "<home>",
        Qt.Key_End: "<end>",
    }
    if event.key() in special_keys:
        # Parse shift here as the key does not support it otherwise
        text = special_keys[event.key()]  # type: ignore
        if event.modifiers() & Qt.ShiftModifier:  # type: ignore
            return "<shift>", text
        return (text,)
    if event.key() == Qt.Key_Colon:  # Required as : is the separator
        return ("<colon>",)
    if event.text().isprintable():
        return (event.text(),)
    return (QKeySequence(event.key()).toString().lower(),) 
Example 17
Project: vimiv-qt   Author: karlch   File: test_eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def test_keyevent_to_sequence(qtkey, modifier, keyname, expected):
    event = QKeyEvent(QEvent.KeyPress, qtkey, modifier, keyname)
    assert eventhandler.keyevent_to_sequence(event) == expected 
Example 18
Project: vidcutter   Author: ozmartian   File: mpvwidget.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent) -> None:
        if event.key() in {Qt.Key_F, Qt.Key_Escape}:
            event.accept()
            if self.parent is None:
                self.originalParent.toggleFullscreen()
            else:
                self.parent.toggleFullscreen()
        elif self.isFullScreen():
            self.originalParent.keyPressEvent(event)
        else:
            super(mpvWidget, self).keyPressEvent(event) 
Example 19
Project: vidcutter   Author: ozmartian   File: videoslider.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent) -> None:
        qApp.sendEvent(self.parent, event)

    # def mouseMoveEvent(self, event: QMouseEvent) -> None:
    #     opt = QStyleOptionSlider()
    #     self.initStyleOption(opt)
    #     handle = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
    #     if handle.x() <= event.pos().x() <= (handle.x() + handle.width()):
    #         self.setCursor(Qt.PointingHandCursor)
    #         self._handleHover = True
    #     else:
    #         self.unsetCursor()
    #         self._handleHover = False
    #     self.initStyle()
    #     super(VideoSlider, self).mouseMoveEvent(event) 
Example 20
Project: mp_python   Author: kerryeon   File: cmd.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event):
        if type(event) == QKeyEvent:
            # enter event
            if event.key() in [Qt.Key_Enter, 16777220]:
                self.execute() 
Example 21
Project: ciba   Author: FindHao   File: entry.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, e):
        keyEvent = QKeyEvent(e)
        ctrl = e.modifiers() & Qt.ControlModifier
        shift = e.modifiers() & Qt.ShiftModifier
        if keyEvent.key() == QtCore.Qt.Key_Escape:
            self.hide()
        # ctrl+c 粘贴处理过的字符串,ctrl+shift+c处理原生选择的数据
        elif ctrl and keyEvent.key() == QtCore.Qt.Key_C: 
            self.clipboard.setText(self.query.word.text)
        elif ctrl and keyEvent.key() == QtCore.Qt.Key_C and shift:
            self.clipboard.setText(self.query.word.raw_text) 
Example 22
Project: thegame   Author: afq984   File: view.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        key = event.key()
        if key in self.keys:
            self.keys[key] = True 
Example 23
Project: thegame   Author: afq984   File: view.py    MIT License 5 votes vote down vote up
def keyReleaseEvent(self, event: QKeyEvent):
        if event.isAutoRepeat():
            event.ignore()
            return
        key = event.key()
        if key in self.keys:
            self.keys[key] = False 
Example 24
Project: programming_with_python   Author: royqh1979   File: SquareAnnulus4.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        if event.key() == QtCore.Qt.Key_Space:
            self._wire = not self._wire
            self.repaint() 
Example 25
Project: programming_with_python   Author: royqh1979   File: hemisphere.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        global p,q,Xangle,Yangle,Zangle
        key = event.key()
        mod = event.modifiers()
        if key == Qt.Key_P and mod != Qt.ShiftModifier and p<50:
            p+=1
            self.update()
        elif key == Qt.Key_P and mod == Qt.ShiftModifier and p>6:
            p-=1
            self.update()
        elif key == Qt.Key_Q and mod != Qt.ShiftModifier and q<50:
            q+=1
            self.update()
        elif key == Qt.Key_Q and mod == Qt.ShiftModifier and q>4:
            q-=1
            self.update()
        elif key == Qt.Key_X:
            if mod != Qt.ShiftModifier:
                Xangle += 5.0
            else:
                Xangle -= 5.0
            Xangle %= 360
            self.update()
        elif key == Qt.Key_Y:
            if mod != Qt.ShiftModifier:
                Yangle += 5.0
            else:
                Yangle -= 5.0
            Yangle %= 360
            self.update()
        elif key == Qt.Key_Z:
            if mod != Qt.ShiftModifier:
                Zangle += 5.0
            else:
                Zangle -= 5.0
            Zangle %= 360
            self.update() 
Example 26
Project: programming_with_python   Author: royqh1979   File: moveSolidSphere.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        global Xvalue,Yvalue,Angle,_depth
        if event.key() == QtCore.Qt.Key_R:
            Xvalue = Yvalue = Angle = 0.0
            self.update()
        elif event.key() == QtCore.Qt.Key_Space:
            Angle += 10.0
            self.update()
        elif event.key() == QtCore.Qt.Key_Up:
            Yvalue += 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_Down:
            Yvalue -= 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_Left:
            Xvalue -= 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_Right:
            Xvalue += 0.1
            self.update()
        elif event.key() == QtCore.Qt.Key_PageUp and _depth < 5 :
            _depth += 1
            self.update()
        elif event.key() == QtCore.Qt.Key_PageDown and _depth>0 :
            _depth -= 1
            self.update() 
Example 27
Project: programming_with_python   Author: royqh1979   File: SquareAnnulus1.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        if event.key() == QtCore.Qt.Key_Space:
            self._wire = not self._wire
            self.update() 
Example 28
Project: programming_with_python   Author: royqh1979   File: hemisphere.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        global p,q,Xangle,Yangle,Zangle
        key = event.key()
        mod = event.modifiers()
        if key == Qt.Key_P and mod != Qt.ShiftModifier and p<50:
            p+=1
            self.update()
        elif key == Qt.Key_P and mod == Qt.ShiftModifier and p>6:
            p-=1
            self.update()
        elif key == Qt.Key_Q and mod != Qt.ShiftModifier and q<50:
            q+=1
            self.update()
        elif key == Qt.Key_Q and mod == Qt.ShiftModifier and q>4:
            q-=1
            self.update()
        elif key == Qt.Key_X:
            if mod != Qt.ShiftModifier:
                Xangle += 5.0
            else:
                Xangle -= 5.0
            Xangle %= 360
            self.update()
        elif key == Qt.Key_Y:
            if mod != Qt.ShiftModifier:
                Yangle += 5.0
            else:
                Yangle -= 5.0
            Yangle %= 360
            self.update()
        elif key == Qt.Key_Z:
            if mod != Qt.ShiftModifier:
                Zangle += 5.0
            else:
                Zangle -= 5.0
            Zangle %= 360
            self.update() 
Example 29
Project: CvStudio   Author: haruiz   File: main_window.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, evt: QtGui.QKeyEvent) -> None:
        self.keyPressed.emit(evt)
        super(MainWindow, self).keyPressEvent(evt) 
Example 30
Project: CvStudio   Author: haruiz   File: image_graphics_view.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        if self._current_polygon and event.key() == QtCore.Qt.Key_Space:
            points=self._current_polygon.points
            self._current_polygon.label=self.current_label
            self._current_polygon=None
            self.selection_mode = SELECTION_MODE.NONE
            self._polygon_guide_line.hide()
            self.setDragMode(QGraphicsView.ScrollHandDrag)
        super(ImageViewer, self).keyPressEvent(event) 
Example 31
Project: CvStudio   Author: haruiz   File: imageViewer.py    MIT License 5 votes vote down vote up
def keyReleaseEvent(self,keyEvent):
        """Overrides to make sure key release passed on to other classes.

        :param QKeyEvent keyEvent: instance of |QKeyEvent|"""
        assert isinstance(keyEvent,QtGui.QKeyEvent)
        # print("graphicsView keyRelease count=%d, autoRepeat=%s" %
        # (keyEvent.count(), keyEvent.isAutoRepeat()))
        keyEvent.ignore()
        # super(SynchableGraphicsView, self).keyReleaseEvent(keyEvent) 
Example 32
Project: CvStudio   Author: haruiz   File: imageViewer.py    MIT License 5 votes vote down vote up
def keyPressEvent(self,keyEvent):
        """Overrides to enable panning while dragging.

        :param QKeyEvent keyEvent: instance of |QKeyEvent|"""
        assert isinstance(keyEvent,QtGui.QKeyEvent)
        if keyEvent.key() == QtCore.Qt.Key_Space:
            if (not keyEvent.isAutoRepeat() and
                    not self._imageViewer.handDragging):
                self._imageViewer.enableHandDrag(True)
            keyEvent.accept()
        else:
            keyEvent.ignore()
            super(MainWindow,self).keyPressEvent(keyEvent) 
Example 33
Project: Python-CTPAPI   Author: nicai0609   File: candle_demo.py    MIT License 5 votes vote down vote up
def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
        """
        Reimplement this method of parent to move chart horizontally and zoom in/out.
        """
        if event.key() == QtCore.Qt.Key_Left:
            self._on_key_left()
        elif event.key() == QtCore.Qt.Key_Right:
            self._on_key_right()
        elif event.key() == QtCore.Qt.Key_Up:
            self._on_key_up()
        elif event.key() == QtCore.Qt.Key_Down:
            self._on_key_down() 
Example 34
Project: schmereo   Author: cmbruns   File: main_window.py    GNU General Public License v2.0 5 votes vote down vote up
def keyReleaseEvent(self, event: QtGui.QKeyEvent):
        if event.key() == Qt.Key_Escape:
            self.marker_manager.set_marker_mode(False) 
Example 35
Project: emacs-application-framework   Author: manateelazycat   File: buffer.py    GNU General Public License v3.0 5 votes vote down vote up
def fake_key_event(self, event_string):
        # Init.
        text = event_string
        modifier = Qt.NoModifier

        # Get key text.
        if event_string in qt_text_dict:
            text = qt_text_dict[event_string]

        if event_string in ["TAB", "<backtab>"]:
            text = ""

        if event_string == "<backtab>":
            modifier = Qt.ShiftModifier

        if event_string.isupper()    :
            modifier = Qt.ShiftModifier

        # print("Press: ", event_string)

        # NOTE: don't ignore text argument, otherwise QWebEngineView not respond key event.
        key_press = QKeyEvent(QEvent.KeyPress, qt_key_dict[event_string], modifier, text)

        for widget in self.get_key_event_widgets():
            QApplication.sendEvent(widget, key_press)

        self.fake_key_event_filter(event_string) 
Example 36
Project: tvlinker   Author: ozmartian   File: settings.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent) -> None:
        if event.key() in (Qt.Key_Enter, Qt.Key_Return):
            return
        super(Settings, self).keyPressEvent(event) 
Example 37
Project: nanovna-saver   Author: mihtjel   File: Marker.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None:
            if a0.type() == QtCore.QEvent.KeyPress:
                if a0.key() == QtCore.Qt.Key_Up and self.nextFrequency != -1:
                    a0.accept()
                    self.setText(str(self.nextFrequency))
                    self.textEdited.emit(self.text())
                    return
                elif a0.key() == QtCore.Qt.Key_Down and self.previousFrequency != -1:
                    a0.accept()
                    self.setText(str(self.previousFrequency))
                    self.textEdited.emit(self.text())
                    return
            super().keyPressEvent(a0) 
Example 38
Project: nanovna-saver   Author: mihtjel   File: Chart.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None:
        m = self.getActiveMarker()
        if m is not None and a0.modifiers() == QtCore.Qt.NoModifier:
            if a0.key() == QtCore.Qt.Key_Down or a0.key() == QtCore.Qt.Key_Left:
                m.frequencyInput.keyPressEvent(QtGui.QKeyEvent(a0.type(), QtCore.Qt.Key_Down, a0.modifiers()))
            elif a0.key() == QtCore.Qt.Key_Up or a0.key() == QtCore.Qt.Key_Right:
                m.frequencyInput.keyPressEvent(QtGui.QKeyEvent(a0.type(), QtCore.Qt.Key_Up, a0.modifiers()))
        else:
            super().keyPressEvent(a0) 
Example 39
Project: ANGRYsearch   Author: DoTheEvo   File: angrysearch.py    GNU General Public License v2.0 4 votes vote down vote up
def keyPressEvent(self, event):
        if type(event) == Qg.QKeyEvent:
            # ESC
            if event.key() == 16777216:
                self.close()
            # CTRL + Q
            if event.key() == 81:
                if event.modifiers() == Qc.Qt.ControlModifier:
                    self.close()
            # F6 KEY
            if event.key() == 16777269:
                self.center.search_input.selectAll()
                self.center.search_input.setFocus()
            # ALT + D
            if event.key() == 68 and event.modifiers() == Qc.Qt.AltModifier:
                self.center.search_input.selectAll()
                self.center.search_input.setFocus()
            # CTRL + L
            if event.key() == 76:
                if event.modifiers() == Qc.Qt.ControlModifier:
                    self.center.search_input.selectAll()
                    self.center.search_input.setFocus()
            # F8 FOR REGEX SEARCH MODE
            if event.key() == 16777271:
                self.setting_params['regex_mode'] = not self.setting_params['regex_mode']
                self.settings.setValue('regex_mode', self.setting_params['regex_mode'])
                self.regex_mode_color_indicator()
                if self.setting_params['regex_mode']:
                    self.status_bar.showMessage('REGEX MODE ENABLED')
                else:
                    self.status_bar.showMessage('REGEX MODE DISABLED')
            # CTRL + W
            if event.key() == 87:
                if event.modifiers() == Qc.Qt.ControlModifier:
                    input_text = self.center.search_input.text().split()
                    if not input_text:
                        return
                    last_removed = ' '.join(input_text[:-1])
                    if len(input_text) > 1:
                        last_removed = last_removed + ' '
                    self.center.search_input.setText(last_removed)

            event.accept()
        else:
            event.ignore() 
Example 40
Project: vidcutter   Author: ozmartian   File: videocutter.py    GNU General Public License v3.0 4 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent) -> None:
        if self.mediaAvailable:

            if event.key() == Qt.Key_Space:
                self.playMedia()
                return

            if event.key() == Qt.Key_Escape and self.isFullScreen():
                self.toggleFullscreen()
                return

            if event.key() == Qt.Key_F:
                self.toggleFullscreen()
                return

            if event.key() == Qt.Key_Home:
                self.setPosition(self.seekSlider.minimum())
                return

            if event.key() == Qt.Key_End:
                self.setPosition(self.seekSlider.maximum())
                return

            if event.key() == Qt.Key_Left:
                self.mpvWidget.frameBackStep()
                self.setPlayButton(False)
                return

            if event.key() == Qt.Key_Down:
                if qApp.queryKeyboardModifiers() == Qt.ShiftModifier:
                    self.mpvWidget.seek(-self.level2Seek, 'relative+exact')
                else:
                    self.mpvWidget.seek(-self.level1Seek, 'relative+exact')
                return

            if event.key() == Qt.Key_Right:
                self.mpvWidget.frameStep()
                self.setPlayButton(False)
                return

            if event.key() == Qt.Key_Up:
                if qApp.queryKeyboardModifiers() == Qt.ShiftModifier:
                    self.mpvWidget.seek(self.level2Seek, 'relative+exact')
                else:
                    self.mpvWidget.seek(self.level1Seek, 'relative+exact')
                return

            if event.key() in {Qt.Key_Return, Qt.Key_Enter} and \
                    (not self.timeCounter.hasFocus() and not self.frameCounter.hasFocus()):
                if self.toolbar_start.isEnabled():
                    self.clipStart()
                elif self.toolbar_end.isEnabled():
                    self.clipEnd()
                return

        super(VideoCutter, self).keyPressEvent(event)