Add KeyInfo.to_event()

This commit is contained in:
Florian Bruhin 2018-02-27 08:20:06 +01:00
parent 1e8f72dfe6
commit ac4fd7c563
2 changed files with 8 additions and 6 deletions

View File

@ -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()

View File

@ -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: