diff --git a/python_payload/apps/gr33nhouse/__init__.py b/python_payload/apps/gr33nhouse/__init__.py index 0dfc5157fe77ead098f5ceb6bc61d9c3e3a1440f..92905eb0cdde7fac6bee4f35c9c41e61ae95a869 100644 --- a/python_payload/apps/gr33nhouse/__init__.py +++ b/python_payload/apps/gr33nhouse/__init__.py @@ -62,6 +62,9 @@ class Gr33nhouseApp(Application): ctx.restore() def think(self, ins: InputState, delta_ms: int) -> None: + if self.vm is None: + raise RuntimeError("vm is None") + self.background.think(ins, delta_ms) self.input.think(ins, delta_ms) diff --git a/python_payload/apps/gr33nhouse/applist.py b/python_payload/apps/gr33nhouse/applist.py index c1514ef15215682f1b9422ddebf538ebba3a719d..21137f5ae8f2d71b4a79e818bd7bef0ab84869f8 100644 --- a/python_payload/apps/gr33nhouse/applist.py +++ b/python_payload/apps/gr33nhouse/applist.py @@ -1,4 +1,4 @@ -from st3m.goose import Optional, Enum +from st3m.goose import Optional, Enum, Any from st3m.input import InputController, InputState from st3m.ui import colours from st3m.ui.view import BaseView, ViewManager @@ -20,7 +20,7 @@ class AppList(BaseView): initial_ticks: int = 0 _state: ViewState = ViewState.INITIAL - apps: list[any] = [] + apps: list[Any] = [] selection: int = 0 input: InputController @@ -153,13 +153,13 @@ class AppList(BaseView): self.selection += 1 elif self.input.buttons.app.middle.pressed: - print(f"state {self._state}") - print(f">> {self.apps[self.selection]}") + if self.vm is None: + raise RuntimeError("vm is None") + app = self.apps[self.selection] url = app["tarDownloadUrl"] name = app["name"] author = app["author"] - # self.vm.push(DownloadView(url)) self.vm.push( ConfirmationView( url=url, diff --git a/python_payload/apps/gr33nhouse/background.py b/python_payload/apps/gr33nhouse/background.py index 516f33be7d21c4547e3f92424c5f328a4ff13707..18f4e1378c4c2caf6f529cb63fa131fe2bc023e8 100644 --- a/python_payload/apps/gr33nhouse/background.py +++ b/python_payload/apps/gr33nhouse/background.py @@ -28,7 +28,7 @@ class Flow3rView(BaseView): c.y += (10 * delta_ms / 1000.0) * 200 / c.z if c.y > 300: c.y = -300 - c.rot += delta_ms * c.rot_speed + c.rot += float(delta_ms) * c.rot_speed self.flowers = sorted(self.flowers, key=lambda c: -c.z) def draw(self, ctx: Context) -> None: @@ -47,10 +47,10 @@ class Flower: self.x = x self.y = y self.z = z - self.rot = 0 + self.rot = 0.0 self.rot_speed = (((random.getrandbits(16) - 32767) / 32767.0) - 0.5) / 800 - def draw(self, ctx: Context): + def draw(self, ctx: Context) -> None: ctx.save() ctx.translate(-78 + self.x, -70 + self.y) ctx.translate(50, 40) diff --git a/python_payload/apps/gr33nhouse/confirmation.py b/python_payload/apps/gr33nhouse/confirmation.py index 7974cb35748f78b569dbbf2d8fefdda86a819bee..fb4a4f63c1fa69081d1e2bb125e828673734cceb 100644 --- a/python_payload/apps/gr33nhouse/confirmation.py +++ b/python_payload/apps/gr33nhouse/confirmation.py @@ -3,6 +3,7 @@ from st3m.ui import colours from st3m.ui.view import BaseView, ViewManager from ctx import Context from .background import Flow3rView +from .download import DownloadView class ConfirmationView(BaseView): @@ -44,27 +45,41 @@ class ConfirmationView(BaseView): ctx.rgb(*colours.BLACK) ctx.font = "Camp Font 3" - ctx.font_size = 24 ctx.text_align = ctx.CENTER ctx.text_baseline = ctx.MIDDLE + ctx.font_size = 16 ctx.move_to(0, -60) ctx.text("Install") + ctx.font_size = 24 ctx.move_to(0, -30) ctx.text(self.name) + ctx.font_size = 16 ctx.move_to(0, 0) ctx.text("by") + ctx.font_size = 24 ctx.move_to(0, 30) ctx.text(self.author) + ctx.font_size = 16 ctx.move_to(0, 60) - ctx.text("?") + ctx.text("(Right shoulder to abort)") ctx.restore() def think(self, ins: InputState, delta_ms: int) -> None: self.input.think(ins, delta_ms) self.background.think(ins, delta_ms) + + if self.vm is None: + raise RuntimeError("vm is None") + + if self.input.buttons.app.middle.pressed: + self.vm.push( + DownloadView( + url=self.url, + ) + ) diff --git a/python_payload/apps/gr33nhouse/download.py b/python_payload/apps/gr33nhouse/download.py index 84dd89f368adcfa72293c5a9ed415cd33115ca63..bdbb37bc31b9570449dde9658af1ef6959d1cde5 100644 --- a/python_payload/apps/gr33nhouse/download.py +++ b/python_payload/apps/gr33nhouse/download.py @@ -1,8 +1,8 @@ -import network from st3m.input import InputState +from st3m.goose import Optional import urequests import gzip -import utarfile +from utarfile import TarFile, DIRTYPE import io import os from st3m.ui.view import BaseView @@ -10,6 +10,8 @@ from ctx import Context class DownloadView(BaseView): + response: Optional[urequests.Response] + def __init__(self, url: str) -> None: super().__init__() self._state = 1 @@ -38,7 +40,8 @@ class DownloadView(BaseView): try: print("Getting it") self.response = urequests.get(self._url) - if self.response.content is not None: + + if self.response is not None and self.response.content is not None: print("Got something") self._state = 3 return @@ -49,12 +52,15 @@ class DownloadView(BaseView): self._try += 1 elif self._state == 4: + if self.response is None: + raise RuntimeError("response is None") + tar = gzip.decompress(self.response.content) self.response = None - t = utarfile.TarFile(fileobj=io.BytesIO(tar)) + t = TarFile(fileobj=io.BytesIO(tar)) for i in t: print(i.name) - if i.type == utarfile.DIRTYPE: + if i.type == DIRTYPE: print("dirtype") dirname = "/flash/sys/apps/" + i.name if not os.path.exists(dirname): @@ -69,4 +75,7 @@ class DownloadView(BaseView): with open(filename, "wb") as of: of.write(f.read()) self._state = 5 + + if self.vm is None: + raise RuntimeError("vm is None") self.vm.pop()