Add post_event to tab API

This commit is contained in:
Florian Bruhin 2016-08-17 18:02:24 +02:00
parent 6f24221c54
commit 1b3d693a5e
3 changed files with 20 additions and 7 deletions

View File

@ -23,7 +23,7 @@ import itertools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QSizeF
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtWidgets import QWidget
from qutebrowser.keyinput import modeman
from qutebrowser.config import config
@ -532,6 +532,10 @@ class AbstractTab(QWidget):
self._load_status = val
self.load_status_changed.emit(val.name)
def post_event(self, evt):
"""Send the given event to the underlying widget."""
raise NotImplementedError
@pyqtSlot('QMouseEvent')
def _on_hint_mouse_event(self, evt):
"""Post a new mouse event from a hintmanager."""
@ -540,7 +544,7 @@ class AbstractTab(QWidget):
# focusProxy()?
log.modes.debug("Hint triggered, focusing {!r}".format(self))
self._widget.setFocus()
QApplication.postEvent(self._widget, evt)
self.post_event(evt)
@pyqtSlot(QUrl)
def _on_link_clicked(self, url):

View File

@ -200,12 +200,9 @@ class WebEngineScroller(browsertab.AbstractScroller):
# FIXME:qtwebengine Abort scrolling if the minimum/maximum was reached.
press_evt = QKeyEvent(QEvent.KeyPress, key, Qt.NoModifier, 0, 0, 0)
release_evt = QKeyEvent(QEvent.KeyRelease, key, Qt.NoModifier, 0, 0, 0)
recipient = self._widget.focusProxy()
for _ in range(count):
# If we get a segfault here, we might want to try sendEvent
# instead.
QApplication.postEvent(recipient, press_evt)
QApplication.postEvent(recipient, release_evt)
self._tab.post_event(press_evt)
self._tab.post_event(release_evt)
@pyqtSlot()
def _update_pos(self):
@ -516,3 +513,9 @@ class WebEngineTab(browsertab.AbstractTab):
page.contentsSizeChanged.connect(self.contents_size_changed)
except AttributeError:
log.stub('contentsSizeChanged, on Qt < 5.7')
def post_event(self, evt):
# If we get a segfault here, we might want to try sendEvent
# instead.
recipient = self._widget.focusProxy()
QApplication.postEvent(recipient, evt)

View File

@ -28,6 +28,7 @@ from PyQt5.QtCore import (pyqtSlot, Qt, QEvent, QUrl, QPoint, QTimer, QSizeF,
from PyQt5.QtGui import QKeyEvent
from PyQt5.QtWebKitWidgets import QWebPage, QWebFrame
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWidgets import QApplication
from PyQt5.QtPrintSupport import QPrinter
from qutebrowser.browser import browsertab
@ -677,3 +678,8 @@ class WebKitTab(browsertab.AbstractTab):
frame.contentsSizeChanged.connect(self._on_contents_size_changed)
frame.initialLayoutCompleted.connect(self._on_history_trigger)
page.link_clicked.connect(self._on_link_clicked)
def post_event(self, evt):
# If we get a segfault here, we might want to try sendEvent
# instead.
QApplication.postEvent(self._widget, evt)