Fix :debug-webaction

This commit is contained in:
Florian Bruhin 2016-07-04 15:45:20 +02:00
parent deb0a10973
commit 70b7314b76
4 changed files with 28 additions and 5 deletions

View File

@ -32,6 +32,10 @@ from PyQt5.QtCore import Qt, QUrl, QEvent
from PyQt5.QtGui import QKeyEvent from PyQt5.QtGui import QKeyEvent
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
except ImportError:
QWebEnginePage = None
import pygments import pygments
import pygments.lexers import pygments.lexers
import pygments.formatters import pygments.formatters
@ -1644,13 +1648,23 @@ class CommandDispatcher:
action: The action to execute, e.g. MoveToNextChar. action: The action to execute, e.g. MoveToNextChar.
count: How many times to repeat the action. count: How many times to repeat the action.
""" """
member = getattr(QWebPage, action, None) tab = self._current_widget()
if not isinstance(member, QWebPage.WebAction):
if tab.backend == tabmod.Backend.QtWebKit:
assert QWebPage is not None
member = getattr(QWebPage, action, None)
base = QWebPage.WebAction
elif tab.backend == tabmod.Backend.QtWebEngine:
assert QWebEnginePage is not None
member = getattr(QWebEnginePage, action, None)
base = QWebEnginePage.WebAction
if not isinstance(member, base):
raise cmdexc.CommandError("{} is not a valid web action!".format( raise cmdexc.CommandError("{} is not a valid web action!".format(
action)) action))
view = self._current_widget()
for _ in range(count): for _ in range(count):
view.triggerPageAction(member) tab.run_webaction(member)
@cmdutils.register(instance='command-dispatcher', scope='window', @cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0, no_cmd_split=True) maxsplit=0, no_cmd_split=True)

View File

@ -482,6 +482,9 @@ class AbstractTab(QWidget):
def icon(self): def icon(self):
raise NotImplementedError raise NotImplementedError
def run_webaction(self, action):
raise NotImplementedError
def __repr__(self): def __repr__(self):
url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode), url = utils.elide(self.cur_url.toDisplayString(QUrl.EncodeUnicode),
100) 100)

View File

@ -156,6 +156,9 @@ class WebEngineViewTab(tab.AbstractTab):
def icon(self): def icon(self):
return self._widget.icon() return self._widget.icon()
def run_webaction(self, action):
self._widget.triggerPageAction(action)
def _connect_signals(self): def _connect_signals(self):
view = self._widget view = self._widget
page = view.page() page = view.page()

View File

@ -487,7 +487,7 @@ class WebViewTab(tab.AbstractTab):
action = QWebPage.ReloadAndBypassCache action = QWebPage.ReloadAndBypassCache
else: else:
action = QWebPage.Reload action = QWebPage.Reload
self._widget.triggerPageAction(action) self.run_webaction(action)
def stop(self): def stop(self):
self._widget.stop() self._widget.stop()
@ -499,6 +499,9 @@ class WebViewTab(tab.AbstractTab):
nam = self._widget.page().networkAccessManager() nam = self._widget.page().networkAccessManager()
nam.clear_all_ssl_errors() nam.clear_all_ssl_errors()
def run_webaction(self, action):
self._widget.triggerPageAction(action)
def _connect_signals(self): def _connect_signals(self):
view = self._widget view = self._widget
page = view.page() page = view.page()