apps: software: Add support for user-defined applications
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
2a3ffad07d
commit
ba8546dd60
|
@ -0,0 +1,18 @@
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
# Copyright (C) 2021 Daniel Thompson
|
||||||
|
"""Example of any automatically discovered application.
|
||||||
|
|
||||||
|
Any python file (``.py`` or ``.mpy``) discovered in the ``apps/``
|
||||||
|
directory will be automatically added to the Software application.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import wasp
|
||||||
|
|
||||||
|
class ReadMeApp():
|
||||||
|
NAME = "ReadMe"
|
||||||
|
|
||||||
|
def foreground(self):
|
||||||
|
draw = wasp.watch.drawable
|
||||||
|
draw.fill()
|
||||||
|
draw.string('Autoloaded from', 0, 96, width=240)
|
||||||
|
draw.string('apps/ReadMe.py', 0, 96+32, width=240)
|
|
@ -16,6 +16,7 @@ whilst still allowing users to activate so many awesome applications!
|
||||||
|
|
||||||
import wasp
|
import wasp
|
||||||
import icons
|
import icons
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class SoftwareApp():
|
class SoftwareApp():
|
||||||
|
@ -50,6 +51,20 @@ class SoftwareApp():
|
||||||
db.append(('timer', factory('Timer')))
|
db.append(('timer', factory('Timer')))
|
||||||
db.append(('weather', factory('Weather')))
|
db.append(('weather', factory('Weather')))
|
||||||
|
|
||||||
|
# Handle user-loaded applications
|
||||||
|
try:
|
||||||
|
for app in os.listdir('apps'):
|
||||||
|
name = None
|
||||||
|
if app.endswith('.py'):
|
||||||
|
name = app[:-3]
|
||||||
|
if app.endswith('.mpy'):
|
||||||
|
name = app[:-4]
|
||||||
|
if name:
|
||||||
|
db.append((name, factory(name)))
|
||||||
|
except OSError:
|
||||||
|
# apps does not exist...
|
||||||
|
pass
|
||||||
|
|
||||||
# Get the initial state for the checkboxes
|
# Get the initial state for the checkboxes
|
||||||
for _, checkbox in db:
|
for _, checkbox in db:
|
||||||
label = checkbox.label.replace(' ', '')
|
label = checkbox.label.replace(' ', '')
|
||||||
|
|
Loading…
Reference in New Issue