From e6d9f93ef771b0cf57757927c8924384e04981a7 Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Wed, 8 May 2024 20:08:40 +0100 Subject: [PATCH] Example app in the simulator --- sim/apps/example/__init__.py | 1 + sim/apps/example/app.py | 19 +++++++++++++++++++ sim/apps/example/metadata.json | 6 ++++++ sim/run.py | 5 ++++- 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 sim/apps/example/__init__.py create mode 100644 sim/apps/example/app.py create mode 100644 sim/apps/example/metadata.json diff --git a/sim/apps/example/__init__.py b/sim/apps/example/__init__.py new file mode 100644 index 0000000..748b7f4 --- /dev/null +++ b/sim/apps/example/__init__.py @@ -0,0 +1 @@ +from .app import ExampleApp \ No newline at end of file diff --git a/sim/apps/example/app.py b/sim/apps/example/app.py new file mode 100644 index 0000000..83faf71 --- /dev/null +++ b/sim/apps/example/app.py @@ -0,0 +1,19 @@ +import asyncio +import app + +from events.input import Buttons, BUTTON_TYPES + + +class ExampleApp(app.App): + def __init__(self): + self.button_states = Buttons(self) + + def update(self, delta): + if self.button_states.get(BUTTON_TYPES["CANCEL"]): + self.minimise() + + def draw(self, ctx): + ctx.save() + ctx.rgb(0.2,0,0).rectangle(-120,-120,240,240).fill() + ctx.rgb(1,0,0).move_to(-80,0).text("Hello world") + ctx.restore() diff --git a/sim/apps/example/metadata.json b/sim/apps/example/metadata.json new file mode 100644 index 0000000..5ad5659 --- /dev/null +++ b/sim/apps/example/metadata.json @@ -0,0 +1,6 @@ +{ + "callable": "ExampleApp", + "name": "Example app", + "category": "unknown", + "hidden": false +} \ No newline at end of file diff --git a/sim/run.py b/sim/run.py index 9667687..3d6aad4 100755 --- a/sim/run.py +++ b/sim/run.py @@ -62,6 +62,7 @@ def find_spec(self, fullname, path, target=None): sys.path = [ os.path.join(projectpath, "sim", "fakes"), + os.path.join(projectpath, "sim", "apps"), os.path.join(projectpath, "modules"), os.path.join(projectpath, "modules/lib"), os.path.join(projectpath, "micropython/ports/esp32/build-tildagon/frozen_mpy"), @@ -99,7 +100,9 @@ def _path_replace(p): p = p[len("/flash") :] p = simpath + p return p - + if p.startswith("/apps"): + dir = os.path.dirname(__file__) + p = f"{dir}{p}" return p