Skip to content

Commit

Permalink
Example app in the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWilkes committed May 8, 2024
1 parent 7e61813 commit e6d9f93
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions sim/apps/example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .app import ExampleApp
19 changes: 19 additions & 0 deletions sim/apps/example/app.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions sim/apps/example/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"callable": "ExampleApp",
"name": "Example app",
"category": "unknown",
"hidden": false
}
5 changes: 4 additions & 1 deletion sim/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit e6d9f93

Please sign in to comment.