From a6eab3e7ffcd9f6530c54931bbba3e0f108e0dd3 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 10 Jan 2021 10:37:25 +0000 Subject: [PATCH] system: Allows apps to be registered using strings Use instance tests to identify strings and substitute then for an instanciated class. Signed-off-by: Daniel Thompson --- wasp/apps/software.py | 3 +-- wasp/wasp.py | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wasp/apps/software.py b/wasp/apps/software.py index 2c7869c..a39cce0 100644 --- a/wasp/apps/software.py +++ b/wasp/apps/software.py @@ -63,8 +63,7 @@ class SoftwareApp(): if checkbox.touch(event): label = checkbox.label.replace(' ', '') if checkbox.state: - exec('import apps.{}'.format(module)) - exec('wasp.system.register(apps.{}.{}App())'.format(module, label)) + wasp.system.register('apps.{}.{}App'.format(module, label)) else: for app in wasp.system.launcher_ring: if type(app).__name__.startswith(label): diff --git a/wasp/wasp.py b/wasp/wasp.py index 79f706c..c9f40db 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -164,6 +164,10 @@ class Manager(): :param object app: The application to regsister """ + if isinstance(app, str): + exec('import ' + app[:app.rindex('.')]) + app = eval(app + '()') + if quick_ring == True: self.quick_ring.append(app) else: