Skip to content
Snippets Groups Projects
Commit 94b3707a authored by pippin's avatar pippin Committed by pippin
Browse files

ui: add MenuItemAction, make reboot functional, add yeet local changes

parent f8b4081f
No related branches found
No related tags found
1 merge request!74ui: add MenuItemAction, make reboot functional, add yeet local changes
Pipeline #6323 passed
from typing import Any from typing import Any
def reset() -> None:
pass
class Pin: class Pin:
""" """
See the official micropython docs for more details: See the official micropython docs for more details:
......
from st3m.reactor import Reactor, Responder from st3m.reactor import Reactor, Responder
from st3m.goose import List from st3m.goose import List
from st3m.ui.menu import MenuItem, MenuItemBack, MenuItemForeground, MenuItemNoop from st3m.ui.menu import (
MenuItem,
MenuItemBack,
MenuItemForeground,
MenuItemNoop,
MenuItemAction,
)
from st3m.ui.elements import overlays from st3m.ui.elements import overlays
from st3m.ui.view import View, ViewManager, ViewTransitionBlend from st3m.ui.view import View, ViewManager, ViewTransitionBlend
from st3m.ui.elements.menus import SimpleMenu, SunMenu from st3m.ui.elements.menus import SimpleMenu, SunMenu
...@@ -8,6 +14,10 @@ from st3m.application import discover_bundles, BundleMetadata ...@@ -8,6 +14,10 @@ from st3m.application import discover_bundles, BundleMetadata
from st3m import settings, logging, processors from st3m import settings, logging, processors
import captouch, audio, leds, gc import captouch, audio, leds, gc
import os
import machine
log = logging.Log(__name__, level=logging.INFO) log = logging.Log(__name__, level=logging.INFO)
...@@ -91,6 +101,11 @@ def run_view(v: View) -> None: ...@@ -91,6 +101,11 @@ def run_view(v: View) -> None:
reactor.run() reactor.run()
def yeet_local_changes() -> None:
os.remove("/flash/sys/.sys-installed")
machine.reset()
def run_main() -> None: def run_main() -> None:
log.info(f"starting main") log.info(f"starting main")
log.info(f"free memory: {gc.mem_free()}") log.info(f"free memory: {gc.mem_free()}")
...@@ -110,7 +125,8 @@ def run_main() -> None: ...@@ -110,7 +125,8 @@ def run_main() -> None:
MenuItemForeground("Settings", menu_settings), MenuItemForeground("Settings", menu_settings),
MenuItemNoop("Disk Mode"), MenuItemNoop("Disk Mode"),
MenuItemNoop("About"), MenuItemNoop("About"),
MenuItemNoop("Reboot"), MenuItemAction("Yeet Local Changes", yeet_local_changes),
MenuItemAction("Reboot", lambda: machine.reset()),
], ],
) )
menu_main = SunMenu( menu_main = SunMenu(
......
...@@ -2,7 +2,7 @@ import st3m ...@@ -2,7 +2,7 @@ import st3m
from st3m import Responder from st3m import Responder
from st3m import logging from st3m import logging
from st3m.goose import ABCBase, abstractmethod, List, Optional from st3m.goose import ABCBase, abstractmethod, List, Optional, Callable
from st3m.input import InputState, InputController from st3m.input import InputState, InputController
from st3m.ui.view import ( from st3m.ui.view import (
BaseView, BaseView,
...@@ -14,7 +14,6 @@ from st3m.ui.view import ( ...@@ -14,7 +14,6 @@ from st3m.ui.view import (
from st3m.ui.interactions import ScrollController from st3m.ui.interactions import ScrollController
from ctx import Context from ctx import Context
log = logging.Log(__name__) log = logging.Log(__name__)
...@@ -73,6 +72,22 @@ class MenuItemForeground(MenuItem): ...@@ -73,6 +72,22 @@ class MenuItemForeground(MenuItem):
return self._label return self._label
class MenuItemAction(MenuItem):
"""
A MenuItem which runs the provided lambda action.
"""
def __init__(self, label: str, action: Callable[[], None]) -> None:
self._label = label
self._action = action
def press(self, vm: Optional[ViewManager]) -> None:
self._action()
def label(self) -> str:
return self._label
class MenuItemNoop(MenuItem): class MenuItemNoop(MenuItem):
""" """
A MenuItem which does nothing. A MenuItem which does nothing.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment