Add a tab-scope object registry.

This commit is contained in:
Florian Bruhin 2014-09-25 07:43:50 +02:00
parent 4067b584ec
commit e8ce45c440
2 changed files with 15 additions and 0 deletions

View File

@ -36,6 +36,13 @@ class UnsetObject:
__slots__ = ()
class RegistryUnavailableError(Exception):
"""Exception raised when a certain registry does not exist yet."""
pass
_UNSET = UnsetObject()
@ -81,6 +88,11 @@ def _get_registry(scope):
"""Get the correct registry for a given scope."""
if scope == 'global':
return global_registry
elif scope == 'tab':
widget = get('tabbed-browser').currentWidget()
if widget is None:
raise RegistryUnavailableError(scope)
return widget.registry
else:
raise ValueError("Invalid scope '{}'!".format(scope))

View File

@ -51,6 +51,7 @@ class WebView(QWebView):
open_target: Where to open the next tab ("normal", "tab", "tab_bg")
viewing_source: Whether the webview is currently displaying source
code.
registry: The ObjectRegistry associated with this tab.
_cur_url: The current URL (accessed via cur_url property).
_has_ssl_errors: Whether SSL errors occured during loading.
_zoom: A NeighborList with the zoom levels.
@ -89,6 +90,8 @@ class WebView(QWebView):
self._cur_url = None
self.cur_url = QUrl()
self.progress = 0
self.registry = objreg.ObjectRegistry()
objreg.register('webview', self, registry=self.registry)
page = webpage.BrowserPage(self)
self.setPage(page)
self.hintmanager = hints.HintManager(self)