From ac4fd7c563832245b97846874a04721521aa5fbd Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 27 Feb 2018 08:20:06 +0100 Subject: [PATCH] Add KeyInfo.to_event() --- qutebrowser/browser/commands.py | 6 ++---- qutebrowser/keyinput/keyutils.py | 8 ++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 701c8324f..a5f60e2ac 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -27,7 +27,6 @@ import typing from PyQt5.QtWidgets import QApplication, QTabBar, QDialog from PyQt5.QtCore import pyqtSlot, Qt, QUrl, QEvent, QUrlQuery -from PyQt5.QtGui import QKeyEvent from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners @@ -2117,9 +2116,8 @@ class CommandDispatcher: raise cmdexc.CommandError(str(e)) for keyinfo in sequence: - args = (keyinfo.key, keyinfo.modifiers, keyinfo.text()) - press_event = QKeyEvent(QEvent.KeyPress, *args) - release_event = QKeyEvent(QEvent.KeyRelease, *args) + press_event = keyinfo.to_event(QEvent.KeyPress) + release_event = keyinfo.to_event(QEvent.KeyRelease) if global_: window = QApplication.focusWindow() diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py index 9be7b4d60..80bf59a35 100644 --- a/qutebrowser/keyinput/keyutils.py +++ b/qutebrowser/keyinput/keyutils.py @@ -24,8 +24,8 @@ import collections import itertools import attr -from PyQt5.QtCore import Qt -from PyQt5.QtGui import QKeySequence +from PyQt5.QtCore import Qt, QEvent +from PyQt5.QtGui import QKeySequence, QKeyEvent from qutebrowser.utils import utils, debug @@ -273,6 +273,10 @@ class KeyInfo: text = text.lower() return text + def to_event(self, typ=QEvent.KeyPress): + """Get a QKeyEvent from this KeyInfo.""" + return QKeyEvent(typ, self.key, self.modifiers, self.text()) + class KeySequence: