diff --git a/python_payload/apps/audio_config/__init__.py b/python_payload/apps/audio_config/__init__.py index 6a021be5ecffbfcc9e26a44a32fad310adb80df9..827a606eb6f467e2fab020578bf8bd0d839bf024 100644 --- a/python_payload/apps/audio_config/__init__.py +++ b/python_payload/apps/audio_config/__init__.py @@ -569,12 +569,8 @@ class SubView(View): self.menu = menu self.app = app - def on_enter(self, vm): - self.vm = vm - def think(self, ins, delta_ms): - if self.vm.is_active(self): - self.app.think(ins, delta_ms) + self.app.think(ins, delta_ms) def draw(self, ctx): self.menu.draw(ctx) 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..145373cca56e918c1696d33391166e979b3e666b 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,8 +104,10 @@ class Gr33nhouseApp(Application): super().think(ins, delta_ms) self._sc.think(ins, delta_ms) - if self.vm is None: - raise RuntimeError("vm is None") + self.background.think(ins, delta_ms) + + if not self.is_active(): + return if not network.WLAN(network.STA_IF).isconnected(): self.state = ViewState.NO_INTERNET @@ -116,8 +116,6 @@ class Gr33nhouseApp(Application): else: self.state = ViewState.CONTENT - self.background.think(ins, delta_ms) - 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..c89b3eb86b9897f251fcbf4d7ad7b00fabea45fe 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,10 @@ 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: - return if self._state == ViewState.INITIAL: + if self.vm.transitioning: + return try: self._state = ViewState.LOADING print("Loading app list...") @@ -147,6 +151,9 @@ class AppList(BaseView): self.background.think(ins, delta_ms) self._scroll_pos += delta_ms / 1000 + if not self.is_active(): + return + if self.input.buttons.app.left.pressed or self.input.buttons.app.left.repeated: self._sc.scroll_left() self._scroll_pos = 0.0 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))