Clean up :debug-webaction
This commit is contained in:
parent
822623f2ed
commit
b91d4ee9c2
@ -1655,7 +1655,7 @@ Syntax: +:debug-webaction 'action'+
|
|||||||
|
|
||||||
Execute a webaction.
|
Execute a webaction.
|
||||||
|
|
||||||
See http://doc.qt.io/qt-5/qwebpage.html#WebAction-enum for the available actions.
|
Available actions: http://doc.qt.io/archives/qt-5.5/qwebpage.html#WebAction-enum (WebKit) http://doc.qt.io/qt-5/qwebenginepage.html#WebAction-enum (WebEngine)
|
||||||
|
|
||||||
==== positional arguments
|
==== positional arguments
|
||||||
* +'action'+: The action to execute, e.g. MoveToNextChar.
|
* +'action'+: The action to execute, e.g. MoveToNextChar.
|
||||||
|
@ -105,7 +105,15 @@ class TabData:
|
|||||||
|
|
||||||
class AbstractAction:
|
class AbstractAction:
|
||||||
|
|
||||||
"""Attribute of AbstractTab for Qt WebActions."""
|
"""Attribute of AbstractTab for Qt WebActions.
|
||||||
|
|
||||||
|
Class attributes (overridden by subclasses):
|
||||||
|
action_class: The class actions are defined on (QWeb{Engine,}Page)
|
||||||
|
action_base: The type of the actions (QWeb{Engine,}Page.WebAction)
|
||||||
|
"""
|
||||||
|
|
||||||
|
action_class = None
|
||||||
|
action_base = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._widget = None
|
self._widget = None
|
||||||
@ -118,6 +126,13 @@ class AbstractAction:
|
|||||||
"""Save the current page."""
|
"""Save the current page."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def run_string(self, name):
|
||||||
|
"""Run a webaction based on its name."""
|
||||||
|
member = getattr(self.action_class, name, None)
|
||||||
|
if not isinstance(member, self.action_base):
|
||||||
|
raise WebTabError("{} is not a valid web action!".format(name))
|
||||||
|
self._widget.triggerPageAction(member)
|
||||||
|
|
||||||
|
|
||||||
class AbstractPrinting:
|
class AbstractPrinting:
|
||||||
|
|
||||||
|
@ -28,14 +28,6 @@ from PyQt5.QtWidgets import QApplication, QTabBar
|
|||||||
from PyQt5.QtCore import Qt, QUrl, QEvent, QUrlQuery
|
from PyQt5.QtCore import Qt, QUrl, QEvent, QUrlQuery
|
||||||
from PyQt5.QtGui import QKeyEvent
|
from PyQt5.QtGui import QKeyEvent
|
||||||
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
|
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
|
||||||
try:
|
|
||||||
from PyQt5.QtWebKitWidgets import QWebPage
|
|
||||||
except ImportError:
|
|
||||||
QWebPage = None
|
|
||||||
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
|
||||||
@ -1905,33 +1897,20 @@ class CommandDispatcher:
|
|||||||
def debug_webaction(self, action, count=1):
|
def debug_webaction(self, action, count=1):
|
||||||
"""Execute a webaction.
|
"""Execute a webaction.
|
||||||
|
|
||||||
See http://doc.qt.io/qt-5/qwebpage.html#WebAction-enum for the
|
Available actions:
|
||||||
available actions.
|
http://doc.qt.io/archives/qt-5.5/qwebpage.html#WebAction-enum (WebKit)
|
||||||
|
http://doc.qt.io/qt-5/qwebenginepage.html#WebAction-enum (WebEngine)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
tab = self._current_widget()
|
tab = self._current_widget()
|
||||||
|
|
||||||
if tab.backend == usertypes.Backend.QtWebKit:
|
|
||||||
assert QWebPage is not None
|
|
||||||
member = getattr(QWebPage, action, None)
|
|
||||||
base = QWebPage.WebAction
|
|
||||||
elif tab.backend == usertypes.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(
|
|
||||||
action))
|
|
||||||
|
|
||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
# This whole command is backend-specific anyways, so it makes no
|
try:
|
||||||
# sense to introduce some API for this.
|
tab.action.run_string(action)
|
||||||
# pylint: disable=protected-access
|
except browsertab.WebTabError as e:
|
||||||
tab._widget.triggerPageAction(member)
|
raise cmdexc.CommandError(str(e))
|
||||||
|
|
||||||
@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)
|
||||||
|
@ -79,17 +79,17 @@ _JS_WORLD_MAP = {
|
|||||||
|
|
||||||
class WebEngineAction(browsertab.AbstractAction):
|
class WebEngineAction(browsertab.AbstractAction):
|
||||||
|
|
||||||
"""QtWebKit implementations related to web actions."""
|
"""QtWebEngine implementations related to web actions."""
|
||||||
|
|
||||||
def _action(self, action):
|
action_class = QWebEnginePage
|
||||||
self._widget.triggerPageAction(action)
|
action_base = QWebEnginePage.WebAction
|
||||||
|
|
||||||
def exit_fullscreen(self):
|
def exit_fullscreen(self):
|
||||||
self._action(QWebEnginePage.ExitFullScreen)
|
self._widget.triggerPageAction(QWebEnginePage.ExitFullScreen)
|
||||||
|
|
||||||
def save_page(self):
|
def save_page(self):
|
||||||
"""Save the current page."""
|
"""Save the current page."""
|
||||||
self._action(QWebEnginePage.SavePage)
|
self._widget.triggerPageAction(QWebEnginePage.SavePage)
|
||||||
|
|
||||||
|
|
||||||
class WebEnginePrinting(browsertab.AbstractPrinting):
|
class WebEnginePrinting(browsertab.AbstractPrinting):
|
||||||
|
@ -57,6 +57,9 @@ class WebKitAction(browsertab.AbstractAction):
|
|||||||
|
|
||||||
"""QtWebKit implementations related to web actions."""
|
"""QtWebKit implementations related to web actions."""
|
||||||
|
|
||||||
|
action_class = QWebPage
|
||||||
|
action_base = QWebPage.WebAction
|
||||||
|
|
||||||
def exit_fullscreen(self):
|
def exit_fullscreen(self):
|
||||||
raise browsertab.UnsupportedOperationError
|
raise browsertab.UnsupportedOperationError
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user