Add a tab-scope object registry.
This commit is contained in:
parent
4067b584ec
commit
e8ce45c440
@ -36,6 +36,13 @@ class UnsetObject:
|
|||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
||||||
|
class RegistryUnavailableError(Exception):
|
||||||
|
|
||||||
|
"""Exception raised when a certain registry does not exist yet."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
_UNSET = UnsetObject()
|
_UNSET = UnsetObject()
|
||||||
|
|
||||||
|
|
||||||
@ -81,6 +88,11 @@ def _get_registry(scope):
|
|||||||
"""Get the correct registry for a given scope."""
|
"""Get the correct registry for a given scope."""
|
||||||
if scope == 'global':
|
if scope == 'global':
|
||||||
return global_registry
|
return global_registry
|
||||||
|
elif scope == 'tab':
|
||||||
|
widget = get('tabbed-browser').currentWidget()
|
||||||
|
if widget is None:
|
||||||
|
raise RegistryUnavailableError(scope)
|
||||||
|
return widget.registry
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid scope '{}'!".format(scope))
|
raise ValueError("Invalid scope '{}'!".format(scope))
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ class WebView(QWebView):
|
|||||||
open_target: Where to open the next tab ("normal", "tab", "tab_bg")
|
open_target: Where to open the next tab ("normal", "tab", "tab_bg")
|
||||||
viewing_source: Whether the webview is currently displaying source
|
viewing_source: Whether the webview is currently displaying source
|
||||||
code.
|
code.
|
||||||
|
registry: The ObjectRegistry associated with this tab.
|
||||||
_cur_url: The current URL (accessed via cur_url property).
|
_cur_url: The current URL (accessed via cur_url property).
|
||||||
_has_ssl_errors: Whether SSL errors occured during loading.
|
_has_ssl_errors: Whether SSL errors occured during loading.
|
||||||
_zoom: A NeighborList with the zoom levels.
|
_zoom: A NeighborList with the zoom levels.
|
||||||
@ -89,6 +90,8 @@ class WebView(QWebView):
|
|||||||
self._cur_url = None
|
self._cur_url = None
|
||||||
self.cur_url = QUrl()
|
self.cur_url = QUrl()
|
||||||
self.progress = 0
|
self.progress = 0
|
||||||
|
self.registry = objreg.ObjectRegistry()
|
||||||
|
objreg.register('webview', self, registry=self.registry)
|
||||||
page = webpage.BrowserPage(self)
|
page = webpage.BrowserPage(self)
|
||||||
self.setPage(page)
|
self.setPage(page)
|
||||||
self.hintmanager = hints.HintManager(self)
|
self.hintmanager = hints.HintManager(self)
|
||||||
|
Loading…
Reference in New Issue
Block a user