From e5d7de8fab7cf1082c81a1f99d2de6cd3ce46098 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak <dos@dosowisko.net> Date: Fri, 15 Sep 2023 00:30:35 +0200 Subject: [PATCH] gr33nhouse: Clean up; don't duplicate BaseView's functionality --- python_payload/apps/gr33nhouse/__init__.py | 6 ++---- python_payload/apps/gr33nhouse/applist.py | 9 +++------ python_payload/apps/gr33nhouse/background.py | 7 ++----- python_payload/apps/gr33nhouse/confirmation.py | 8 +++----- python_payload/apps/gr33nhouse/download.py | 9 ++------- python_payload/apps/gr33nhouse/manual.py | 7 +++---- python_payload/apps/gr33nhouse/record.py | 10 ++-------- 7 files changed, 17 insertions(+), 39 deletions(-) diff --git a/python_payload/apps/gr33nhouse/__init__.py b/python_payload/apps/gr33nhouse/__init__.py index 46a98a3f4a..327fc68fa0 100644 --- a/python_payload/apps/gr33nhouse/__init__.py +++ b/python_payload/apps/gr33nhouse/__init__.py @@ -1,6 +1,6 @@ from st3m.goose import Enum from st3m.application import Application, ApplicationContext -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.ui.interactions import ScrollController from st3m.ui import colours from st3m.ui.view import ViewManager @@ -20,14 +20,12 @@ class ViewState(Enum): class Gr33nhouseApp(Application): items = ["Browse apps", "Record flow3r seed", "Enter flow3r seed"] - input: InputController background: Flow3rView state: ViewState def __init__(self, app_ctx: ApplicationContext) -> None: super().__init__(app_ctx=app_ctx) - self.input = InputController() self.background = Flow3rView() self._sc = ScrollController() self._sc.set_item_count(3) @@ -105,7 +103,7 @@ class Gr33nhouseApp(Application): ctx.restore() def think(self, ins: InputState, delta_ms: int) -> None: - self.input.think(ins, delta_ms) + super().think(ins, delta_ms) self._sc.think(ins, delta_ms) if self.vm is None: diff --git a/python_payload/apps/gr33nhouse/applist.py b/python_payload/apps/gr33nhouse/applist.py index e755a6a340..475c3025ae 100644 --- a/python_payload/apps/gr33nhouse/applist.py +++ b/python_payload/apps/gr33nhouse/applist.py @@ -1,5 +1,5 @@ from st3m.goose import Optional, Enum, Any -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.ui import colours from st3m.ui.view import BaseView, ViewManager from st3m.ui.interactions import ScrollController @@ -25,12 +25,10 @@ class AppList(BaseView): apps: list[Any] = [] - input: InputController background: Flow3rView def __init__(self) -> None: - self.input = InputController() - self.vm = None + super().__init__() self.background = Flow3rView() self._sc = ScrollController() @@ -122,12 +120,11 @@ class AppList(BaseView): raise RuntimeError(f"Invalid view state {self._state}") def think(self, ins: InputState, delta_ms: int) -> None: + super().think(ins, delta_ms) self._sc.think(ins, delta_ms) if self.initial_ticks == 0 or time.ticks_ms() < self.initial_ticks + 300: return - self.input.think(ins, delta_ms) - if self._state == ViewState.INITIAL: try: self._state = ViewState.LOADING diff --git a/python_payload/apps/gr33nhouse/background.py b/python_payload/apps/gr33nhouse/background.py index 18f4e1378c..f3a58605ca 100644 --- a/python_payload/apps/gr33nhouse/background.py +++ b/python_payload/apps/gr33nhouse/background.py @@ -1,16 +1,13 @@ import random -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.ui.view import BaseView from ctx import Context class Flow3rView(BaseView): - input: InputController - def __init__(self) -> None: - self.vm = None - self.input = InputController() + super().__init__() self.flowers = [] for i in range(8): diff --git a/python_payload/apps/gr33nhouse/confirmation.py b/python_payload/apps/gr33nhouse/confirmation.py index f7702815fd..fbf1845728 100644 --- a/python_payload/apps/gr33nhouse/confirmation.py +++ b/python_payload/apps/gr33nhouse/confirmation.py @@ -1,4 +1,4 @@ -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.ui import colours from st3m.ui.view import BaseView, ViewManager from ctx import Context @@ -8,15 +8,13 @@ from .download import DownloadView class ConfirmationView(BaseView): background: Flow3rView - input: InputController url: str name: str author: str def __init__(self, url: str, name: str, author: str) -> None: - self.input = InputController() - self.vm = None + super().__init__() self.background = Flow3rView() self.url = url @@ -71,7 +69,7 @@ class ConfirmationView(BaseView): ctx.restore() def think(self, ins: InputState, delta_ms: int) -> None: - self.input.think(ins, delta_ms) + super().think(ins, delta_ms) self.background.think(ins, delta_ms) if self.vm is None: diff --git a/python_payload/apps/gr33nhouse/download.py b/python_payload/apps/gr33nhouse/download.py index 64cc91b26b..ca85f9a049 100644 --- a/python_payload/apps/gr33nhouse/download.py +++ b/python_payload/apps/gr33nhouse/download.py @@ -1,4 +1,4 @@ -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.goose import Optional, List from st3m.ui import colours import urequests @@ -28,8 +28,6 @@ class DownloadView(BaseView): """ _state: int - input: InputController - def __init__(self, url: str) -> None: super().__init__() self._state = 1 @@ -38,8 +36,6 @@ class DownloadView(BaseView): self.response = b"" self._download_instance = None - self.input = InputController() - def draw(self, ctx: Context) -> None: ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill() @@ -97,8 +93,7 @@ class DownloadView(BaseView): req.close() def think(self, ins: InputState, delta_ms: int) -> None: - # super().think(ins, delta_ms) # Let BaseView do its thing - self.input.think(ins, delta_ms) + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.buttons.app.middle.pressed: if self.vm is None: diff --git a/python_payload/apps/gr33nhouse/manual.py b/python_payload/apps/gr33nhouse/manual.py index 34c4232ce9..0d112ae773 100644 --- a/python_payload/apps/gr33nhouse/manual.py +++ b/python_payload/apps/gr33nhouse/manual.py @@ -1,5 +1,5 @@ from st3m.goose import Optional, Enum -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.ui import colours from st3m.ui.view import BaseView, ViewManager from ctx import Context @@ -34,8 +34,7 @@ class ManualInputView(BaseView): wait_timer: Optional[int] def __init__(self) -> None: - self.input = InputController() - self.vm = None + super().__init__() self.background = Flow3rView() self.flow3r_seed = "" @@ -109,7 +108,7 @@ class ManualInputView(BaseView): ctx.text(f"not found!") def think(self, ins: InputState, delta_ms: int) -> None: - self.input.think(ins, delta_ms) + super().think(ins, delta_ms) self.background.think(ins, delta_ms) if self.state == ViewState.ENTER_SEED: diff --git a/python_payload/apps/gr33nhouse/record.py b/python_payload/apps/gr33nhouse/record.py index be2e969e33..6fb6d6abcf 100644 --- a/python_payload/apps/gr33nhouse/record.py +++ b/python_payload/apps/gr33nhouse/record.py @@ -1,4 +1,4 @@ -from st3m.input import InputController, InputState +from st3m.input import InputState from st3m.ui import colours from st3m.ui.view import BaseView, ViewManager from ctx import Context @@ -6,11 +6,8 @@ from .background import Flow3rView class RecordView(BaseView): - input: InputController - def __init__(self) -> None: - self.input = InputController() - self.vm = None + super().__init__() self.background = Flow3rView() def on_enter(self, vm: ViewManager | None) -> None: @@ -37,6 +34,3 @@ class RecordView(BaseView): ctx.text_baseline = ctx.MIDDLE ctx.text("Coming soon") ctx.restore() - - def think(self, ins: InputState, delta_ms: int) -> None: - self.input.think(ins, delta_ms) -- GitLab