diff options
-rw-r--r-- | qutebrowser/browser/webengine/notification.py | 32 | ||||
-rw-r--r-- | qutebrowser/misc/objects.py | 4 | ||||
-rw-r--r-- | qutebrowser/utils/qtutils.py | 7 |
3 files changed, 20 insertions, 23 deletions
diff --git a/qutebrowser/browser/webengine/notification.py b/qutebrowser/browser/webengine/notification.py index 7ab769659..a5ba56b62 100644 --- a/qutebrowser/browser/webengine/notification.py +++ b/qutebrowser/browser/webengine/notification.py @@ -49,20 +49,18 @@ import itertools import functools import subprocess from typing import Any, List, Dict, Optional, Iterator, TYPE_CHECKING -from qutebrowser.qt import QtWidgets if TYPE_CHECKING: # putting these behind TYPE_CHECKING also means this module is importable # on installs that don't have these - from qutebrowser.qt import QtWebEngineWidgets, QtWebEngineCore, QWebEngineNotification - from qutebrowser.qt import QWebEngineProfile + from qutebrowser.qt import QtWebEngineWidgets, QtWebEngineCore from qutebrowser.config import config from qutebrowser.misc import objects from qutebrowser.utils import ( qtutils, log, utils, debug, message, version, objreg, resources, ) -from qutebrowser.qt import QtWebEngine, QtGui, QtDBus, QtCore, sip +from qutebrowser.qt import QtWidgets, QtWebEngine, QtGui, QtDBus, QtCore, sip bridge: Optional['NotificationBridgePresenter'] = None @@ -123,7 +121,7 @@ class AbstractNotificationAdapter(QtCore.QObject): def present( self, - qt_notification: "QWebEngineNotification", + qt_notification: "QtWebEngineCore.QWebEngineNotification", *, replaces_id: Optional[int], ) -> int: @@ -169,7 +167,7 @@ class NotificationBridgePresenter(QtCore.QObject): super().__init__(parent) assert _notifications_supported() - self._active_notifications: Dict[int, 'QWebEngineNotification'] = {} + self._active_notifications: Dict[int, 'QtWebEngineCore.QWebEngineNotification'] = {} self._adapter: Optional[AbstractNotificationAdapter] = None config.instance.changed.connect(self._init_adapter) @@ -227,7 +225,7 @@ class NotificationBridgePresenter(QtCore.QObject): self._adapter.error.connect(self._on_adapter_error) self._adapter.clear_all.connect(self._on_adapter_clear_all) - def install(self, profile: "QWebEngineProfile") -> None: + def install(self, profile: "QtWebEngineWidgets.QWebEngineProfile") -> None: """Set the profile to use this bridge as the presenter.""" if QtWebEngine.PYQT_WEBENGINE_VERSION < 0x050F00: # PyQtWebEngine unrefs the callback after it's called, for some @@ -235,14 +233,14 @@ class NotificationBridgePresenter(QtCore.QObject): # its refcount to prevent it from getting GC'd. Otherwise, random # methods start getting called with the notification as `self`, or # segfaults happen, or other badness. - def _present_and_reset(qt_notification: "QWebEngineNotification") -> None: + def _present_and_reset(qt_notification: "QtWebEngineCore.QWebEngineNotification") -> None: profile.setNotificationPresenter(_present_and_reset) self.present(qt_notification) profile.setNotificationPresenter(_present_and_reset) else: profile.setNotificationPresenter(self.present) - def present(self, qt_notification: "QWebEngineNotification") -> None: + def present(self, qt_notification: "QtWebEngineCore.QWebEngineNotification") -> None: """Show a notification using the configured adapter. Lazily initializes a suitable adapter if none exists yet. @@ -281,7 +279,7 @@ class NotificationBridgePresenter(QtCore.QObject): def _find_replaces_id( self, - new_notification: "QWebEngineNotification", + new_notification: "QtWebEngineCore.QWebEngineNotification", ) -> Optional[int]: """Find an existing notification to replace. @@ -361,7 +359,7 @@ class NotificationBridgePresenter(QtCore.QObject): return self._focus_first_matching_tab(notification) - def _focus_first_matching_tab(self, notification: "QWebEngineNotification") -> None: + def _focus_first_matching_tab(self, notification: "QtWebEngineCore.QWebEngineNotification") -> None: for win_id in objreg.window_registry: tabbedbrowser = objreg.get("tabbed-browser", window=win_id, scope="window") for idx, tab in enumerate(tabbedbrowser.widgets()): @@ -441,7 +439,7 @@ class SystrayNotificationAdapter(AbstractNotificationAdapter): def present( self, - qt_notification: "QWebEngineNotification", + qt_notification: "QtWebEngineCore.QWebEngineNotification", *, replaces_id: Optional[int], ) -> int: @@ -503,7 +501,7 @@ class MessagesNotificationAdapter(AbstractNotificationAdapter): def present( self, - qt_notification: "QWebEngineNotification", + qt_notification: "QtWebEngineCore.QWebEngineNotification", *, replaces_id: Optional[int], ) -> int: @@ -522,7 +520,7 @@ class MessagesNotificationAdapter(AbstractNotificationAdapter): def on_web_closed(self, _notification_id: int) -> None: """We can't close messages.""" - def _format_message(self, qt_notification: "QWebEngineNotification") -> str: + def _format_message(self, qt_notification: "QtWebEngineCore.QWebEngineNotification") -> str: title = html.escape(qt_notification.title()) body = html.escape(qt_notification.message()) hint = "" if qt_notification.icon().isNull() else " (image not shown)" @@ -563,7 +561,7 @@ class HerbeNotificationAdapter(AbstractNotificationAdapter): def present( self, - qt_notification: "QWebEngineNotification", + qt_notification: "QtWebEngineCore.QWebEngineNotification", *, replaces_id: Optional[int], ) -> int: @@ -584,7 +582,7 @@ class HerbeNotificationAdapter(AbstractNotificationAdapter): def _message_lines( self, - qt_notification: "QWebEngineNotification", + qt_notification: "QtWebEngineCore.QWebEngineNotification", ) -> Iterator[str]: """Get the lines to display for this notification.""" yield qt_notification.title() @@ -928,7 +926,7 @@ class DBusNotificationAdapter(AbstractNotificationAdapter): def present( self, - qt_notification: "QWebEngineNotification", + qt_notification: "QtWebEngineCore.QWebEngineNotification", *, replaces_id: Optional[int], ) -> int: diff --git a/qutebrowser/misc/objects.py b/qutebrowser/misc/objects.py index c20b547a2..e270e80a6 100644 --- a/qutebrowser/misc/objects.py +++ b/qutebrowser/misc/objects.py @@ -26,7 +26,7 @@ import argparse from typing import TYPE_CHECKING, Any, Dict, Set, Union, cast if TYPE_CHECKING: - from qutebrowser.qt import QtWidgets, QApplication + from qutebrowser.qt import QtWidgets from qutebrowser.utils import usertypes from qutebrowser.commands import command @@ -47,4 +47,4 @@ backend: Union['usertypes.Backend', NoBackend] = NoBackend() commands: Dict[str, 'command.Command'] = {} debug_flags: Set[str] = set() args = cast(argparse.Namespace, None) -qapp = cast('QApplication', None) +qapp = cast('QtWidgets.QApplication', None) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 9b0186b55..90e7d252a 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -39,8 +39,7 @@ if QtWebKit: else: qWebKitVersion = None # type: ignore[assignment] # noqa: N816 if TYPE_CHECKING: - from qutebrowser.qt import QWebHistory - from qutebrowser.qt import QWebEngineHistory + from qutebrowser.qt import QtWebEngineWidgets from qutebrowser.misc import objects from qutebrowser.utils import usertypes, utils @@ -185,8 +184,8 @@ _QtSerializableType = Union[ QtCore.QObject, QtCore.QByteArray, QtCore.QUrl, - 'QWebEngineHistory', - 'QWebHistory' + 'QtWebEngineWidgets.QWebEngineHistory', + 'QtWebKit.QWebHistory' ] |