Skip to content
Snippets Groups Projects
Verified Commit 44b0c6f1 authored by dos's avatar dos
Browse files

python_payload: Clean up application's input handling during transitions

Apps don't have to check whether they're active anymore, unless they
explicitly ask to receive think calls after on_exit.

Make gr33nhouse ask for it, as it animates its background. Remove
is_active guards from other apps (and clean up some related codepaths
while at that too).
parent 154a6a29
No related branches found
No related tags found
No related merge requests found
Pipeline #8811 passed
...@@ -30,7 +30,6 @@ class AppWorms(Application): ...@@ -30,7 +30,6 @@ class AppWorms(Application):
def on_enter(self, vm: Optional[ViewManager]) -> None: def on_enter(self, vm: Optional[ViewManager]) -> None:
super().on_enter(vm) super().on_enter(vm)
self.just_shown = False self.just_shown = False
self._bg = True
self.worms = [] # reset worms self.worms = [] # reset worms
def draw_background(self, ctx): def draw_background(self, ctx):
...@@ -41,9 +40,8 @@ class AppWorms(Application): ...@@ -41,9 +40,8 @@ class AppWorms(Application):
ctx.move_to(0, 0).rgb(*WHITE).text("touch me :)") ctx.move_to(0, 0).rgb(*WHITE).text("touch me :)")
def draw(self, ctx: Context) -> None: 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.draw_background(ctx)
self._bg = False
else: else:
for w in self.worms: for w in self.worms:
w.draw(ctx) w.draw(ctx)
......
...@@ -33,11 +33,9 @@ class Gr33nhouseApp(Application): ...@@ -33,11 +33,9 @@ class Gr33nhouseApp(Application):
self.state = ViewState.CONTENT self.state = ViewState.CONTENT
self.wifi_status = None self.wifi_status = None
def on_enter(self, vm: ViewManager | None) -> None: def on_exit(self) -> bool:
super().on_enter(vm) # request thinks after on_exit
return True
if self.vm is None:
raise RuntimeError("vm is None")
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
if self.state == ViewState.NO_INTERNET: if self.state == ViewState.NO_INTERNET:
...@@ -106,9 +104,6 @@ class Gr33nhouseApp(Application): ...@@ -106,9 +104,6 @@ class Gr33nhouseApp(Application):
super().think(ins, delta_ms) super().think(ins, delta_ms)
self._sc.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(): if not network.WLAN(network.STA_IF).isconnected():
self.state = ViewState.NO_INTERNET self.state = ViewState.NO_INTERNET
self.wifi_status = network.WLAN(network.STA_IF).status() self.wifi_status = network.WLAN(network.STA_IF).status()
...@@ -118,6 +113,9 @@ class Gr33nhouseApp(Application): ...@@ -118,6 +113,9 @@ class Gr33nhouseApp(Application):
self.background.think(ins, delta_ms) 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: if self.input.buttons.app.left.pressed or self.input.buttons.app.left.repeated:
self._sc.scroll_left() self._sc.scroll_left()
elif ( elif (
......
...@@ -31,6 +31,10 @@ class AppList(BaseView): ...@@ -31,6 +31,10 @@ class AppList(BaseView):
self.background = Flow3rView() self.background = Flow3rView()
self._sc = ScrollController() self._sc = ScrollController()
def on_exit(self) -> bool:
# request thinks after on_exit
return True
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
ctx.move_to(0, 0) ctx.move_to(0, 0)
...@@ -117,10 +121,13 @@ class AppList(BaseView): ...@@ -117,10 +121,13 @@ class AppList(BaseView):
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) super().think(ins, delta_ms)
self._sc.think(ins, delta_ms) self._sc.think(ins, delta_ms)
if self.is_active() and self.vm.transitioning:
if self.is_active():
return return
if self._state == ViewState.INITIAL: if self._state == ViewState.INITIAL:
if self.vm.transitioning:
return
try: try:
self._state = ViewState.LOADING self._state = ViewState.LOADING
print("Loading app list...") print("Loading app list...")
......
...@@ -21,11 +21,9 @@ class ConfirmationView(BaseView): ...@@ -21,11 +21,9 @@ class ConfirmationView(BaseView):
self.name = name self.name = name
self.author = author self.author = author
def on_enter(self, vm: ViewManager | None) -> None: def on_exit(self) -> bool:
super().on_enter(vm) # request thinks after on_exit
return True
if self.vm is None:
raise RuntimeError("vm is None")
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
ctx.move_to(0, 0) ctx.move_to(0, 0)
...@@ -72,10 +70,7 @@ class ConfirmationView(BaseView): ...@@ -72,10 +70,7 @@ class ConfirmationView(BaseView):
super().think(ins, delta_ms) super().think(ins, delta_ms)
self.background.think(ins, delta_ms) self.background.think(ins, delta_ms)
if self.vm is None: if self.is_active() and self.input.buttons.app.middle.pressed:
raise RuntimeError("vm is None")
if self.input.buttons.app.middle.pressed:
self.vm.replace( self.vm.replace(
DownloadView( DownloadView(
url=self.url, url=self.url,
......
...@@ -46,8 +46,10 @@ class ManualInputView(BaseView): ...@@ -46,8 +46,10 @@ class ManualInputView(BaseView):
super().on_enter(vm) super().on_enter(vm)
self.flow3r_seed = "" self.flow3r_seed = ""
self.state = ViewState.ENTER_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: def draw(self, ctx: Context) -> None:
self.background.draw(ctx) self.background.draw(ctx)
......
...@@ -10,12 +10,6 @@ class RecordView(BaseView): ...@@ -10,12 +10,6 @@ class RecordView(BaseView):
super().__init__() super().__init__()
self.background = Flow3rView() 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: def draw(self, ctx: Context) -> None:
ctx.move_to(0, 0) ctx.move_to(0, 0)
ctx.save() ctx.save()
......
...@@ -170,9 +170,6 @@ class Otamatone(Application): ...@@ -170,9 +170,6 @@ class Otamatone(Application):
self._ts += delta_ms self._ts += delta_ms
self._blob.think(ins, delta_ms) self._blob.think(ins, delta_ms)
if not self.is_active():
return
petal = self.input.captouch.petals[self.PETAL_NO] petal = self.input.captouch.petals[self.PETAL_NO]
pos = ins.captouch.petals[self.PETAL_NO].position pos = ins.captouch.petals[self.PETAL_NO].position
ctrl = pos[0] / 40000 ctrl = pos[0] / 40000
......
...@@ -253,9 +253,6 @@ class WifiApp(Application): ...@@ -253,9 +253,6 @@ class WifiApp(Application):
super().think(ins, delta_ms) super().think(ins, delta_ms)
self._scroll_pos += delta_ms / 1000 self._scroll_pos += delta_ms / 1000
if not self.is_active():
return
leds.set_all_rgb(0, 0, 0) leds.set_all_rgb(0, 0, 0)
if self.input.buttons.app.left.pressed and self._wlan_offset > 0: if self.input.buttons.app.left.pressed and self._wlan_offset > 0:
......
...@@ -540,7 +540,7 @@ class KeyboardDemoApp(Application): ...@@ -540,7 +540,7 @@ class KeyboardDemoApp(Application):
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) # Let Application do its thing 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)) self.vm.push(KeyboardView(self._model))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment