diff --git a/docs/badge/application-programming.rst b/docs/badge/application-programming.rst index 143d22e1eb5e9a352379b426a5e353f309e17f57..028ad53a5ed9b1cbfff7ab1f33c7980ca7739f96 100644 --- a/docs/badge/application-programming.rst +++ b/docs/badge/application-programming.rst @@ -305,11 +305,9 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState class SecondScreen(ViewWithInputState): def __init__(self) -> None: super().__init__() - self._vm = None def on_enter(self, vm: Optional[ViewManager]) -> None: super().on_enter(vm) # Let ViewWithInputState do its thing - self._vm = vm def draw(self, ctx: Context) -> None: # Paint the background black @@ -321,13 +319,12 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState super().think(ins, delta_ms) # Let ViewWithInputState do its thing if self.input.right_shoulder.middle.pressed: - self._vm.pop() + self.vm.pop() class Example(ViewWithInputState): def __init__(self) -> None: super().__init__() - self._vm = None def draw(self, ctx: Context) -> None: # Paint the background black @@ -337,13 +334,13 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState def on_enter(self, vm: Optional[ViewManager]) -> None: - self._vm = vm + super().on_enter(vm) # Let ViewWithInputState do its thing def think(self, ins: InputState, delta_ms: int) -> None: super().think(ins, delta_ms) # Let ViewWithInputState do its thing if self.input.right_shoulder.middle.pressed: - self._vm.push(SecondScreen()) + self.vm.push(SecondScreen()) st3m.run.run_view(Example()) @@ -366,11 +363,9 @@ Let's introduce the final class you should actually be using for application dev class SecondScreen(ViewWithInputState): def __init__(self) -> None: super().__init__() - self._vm = None def on_enter(self, vm: Optional[ViewManager]) -> None: super().on_enter(vm) # Let ViewWithInputState do its thing - self._vm = vm def draw(self, ctx: Context) -> None: # Paint the background black @@ -382,7 +377,7 @@ Let's introduce the final class you should actually be using for application dev super().think(ins, delta_ms) # Let ViewWithInputState do its thing if self.input.right_shoulder.middle.pressed: - self._vm.pop() + self.vm.pop() class MyDemo(Application): diff --git a/python_payload/st3m/application.py b/python_payload/st3m/application.py index a938af858555b4361cd642c7e1dd011364db86ca..79842d1da1daabc6ef7e6dcc69732d5d9281b95b 100644 --- a/python_payload/st3m/application.py +++ b/python_payload/st3m/application.py @@ -21,23 +21,21 @@ log = Log(__name__) class Application(ViewWithInputState): def __init__(self, name: str = __name__) -> None: self._name = name - self._view_manager: Optional[ViewManager] = None super().__init__() def on_exit(self) -> None: pass def on_enter(self, vm: Optional[ViewManager]) -> None: - self._view_manager = vm super().on_enter(vm) def think(self, ins: InputState, delta_ms: int) -> None: super().think(ins, delta_ms) if self.input.left_shoulder.middle.pressed: - if self._view_manager is not None: + if self.vm is not None: self.on_exit() - self._view_manager.pop(ViewTransitionSwipeRight()) + self.vm.pop(ViewTransitionSwipeRight()) class BundleLoadException(BaseException): diff --git a/python_payload/st3m/ui/menu.py b/python_payload/st3m/ui/menu.py index 781eacdc36910e26b1c328880d0b80f2708d888f..174d7a11069a12bbe0e7179524d48fed454b7484 100644 --- a/python_payload/st3m/ui/menu.py +++ b/python_payload/st3m/ui/menu.py @@ -120,19 +120,16 @@ class MenuController(ViewWithInputState): __slots__ = ( "_items", "_scroll_controller", - "_view_manager", ) def __init__(self, items: List[MenuItem]) -> None: self._items = items self._scroll_controller = ScrollController() self._scroll_controller.set_item_count(len(items)) - self._view_manager: Optional[ViewManager] = None super().__init__() def on_enter(self, vm: Optional["ViewManager"]) -> None: - self._view_manager = vm super().on_enter(vm) def _parse_state(self) -> None: @@ -174,4 +171,4 @@ class MenuController(ViewWithInputState): Automatically called on canonical user input. """ - self._items[self._scroll_controller.target_position()].press(self._view_manager) + self._items[self._scroll_controller.target_position()].press(self.vm) diff --git a/python_payload/st3m/ui/view.py b/python_payload/st3m/ui/view.py index 8a8d050a257797c24eb8aed16f02174f97674b10..42c91a4b4338a8ab4175f363cd66b153e78b2873 100644 --- a/python_payload/st3m/ui/view.py +++ b/python_payload/st3m/ui/view.py @@ -35,9 +35,11 @@ class ViewWithInputState(View): def __init__(self) -> None: self.input = InputController() + self.vm: Optional["ViewManager"] = None def on_enter(self, vm: Optional["ViewManager"]) -> None: self.input._ignore_pressed() + self.vm = vm def think(self, ins: InputState, delta_ms: int) -> None: self.input.think(ins, delta_ms)