Skip to content
Snippets Groups Projects
Commit c1eacb49 authored by Anon's avatar Anon Committed by schneider
Browse files

py/gr33nhouse: tweak app store

parent 7670d193
No related branches found
No related tags found
No related merge requests found
from st3m.goose import Enum
from st3m.application import Application, ApplicationContext
from st3m.input import InputController, InputState
from st3m.ui import colours
from st3m.ui.view import ViewManager
from ctx import Context
import network
from .applist import AppList
from .background import Flow3rView
from .record import RecordView
from .manual import ManualInputView
class ViewState(Enum):
CONTENT = 1
NO_INTERNET = 2
class Gr33nhouseApp(Application):
items = ["Browse apps", "Record App Seed", "Enter App Seed"]
selection = 0
input: InputController
background: Flow3rView
state: ViewState
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx=app_ctx)
......@@ -22,6 +30,8 @@ class Gr33nhouseApp(Application):
self.input = InputController()
self.background = Flow3rView()
self.state = ViewState.CONTENT
def on_enter(self, vm: ViewManager | None) -> None:
super().on_enter(vm)
......@@ -29,6 +39,32 @@ class Gr33nhouseApp(Application):
raise RuntimeError("vm is None")
def draw(self, ctx: Context) -> None:
if self.state == ViewState.NO_INTERNET:
ctx.move_to(0, 0)
ctx.rgb(*colours.BLACK)
ctx.rectangle(
-120.0,
-120.0,
240.0,
240.0,
).fill()
ctx.save()
ctx.rgb(*colours.WHITE)
ctx.font = "Camp Font 3"
ctx.font_size = 24
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
ctx.move_to(0, -15)
ctx.text("No internet")
ctx.move_to(0, 15)
ctx.text("Check settings")
ctx.restore()
return
self.background.draw(ctx)
ctx.save()
......@@ -62,11 +98,18 @@ class Gr33nhouseApp(Application):
ctx.restore()
def think(self, ins: InputState, delta_ms: int) -> None:
self.input.think(ins, delta_ms)
if self.vm is None:
raise RuntimeError("vm is None")
if not network.WLAN(network.STA_IF).isconnected():
self.state = ViewState.NO_INTERNET
return
else:
self.state = ViewState.CONTENT
self.background.think(ins, delta_ms)
self.input.think(ins, delta_ms)
if self.input.buttons.app.left.pressed:
if self.selection > 0:
......
......@@ -78,7 +78,7 @@ class ConfirmationView(BaseView):
raise RuntimeError("vm is None")
if self.input.buttons.app.middle.pressed:
self.vm.push(
self.vm.replace(
DownloadView(
url=self.url,
)
......
from st3m.input import InputState
from st3m.input import InputController, InputState
from st3m.goose import Optional
from st3m.ui import colours
import urequests
import gzip
from utarfile import TarFile, DIRTYPE
......@@ -12,29 +13,74 @@ from ctx import Context
class DownloadView(BaseView):
response: Optional[urequests.Response]
"""
View state
1 = Init
2 = Fetching
3 = Extracting
4 = Extracting
5 = Done
"""
state: int
input: InputController
def __init__(self, url: str) -> None:
super().__init__()
self._state = 1
self._try = 1
self._url = url
self.input = InputController()
def draw(self, ctx: Context) -> None:
ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
ctx.save()
ctx.move_to(0, 0)
if self._state == 1 or self._state == 2:
# Fetching
ctx.rgb(255, 0, 0).rectangle(-20, -20, 40, 40).fill()
ctx.rgb(*colours.WHITE)
ctx.font = "Camp Font 3"
ctx.font_size = 24
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
ctx.text("Downloading...")
self._state = 2
elif self._state == 3 or self._state == 4:
# Extracting
ctx.rgb(0, 0, 255).rectangle(-20, -20, 40, 40).fill()
ctx.rgb(*colours.WHITE)
ctx.font = "Camp Font 3"
ctx.font_size = 24
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
ctx.text("Extracting...")
self._state = 4
elif self._state == 5:
# Done
ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill()
ctx.move_to(0, -30)
ctx.rgb(*colours.WHITE)
ctx.font = "Camp Font 3"
ctx.font_size = 24
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
ctx.text("All done!")
ctx.move_to(0, 0)
ctx.text("The app will be")
ctx.move_to(0, 30)
ctx.text("available after reboot")
ctx.restore()
def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms) # Let BaseView do its thing
# super().think(ins, delta_ms) # Let BaseView do its thing
self.input.think(ins, delta_ms)
if self._state == 2:
try:
......@@ -76,6 +122,7 @@ class DownloadView(BaseView):
of.write(f.read())
self._state = 5
if self.input.buttons.app.middle.pressed:
if self.vm is None:
raise RuntimeError("vm is None")
self.vm.pop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment