Detach object registry from application.
This commit is contained in:
parent
aa646463b0
commit
b0a9ecf094
@ -53,7 +53,6 @@ class Application(QApplication):
|
|||||||
"""Main application instance.
|
"""Main application instance.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
registry: The object registry of global objects.
|
|
||||||
meta_registry: The object registry of object registries.
|
meta_registry: The object registry of object registries.
|
||||||
_args: ArgumentParser instance.
|
_args: ArgumentParser instance.
|
||||||
_commandrunner: The main CommandRunner instance.
|
_commandrunner: The main CommandRunner instance.
|
||||||
@ -84,8 +83,7 @@ class Application(QApplication):
|
|||||||
'main': False,
|
'main': False,
|
||||||
}
|
}
|
||||||
self.meta_registry = objreg.ObjectRegistry()
|
self.meta_registry = objreg.ObjectRegistry()
|
||||||
self.registry = objreg.ObjectRegistry()
|
self.meta_registry['global'] = objreg.global_registry
|
||||||
self.meta_registry['global'] = self.registry
|
|
||||||
objreg.register('app', self)
|
objreg.register('app', self)
|
||||||
self._shutting_down = False
|
self._shutting_down = False
|
||||||
self._keyparsers = None
|
self._keyparsers = None
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from PyQt5.QtCore import QCoreApplication, QObject
|
from PyQt5.QtCore import QObject
|
||||||
|
|
||||||
|
|
||||||
class UnsetObject:
|
class UnsetObject:
|
||||||
@ -70,6 +70,9 @@ class ObjectRegistry(collections.UserDict):
|
|||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
global_registry = ObjectRegistry()
|
||||||
|
|
||||||
|
|
||||||
def get(name, default=_UNSET):
|
def get(name, default=_UNSET):
|
||||||
"""Helper function to get an object.
|
"""Helper function to get an object.
|
||||||
|
|
||||||
@ -77,7 +80,7 @@ def get(name, default=_UNSET):
|
|||||||
default: A default to return if the object does not exist.
|
default: A default to return if the object does not exist.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return QCoreApplication.instance().registry[name]
|
return global_registry[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if default is not _UNSET:
|
if default is not _UNSET:
|
||||||
return default
|
return default
|
||||||
@ -93,13 +96,12 @@ def register(name, obj, update=False):
|
|||||||
obj: The object to register.
|
obj: The object to register.
|
||||||
update: If True, allows to update an already registered object.
|
update: If True, allows to update an already registered object.
|
||||||
"""
|
"""
|
||||||
registry = QCoreApplication.instance().registry
|
if not update and name in global_registry:
|
||||||
if not update and name in registry:
|
|
||||||
raise KeyError("Object '{}' is already registered ({})!".format(
|
raise KeyError("Object '{}' is already registered ({})!".format(
|
||||||
name, repr(registry[name])))
|
name, repr(global_registry[name])))
|
||||||
registry[name] = obj
|
global_registry[name] = obj
|
||||||
|
|
||||||
|
|
||||||
def delete(name):
|
def delete(name):
|
||||||
"""Helper function to unregister an object."""
|
"""Helper function to unregister an object."""
|
||||||
del QCoreApplication.instance().registry[name]
|
del global_registry[name]
|
||||||
|
Loading…
Reference in New Issue
Block a user