Get rid of meta registry
This commit is contained in:
parent
ce8409feb2
commit
b6393a1841
@ -294,8 +294,6 @@ There are currently these object registries, also called 'scopes':
|
|||||||
* The `tab` scope with objects which are per-tab (`hintmanager`, `webview`,
|
* The `tab` scope with objects which are per-tab (`hintmanager`, `webview`,
|
||||||
etc.). Passing this scope to `objreg.get()` always selects the object in the
|
etc.). Passing this scope to `objreg.get()` always selects the object in the
|
||||||
currently focused tab.
|
currently focused tab.
|
||||||
* The `meta` scope which is an object registry of all other object registries,
|
|
||||||
mainly intended for debugging.
|
|
||||||
|
|
||||||
A new object can be registered by using
|
A new object can be registered by using
|
||||||
+objreg.register(_name_, _object_[, scope=_scope_])+. An object should not be
|
+objreg.register(_name_, _object_[, scope=_scope_])+. An object should not be
|
||||||
|
@ -287,20 +287,6 @@ class Application(QApplication):
|
|||||||
lines.append(' ' * depth + repr(kid))
|
lines.append(' ' * depth + repr(kid))
|
||||||
self._get_pyqt_objects(lines, kid, depth + 1)
|
self._get_pyqt_objects(lines, kid, depth + 1)
|
||||||
|
|
||||||
def _get_registered_objects(self):
|
|
||||||
"""Get all registered objects in all registries as a string."""
|
|
||||||
blocks = []
|
|
||||||
lines = []
|
|
||||||
for name, registry in objreg.meta_registry.items():
|
|
||||||
blocks.append((name, registry.dump_objects()))
|
|
||||||
for name, data in sorted(blocks, key=lambda e: e[0]):
|
|
||||||
lines.append("")
|
|
||||||
lines.append("{} object registry - {} objects:".format(
|
|
||||||
name, len(data)))
|
|
||||||
for line in data:
|
|
||||||
lines.append(" {}".format(line))
|
|
||||||
return lines
|
|
||||||
|
|
||||||
def get_all_objects(self):
|
def get_all_objects(self):
|
||||||
"""Get all children of an object recursively as a string."""
|
"""Get all children of an object recursively as a string."""
|
||||||
output = ['']
|
output = ['']
|
||||||
@ -316,7 +302,7 @@ class Application(QApplication):
|
|||||||
len(pyqt_lines)))
|
len(pyqt_lines)))
|
||||||
output += pyqt_lines
|
output += pyqt_lines
|
||||||
output += ['']
|
output += ['']
|
||||||
output += self._get_registered_objects()
|
output += objreg.dump_objects()
|
||||||
return '\n'.join(output)
|
return '\n'.join(output)
|
||||||
|
|
||||||
def _recover_pages(self, forgiving=False):
|
def _recover_pages(self, forgiving=False):
|
||||||
|
@ -97,9 +97,6 @@ class ObjectRegistry(collections.UserDict):
|
|||||||
|
|
||||||
# The registry for global objects
|
# The registry for global objects
|
||||||
global_registry = ObjectRegistry()
|
global_registry = ObjectRegistry()
|
||||||
# The object registry of object registries.
|
|
||||||
meta_registry = ObjectRegistry()
|
|
||||||
meta_registry['global'] = global_registry
|
|
||||||
# The window registry.
|
# The window registry.
|
||||||
window_registry = ObjectRegistry()
|
window_registry = ObjectRegistry()
|
||||||
|
|
||||||
@ -148,8 +145,6 @@ def _get_registry(scope, window):
|
|||||||
return _get_tab_registry()
|
return _get_tab_registry()
|
||||||
elif scope == 'window':
|
elif scope == 'window':
|
||||||
return _get_window_registry(window)
|
return _get_window_registry(window)
|
||||||
elif scope == 'meta':
|
|
||||||
return meta_registry
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid scope '{}'!".format(scope))
|
raise ValueError("Invalid scope '{}'!".format(scope))
|
||||||
|
|
||||||
@ -197,3 +192,22 @@ def delete(name, scope='global', window=None):
|
|||||||
"""Helper function to unregister an object."""
|
"""Helper function to unregister an object."""
|
||||||
reg = _get_registry(scope, window)
|
reg = _get_registry(scope, window)
|
||||||
del reg[name]
|
del reg[name]
|
||||||
|
|
||||||
|
|
||||||
|
def dump_objects():
|
||||||
|
"""Get all registered objects in all registries as a string."""
|
||||||
|
blocks = []
|
||||||
|
lines = []
|
||||||
|
blocks.append(('global', global_registry.dump_objects()))
|
||||||
|
for win_id in window_registry:
|
||||||
|
registry = _get_registry('window', window=win_id)
|
||||||
|
blocks.append(('window-{}'.format(win_id), registry.dump_objects()))
|
||||||
|
# FIXME: Add tab registries
|
||||||
|
for name, data in sorted(blocks, key=lambda e: e[0]):
|
||||||
|
lines.append("")
|
||||||
|
lines.append("{} object registry - {} objects:".format(
|
||||||
|
name, len(data)))
|
||||||
|
for line in data:
|
||||||
|
lines.append(" {}".format(line))
|
||||||
|
return lines
|
||||||
|
|
||||||
|
@ -76,8 +76,6 @@ class MainWindow(QWidget):
|
|||||||
self._commandrunner = None
|
self._commandrunner = None
|
||||||
self.win_id = win_id
|
self.win_id = win_id
|
||||||
self.registry = objreg.ObjectRegistry()
|
self.registry = objreg.ObjectRegistry()
|
||||||
objreg.register('window-{}'.format(win_id), self.registry,
|
|
||||||
scope='meta')
|
|
||||||
objreg.window_registry[win_id] = self
|
objreg.window_registry[win_id] = self
|
||||||
objreg.register('main-window', self, scope='window', window=win_id)
|
objreg.register('main-window', self, scope='window', window=win_id)
|
||||||
|
|
||||||
|
@ -108,8 +108,6 @@ class WebView(QWebView):
|
|||||||
hintmanager.mouse_event.connect(self.on_mouse_event)
|
hintmanager.mouse_event.connect(self.on_mouse_event)
|
||||||
hintmanager.set_open_target.connect(self.set_force_open_target)
|
hintmanager.set_open_target.connect(self.set_force_open_target)
|
||||||
objreg.register('hintmanager', hintmanager, registry=self.registry)
|
objreg.register('hintmanager', hintmanager, registry=self.registry)
|
||||||
objreg.register('tab-{}'.format(self.tab_id),
|
|
||||||
self.registry, scope='meta')
|
|
||||||
page.linkHovered.connect(self.linkHovered)
|
page.linkHovered.connect(self.linkHovered)
|
||||||
page.mainFrame().loadStarted.connect(self.on_load_started)
|
page.mainFrame().loadStarted.connect(self.on_load_started)
|
||||||
self.urlChanged.connect(self.on_url_changed)
|
self.urlChanged.connect(self.on_url_changed)
|
||||||
|
Loading…
Reference in New Issue
Block a user