From d2b100d3a05cf5193cbeb53f083d1df45f616dfa Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Wed, 9 Aug 2023 01:11:17 +0200 Subject: [PATCH] ui: rename ViewWithInputState to BaseView --- docs/badge/application-programming.rst | 22 +++++++++++----------- python_payload/st3m/application.py | 4 ++-- python_payload/st3m/ui/menu.py | 4 ++-- python_payload/st3m/ui/view.py | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/badge/application-programming.rst b/docs/badge/application-programming.rst index 028ad53a5e..d8bc843116 100644 --- a/docs/badge/application-programming.rst +++ b/docs/badge/application-programming.rst @@ -294,20 +294,20 @@ Example 2b: Easier view management ---------------------------------- The idea that a button (physical or captouch) is used to enter / exit a view is so universal that -there is a special view which helps you with that: :py:class:`ViewWithInputState`. It integrates an +there is a special view which helps you with that: :py:class:`BaseView`. It integrates an `InputController` and handles the ignoring of extra presses: .. code-block:: python - from st3m.ui.view import ViewWithInputState + from st3m.ui.view import BaseView import st3m.run - class SecondScreen(ViewWithInputState): + class SecondScreen(BaseView): def __init__(self) -> None: super().__init__() def on_enter(self, vm: Optional[ViewManager]) -> None: - super().on_enter(vm) # Let ViewWithInputState do its thing + super().on_enter(vm) # Let BaseView do its thing def draw(self, ctx: Context) -> None: # Paint the background black @@ -316,13 +316,13 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill() def think(self, ins: InputState, delta_ms: int) -> None: - super().think(ins, delta_ms) # Let ViewWithInputState do its thing + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.right_shoulder.middle.pressed: self.vm.pop() - class Example(ViewWithInputState): + class Example(BaseView): def __init__(self) -> None: super().__init__() @@ -334,10 +334,10 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState def on_enter(self, vm: Optional[ViewManager]) -> None: - super().on_enter(vm) # Let ViewWithInputState do its thing + super().on_enter(vm) # Let BaseView do its thing def think(self, ins: InputState, delta_ms: int) -> None: - super().think(ins, delta_ms) # Let ViewWithInputState do its thing + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.right_shoulder.middle.pressed: self.vm.push(SecondScreen()) @@ -360,12 +360,12 @@ Let's introduce the final class you should actually be using for application dev from st3m.application import Application import st3m.run - class SecondScreen(ViewWithInputState): + class SecondScreen(BaseView): def __init__(self) -> None: super().__init__() def on_enter(self, vm: Optional[ViewManager]) -> None: - super().on_enter(vm) # Let ViewWithInputState do its thing + super().on_enter(vm) # Let BaseView do its thing def draw(self, ctx: Context) -> None: # Paint the background black @@ -374,7 +374,7 @@ Let's introduce the final class you should actually be using for application dev ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill() def think(self, ins: InputState, delta_ms: int) -> None: - super().think(ins, delta_ms) # Let ViewWithInputState do its thing + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.right_shoulder.middle.pressed: self.vm.pop() diff --git a/python_payload/st3m/application.py b/python_payload/st3m/application.py index 79842d1da1..576e7cfe54 100644 --- a/python_payload/st3m/application.py +++ b/python_payload/st3m/application.py @@ -1,5 +1,5 @@ from st3m.ui.view import ( - ViewWithInputState, + BaseView, ViewTransitionSwipeRight, ViewTransitionSwipeLeft, ViewManager, @@ -18,7 +18,7 @@ import sys log = Log(__name__) -class Application(ViewWithInputState): +class Application(BaseView): def __init__(self, name: str = __name__) -> None: self._name = name super().__init__() diff --git a/python_payload/st3m/ui/menu.py b/python_payload/st3m/ui/menu.py index 174d7a1106..da90f65833 100644 --- a/python_payload/st3m/ui/menu.py +++ b/python_payload/st3m/ui/menu.py @@ -5,7 +5,7 @@ from st3m import logging from st3m.goose import ABCBase, abstractmethod, List, Optional from st3m.input import InputState, InputController from st3m.ui.view import ( - ViewWithInputState, + BaseView, View, ViewManager, ViewTransitionSwipeLeft, @@ -108,7 +108,7 @@ class MenuItemBack(MenuItem): ctx.text("\ue5c4") -class MenuController(ViewWithInputState): +class MenuController(BaseView): """ Base class for menus. Reacts to canonical inputs (left shoulder button) to move across and select actions from the menu. diff --git a/python_payload/st3m/ui/view.py b/python_payload/st3m/ui/view.py index 42c91a4b43..c0b2ee5f11 100644 --- a/python_payload/st3m/ui/view.py +++ b/python_payload/st3m/ui/view.py @@ -10,7 +10,7 @@ class View(Responder): lifecycle in terms of being foregrounded or backgrounded. These signals can be used to alter input processing, se the - ViewWithInputState class. + BaseView class. """ def on_enter(self, vm: Optional["ViewManager"]) -> None: @@ -21,7 +21,7 @@ class View(Responder): pass -class ViewWithInputState(View): +class BaseView(View): """ A base class helper for implementing views which respond to inputs and who want to do their own, separate input processing. -- GitLab