本文整理汇总了Python中PyQt5.QtCore.QEvent.KeyPress方法的典型用法代码示例。如果您正苦于以下问题:Python QEvent.KeyPress方法的具体用法?Python QEvent.KeyPress怎么用?Python QEvent.KeyPress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QEvent
的用法示例。
在下文中一共展示了QEvent.KeyPress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_keyrelease
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def _handle_keyrelease(self, event: QKeyEvent) -> bool:
"""Handle filtering of KeyRelease events.
Args:
event: The KeyPress to examine.
Return:
True if event should be filtered, False otherwise.
"""
# handle like matching KeyPress
keyevent = KeyEvent.from_event(event)
if keyevent in self._releaseevents_to_pass:
self._releaseevents_to_pass.remove(keyevent)
filter_this = False
else:
filter_this = True
if self.mode != usertypes.KeyMode.insert:
log.modes.debug("filter: {}".format(filter_this))
return filter_this
示例2: handle_event
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def handle_event(self, event: QEvent) -> bool:
"""Filter all events based on the currently set mode.
Also calls the real keypress handler.
Args:
event: The KeyPress to examine.
Return:
True if event should be filtered, False otherwise.
"""
handlers = {
QEvent.KeyPress: self._handle_keypress,
QEvent.KeyRelease: self._handle_keyrelease,
QEvent.ShortcutOverride:
functools.partial(self._handle_keypress, dry_run=True),
} # type: Mapping[QEvent.Type, Callable[[QKeyEvent], bool]]
handler = handlers[event.type()]
return handler(cast(QKeyEvent, event))
示例3: eventFilter
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def eventFilter(self, obj, e):
if obj == self.command and e.type() == QEvent.KeyPress:
history = self.device.history
if e.modifiers() & Qt.ControlModifier:
if e.key() == Qt.Key_H:
d = DeviceConsoleHistory(self.device.env.devices)
if d.exec_() == QDialog.Accepted:
self.command.setText(d.command)
elif len(history) > 0:
if e.key() == Qt.Key_E:
self.command.setText(history[0])
if e.key() == Qt.Key_Down:
self.command.completer().setModel(QStringListModel(history))
self.command.setText(' ')
self.command.completer().complete()
return False
return QDockWidget.eventFilter(self, obj, e)
示例4: test_surrogates
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def test_surrogates(key, modifiers, text, expected):
evt = QKeyEvent(QKeyEvent.KeyPress, key, modifiers, text)
assert str(keyutils.KeyInfo.from_event(evt)) == expected
示例5: test_append_event
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def test_append_event(self, old, key, modifiers, text, expected):
seq = keyutils.KeySequence.parse(old)
event = QKeyEvent(QKeyEvent.KeyPress, key, modifiers, text)
new = seq.append_event(event)
assert new == keyutils.KeySequence.parse(expected)
示例6: test_append_event_invalid
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def test_append_event_invalid(self, key):
seq = keyutils.KeySequence()
event = QKeyEvent(QKeyEvent.KeyPress, key, Qt.NoModifier, '')
with pytest.raises(keyutils.KeyParseError):
seq.append_event(event)
示例7: test_key_info_from_event
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def test_key_info_from_event():
ev = QKeyEvent(QEvent.KeyPress, Qt.Key_A, Qt.ShiftModifier, 'A')
info = keyutils.KeyInfo.from_event(ev)
assert info.key == Qt.Key_A
assert info.modifiers == Qt.ShiftModifier
示例8: to_event
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def to_event(self, typ: QEvent.Type = QEvent.KeyPress) -> QKeyEvent:
"""Get a QKeyEvent from this KeyInfo."""
return QKeyEvent(typ, self.key, self.modifiers, self.text())
示例9: __init__
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def __init__(self, parent: QObject = None) -> None:
super().__init__(parent)
self._activated = True
self._handlers = {
QEvent.KeyPress: self._handle_key_event,
QEvent.KeyRelease: self._handle_key_event,
QEvent.ShortcutOverride: self._handle_key_event,
}
示例10: eventFilter
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def eventFilter(self, source, event):
if event.type() == QEvent.KeyPress:
if event.key():
# show new keys in window
self.capturedKeyLabel.setText(str(QKeySequence(event.modifiers() | event.key()).toString()))
return super(KeyCapturingWindow, self).eventFilter(source, event)
示例11: eventFilter
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def eventFilter(self, obj, event):
if obj == self.edtCommand:
if event.type() == QEvent.KeyPress:
if event.key() == Qt.Key_Up:
self.prev_command()
return True
elif event.key() == Qt.Key_Down:
self.next_command()
return True
return False
else:
return super().eventFilter(obj, event)
示例12: handleEvent
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def handleEvent(self, event):
if event.type() == QEvent.KeyPress:
e = KeyEvent(KeyEvent.KeyPressEvent, self._qtKeyToUMKey(event.key()))
self.event.emit(e)
elif event.type() == QEvent.KeyRelease:
e = KeyEvent(KeyEvent.KeyReleaseEvent, self._qtKeyToUMKey(event.key()))
self.event.emit(e)
示例13: eventFilter
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def eventFilter(self, source, evt):
t = evt.type()
if t == QEvent.Wheel:
self.new_entry_flag = True
self.mouse_scroll_event(evt)
return True
elif t == QEvent.KeyPress:
self.new_entry_flag = True
if evt.key() == QtCore.Qt.Key_Return:
self.update_entry(evt)
return True
return False
示例14: eventFilter
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def eventFilter(self, receiver, event):
# catch up/down arrow key presses in hosts table
if event.type() == QEvent.KeyPress and receiver in self.hosts_table_views:
return self.filterKeyPressInHostsTableView(event.key(), receiver)
elif event.type() == QEvent.Close and receiver == self.main_window:
event.ignore()
self.view.appExit()
return True
else:
parent = super(MyEventFilter, self)
return parent.eventFilter(receiver, event) # normal event processing
示例15: simulateKeyPress
# 需要导入模块: from PyQt5.QtCore import QEvent [as 别名]
# 或者: from PyQt5.QtCore.QEvent import KeyPress [as 别名]
def simulateKeyPress(self, key_event):
self.mock_event.type = Mock(return_value=QEvent.KeyPress)
self.mock_event.key = Mock(return_value=key_event)