diff --git a/python_payload/apps/demo_worms/__init__.py b/python_payload/apps/demo_worms/__init__.py index d256ff708cb1ab18a5f1d200b4c57b8758dba53a..e4029bfee02db672a0cb0cbe6206ac2261727b76 100644 --- a/python_payload/apps/demo_worms/__init__.py +++ b/python_payload/apps/demo_worms/__init__.py @@ -30,7 +30,6 @@ class AppWorms(Application): def on_enter(self, vm: Optional[ViewManager]) -> None: super().on_enter(vm) self.just_shown = False - self._bg = True self.worms = [] # reset worms def draw_background(self, ctx): @@ -41,9 +40,8 @@ class AppWorms(Application): ctx.move_to(0, 0).rgb(*WHITE).text("touch me :)") def draw(self, ctx: Context) -> None: - if self._bg or (self.vm.transitioning and self.is_active()): + if self.vm.transitioning and self.is_active(): self.draw_background(ctx) - self._bg = False else: for w in self.worms: w.draw(ctx) diff --git a/python_payload/apps/gr33nhouse/__init__.py b/python_payload/apps/gr33nhouse/__init__.py index eec16b918f83a27ad0ce4d6eada6392d645117e9..ad5ac1276152b5c371eaddade3a9bf2c85c097ae 100644 --- a/python_payload/apps/gr33nhouse/__init__.py +++ b/python_payload/apps/gr33nhouse/__init__.py @@ -33,11 +33,9 @@ class Gr33nhouseApp(Application): self.state = ViewState.CONTENT self.wifi_status = None - def on_enter(self, vm: ViewManager | None) -> None: - super().on_enter(vm) - - if self.vm is None: - raise RuntimeError("vm is None") + def on_exit(self) -> bool: + # request thinks after on_exit + return True def draw(self, ctx: Context) -> None: if self.state == ViewState.NO_INTERNET: @@ -106,9 +104,6 @@ class Gr33nhouseApp(Application): super().think(ins, delta_ms) self._sc.think(ins, delta_ms) - if self.vm is None: - raise RuntimeError("vm is None") - if not network.WLAN(network.STA_IF).isconnected(): self.state = ViewState.NO_INTERNET self.wifi_status = network.WLAN(network.STA_IF).status() @@ -118,6 +113,9 @@ class Gr33nhouseApp(Application): self.background.think(ins, delta_ms) + if not self.is_active(): + return + if self.input.buttons.app.left.pressed or self.input.buttons.app.left.repeated: self._sc.scroll_left() elif ( diff --git a/python_payload/apps/gr33nhouse/applist.py b/python_payload/apps/gr33nhouse/applist.py index 520f67e5cba927a40c07e5f4868a6d8672988c7d..decbea03da0b04aeea26ede068d75aeadf347c53 100644 --- a/python_payload/apps/gr33nhouse/applist.py +++ b/python_payload/apps/gr33nhouse/applist.py @@ -31,6 +31,10 @@ class AppList(BaseView): self.background = Flow3rView() self._sc = ScrollController() + def on_exit(self) -> bool: + # request thinks after on_exit + return True + def draw(self, ctx: Context) -> None: ctx.move_to(0, 0) @@ -117,10 +121,13 @@ class AppList(BaseView): def think(self, ins: InputState, delta_ms: int) -> None: super().think(ins, delta_ms) self._sc.think(ins, delta_ms) - if self.is_active() and self.vm.transitioning: + + if self.is_active(): return if self._state == ViewState.INITIAL: + if self.vm.transitioning: + return try: self._state = ViewState.LOADING print("Loading app list...") diff --git a/python_payload/apps/gr33nhouse/confirmation.py b/python_payload/apps/gr33nhouse/confirmation.py index fbf18457287ac325aeca6b43688a752ea049e2e3..68328576533c97f3418149d98b46d6833ba6eea9 100644 --- a/python_payload/apps/gr33nhouse/confirmation.py +++ b/python_payload/apps/gr33nhouse/confirmation.py @@ -21,11 +21,9 @@ class ConfirmationView(BaseView): self.name = name self.author = author - def on_enter(self, vm: ViewManager | None) -> None: - super().on_enter(vm) - - if self.vm is None: - raise RuntimeError("vm is None") + def on_exit(self) -> bool: + # request thinks after on_exit + return True def draw(self, ctx: Context) -> None: ctx.move_to(0, 0) @@ -72,10 +70,7 @@ class ConfirmationView(BaseView): super().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: + if self.is_active() and self.input.buttons.app.middle.pressed: self.vm.replace( DownloadView( url=self.url, diff --git a/python_payload/apps/gr33nhouse/manual.py b/python_payload/apps/gr33nhouse/manual.py index 16960b7ab1a91d20647f6853bb660ead337a7eac..44e9c84f95a2418290a69cb6e0bfa9ffd828fd3d 100644 --- a/python_payload/apps/gr33nhouse/manual.py +++ b/python_payload/apps/gr33nhouse/manual.py @@ -46,8 +46,10 @@ class ManualInputView(BaseView): super().on_enter(vm) self.flow3r_seed = "" self.state = ViewState.ENTER_SEED - if self.vm is None: - raise RuntimeError("vm is None") + + def on_exit(self) -> bool: + # request thinks after on_exit + return True def draw(self, ctx: Context) -> None: self.background.draw(ctx) diff --git a/python_payload/apps/gr33nhouse/record.py b/python_payload/apps/gr33nhouse/record.py index 6fb6d6abcfb242739eed68f8c7e01c1186641438..0fa59d39c1ea5adb6d710a1e4b53c63b291273a4 100644 --- a/python_payload/apps/gr33nhouse/record.py +++ b/python_payload/apps/gr33nhouse/record.py @@ -10,12 +10,6 @@ class RecordView(BaseView): super().__init__() self.background = Flow3rView() - def on_enter(self, vm: ViewManager | None) -> None: - super().on_enter(vm) - - if self.vm is None: - raise RuntimeError("vm is None") - def draw(self, ctx: Context) -> None: ctx.move_to(0, 0) ctx.save() diff --git a/python_payload/apps/otamatone/__init__.py b/python_payload/apps/otamatone/__init__.py index 8f5dbe3b5f00038b7b60fec1fcda25c62c9bf0a7..610e8bfce865189851d0e9d894fcfcd40c7c9bad 100644 --- a/python_payload/apps/otamatone/__init__.py +++ b/python_payload/apps/otamatone/__init__.py @@ -170,9 +170,6 @@ class Otamatone(Application): self._ts += delta_ms self._blob.think(ins, delta_ms) - if not self.is_active(): - return - petal = self.input.captouch.petals[self.PETAL_NO] pos = ins.captouch.petals[self.PETAL_NO].position ctrl = pos[0] / 40000 diff --git a/python_payload/apps/w1f1/__init__.py b/python_payload/apps/w1f1/__init__.py index b292b2e09e964d098d001c9f47fc1d50672655a0..252f3a1d3c50932be5edbd60b0363536d70d65f2 100644 --- a/python_payload/apps/w1f1/__init__.py +++ b/python_payload/apps/w1f1/__init__.py @@ -253,9 +253,6 @@ class WifiApp(Application): super().think(ins, delta_ms) self._scroll_pos += delta_ms / 1000 - if not self.is_active(): - return - leds.set_all_rgb(0, 0, 0) if self.input.buttons.app.left.pressed and self._wlan_offset > 0: diff --git a/python_payload/apps/w1f1/k3yboard.py b/python_payload/apps/w1f1/k3yboard.py index 2fb478e757c85079e9f5d94235ae7017ad5ea60c..c5333d1b783af816c258f27f67b0cba91a0bddae 100644 --- a/python_payload/apps/w1f1/k3yboard.py +++ b/python_payload/apps/w1f1/k3yboard.py @@ -540,7 +540,7 @@ class KeyboardDemoApp(Application): def think(self, ins: InputState, delta_ms: int) -> None: super().think(ins, delta_ms) # Let Application do its thing - if self.is_active() and self.input.buttons.app.middle.pressed: + if self.input.buttons.app.middle.pressed: self.vm.push(KeyboardView(self._model))