diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2021-06-03 18:57:09 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2021-06-03 18:57:09 (GMT) |
| commit | e76a4afd8550145d4c43b3f1513b2fd209af8dd1 (patch) | |
| tree | 860e1634e283463f9ce7593fa75bca34ff152be3 | |
| parent | 0d385b8dc593b4e8207824d0e8ef9b22d2f9c98d (diff) | |
manager: Improve application registration
When an application is registered using a string that gives the class
name (e.g. "apps.chrono.ChronoApp") when we automatically delete
the module from a couple of namespaces. This ensures the garbage
collector can do a deeper clean when the application is unregistered.
We also provide a means to directly register watch faces (e.g. to
replace the default clock).
Fixes: #214
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
| -rw-r--r-- | wasp/wasp.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/wasp/wasp.py b/wasp/wasp.py index ad09dce..abcb974 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -18,6 +18,7 @@ import gc import machine import micropython import steplogger +import sys import watch import widgets @@ -166,16 +167,21 @@ class Manager(): # an exception starting one of the apps... pass - def register(self, app, quick_ring=False): + def register(self, app, quick_ring=False, watch_face=False): """Register an application with the system. :param object app: The application to regsister """ if isinstance(app, str): - exec('import ' + app[:app.rindex('.')]) + modname = app[:app.rindex('.')] + exec('import ' + modname) app = eval(app + '()') + exec('del ' + modname) + exec('del sys.modules["' + modname + '"]') - if quick_ring == True: + if watch_face: + self.quick_ring[0] = app + elif quick_ring: self.quick_ring.append(app) else: self.launcher_ring.append(app) |
