Adjust :debug-webaction for new-style enums

With scoped enums, we don't need to check whether the member belongs to the enum
class anymore, we just get it directly from there.

Also needed for PyQt 6 because we can't access the members unscoped anymore.

TODO: Pick to master?
This commit is contained in:
Florian Bruhin 2022-05-19 16:51:14 +02:00
parent 76514547cf
commit 6ce8ff1e71
3 changed files with 4 additions and 8 deletions

View File

@ -153,7 +153,6 @@ class AbstractAction:
"""Attribute ``action`` of AbstractTab for Qt WebActions."""
action_class: Type[Union['QWebPage', 'QWebEnginePage']]
action_base: Type[Union['QWebPage.WebAction', 'QWebEnginePage.WebAction']]
def __init__(self, tab: 'AbstractTab') -> None:
@ -170,10 +169,10 @@ class AbstractAction:
def run_string(self, name: str) -> None:
"""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))
assert member is not None # for mypy
try:
member = getattr(self.action_base, name)
except AttributeError:
raise WebTabError(f"{name} is not a valid web action!")
self._widget.triggerPageAction(member)
def show_source(self, pygments: bool = False) -> None:

View File

@ -59,8 +59,6 @@ class WebEngineAction(browsertab.AbstractAction):
"""QtWebEngine implementations related to web actions."""
_widget: webview.WebEngineView
action_class = QWebEnginePage
action_base = QWebEnginePage.WebAction
def exit_fullscreen(self):

View File

@ -44,7 +44,6 @@ class WebKitAction(browsertab.AbstractAction):
"""QtWebKit implementations related to web actions."""
action_class = QWebPage
action_base = QWebPage.WebAction
_widget: webview.WebView