Get rid of meta registry

This commit is contained in:
Florian Bruhin 2014-10-05 21:50:14 +02:00
parent ce8409feb2
commit b6393a1841
5 changed files with 20 additions and 26 deletions

View File

@ -294,8 +294,6 @@ There are currently these object registries, also called 'scopes':
* The `tab` scope with objects which are per-tab (`hintmanager`, `webview`,
etc.). Passing this scope to `objreg.get()` always selects the object in the
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
+objreg.register(_name_, _object_[, scope=_scope_])+. An object should not be

View File

@ -287,20 +287,6 @@ class Application(QApplication):
lines.append(' ' * depth + repr(kid))
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):
"""Get all children of an object recursively as a string."""
output = ['']
@ -316,7 +302,7 @@ class Application(QApplication):
len(pyqt_lines)))
output += pyqt_lines
output += ['']
output += self._get_registered_objects()
output += objreg.dump_objects()
return '\n'.join(output)
def _recover_pages(self, forgiving=False):

View File

@ -97,9 +97,6 @@ class ObjectRegistry(collections.UserDict):
# The registry for global objects
global_registry = ObjectRegistry()
# The object registry of object registries.
meta_registry = ObjectRegistry()
meta_registry['global'] = global_registry
# The window registry.
window_registry = ObjectRegistry()
@ -148,8 +145,6 @@ def _get_registry(scope, window):
return _get_tab_registry()
elif scope == 'window':
return _get_window_registry(window)
elif scope == 'meta':
return meta_registry
else:
raise ValueError("Invalid scope '{}'!".format(scope))
@ -197,3 +192,22 @@ def delete(name, scope='global', window=None):
"""Helper function to unregister an object."""
reg = _get_registry(scope, window)
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

View File

@ -76,8 +76,6 @@ class MainWindow(QWidget):
self._commandrunner = None
self.win_id = win_id
self.registry = objreg.ObjectRegistry()
objreg.register('window-{}'.format(win_id), self.registry,
scope='meta')
objreg.window_registry[win_id] = self
objreg.register('main-window', self, scope='window', window=win_id)

View File

@ -108,8 +108,6 @@ class WebView(QWebView):
hintmanager.mouse_event.connect(self.on_mouse_event)
hintmanager.set_open_target.connect(self.set_force_open_target)
objreg.register('hintmanager', hintmanager, registry=self.registry)
objreg.register('tab-{}'.format(self.tab_id),
self.registry, scope='meta')
page.linkHovered.connect(self.linkHovered)
page.mainFrame().loadStarted.connect(self.on_load_started)
self.urlChanged.connect(self.on_url_changed)