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

py/gr33nhouse: fix typing issues

parent bc502848
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,9 @@ class Gr33nhouseApp(Application): ...@@ -62,6 +62,9 @@ class Gr33nhouseApp(Application):
ctx.restore() ctx.restore()
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
if self.vm is None:
raise RuntimeError("vm is None")
self.background.think(ins, delta_ms) self.background.think(ins, delta_ms)
self.input.think(ins, delta_ms) self.input.think(ins, delta_ms)
......
from st3m.goose import Optional, Enum from st3m.goose import Optional, Enum, Any
from st3m.input import InputController, InputState from st3m.input import InputController, InputState
from st3m.ui import colours from st3m.ui import colours
from st3m.ui.view import BaseView, ViewManager from st3m.ui.view import BaseView, ViewManager
...@@ -20,7 +20,7 @@ class AppList(BaseView): ...@@ -20,7 +20,7 @@ class AppList(BaseView):
initial_ticks: int = 0 initial_ticks: int = 0
_state: ViewState = ViewState.INITIAL _state: ViewState = ViewState.INITIAL
apps: list[any] = [] apps: list[Any] = []
selection: int = 0 selection: int = 0
input: InputController input: InputController
...@@ -153,13 +153,13 @@ class AppList(BaseView): ...@@ -153,13 +153,13 @@ class AppList(BaseView):
self.selection += 1 self.selection += 1
elif self.input.buttons.app.middle.pressed: elif self.input.buttons.app.middle.pressed:
print(f"state {self._state}") if self.vm is None:
print(f">> {self.apps[self.selection]}") raise RuntimeError("vm is None")
app = self.apps[self.selection] app = self.apps[self.selection]
url = app["tarDownloadUrl"] url = app["tarDownloadUrl"]
name = app["name"] name = app["name"]
author = app["author"] author = app["author"]
# self.vm.push(DownloadView(url))
self.vm.push( self.vm.push(
ConfirmationView( ConfirmationView(
url=url, url=url,
......
...@@ -28,7 +28,7 @@ class Flow3rView(BaseView): ...@@ -28,7 +28,7 @@ class Flow3rView(BaseView):
c.y += (10 * delta_ms / 1000.0) * 200 / c.z c.y += (10 * delta_ms / 1000.0) * 200 / c.z
if c.y > 300: if c.y > 300:
c.y = -300 c.y = -300
c.rot += delta_ms * c.rot_speed c.rot += float(delta_ms) * c.rot_speed
self.flowers = sorted(self.flowers, key=lambda c: -c.z) self.flowers = sorted(self.flowers, key=lambda c: -c.z)
def draw(self, ctx: Context) -> None: def draw(self, ctx: Context) -> None:
...@@ -47,10 +47,10 @@ class Flower: ...@@ -47,10 +47,10 @@ class Flower:
self.x = x self.x = x
self.y = y self.y = y
self.z = z self.z = z
self.rot = 0 self.rot = 0.0
self.rot_speed = (((random.getrandbits(16) - 32767) / 32767.0) - 0.5) / 800 self.rot_speed = (((random.getrandbits(16) - 32767) / 32767.0) - 0.5) / 800
def draw(self, ctx: Context): def draw(self, ctx: Context) -> None:
ctx.save() ctx.save()
ctx.translate(-78 + self.x, -70 + self.y) ctx.translate(-78 + self.x, -70 + self.y)
ctx.translate(50, 40) ctx.translate(50, 40)
......
...@@ -3,6 +3,7 @@ from st3m.ui import colours ...@@ -3,6 +3,7 @@ from st3m.ui import colours
from st3m.ui.view import BaseView, ViewManager from st3m.ui.view import BaseView, ViewManager
from ctx import Context from ctx import Context
from .background import Flow3rView from .background import Flow3rView
from .download import DownloadView
class ConfirmationView(BaseView): class ConfirmationView(BaseView):
...@@ -44,27 +45,41 @@ class ConfirmationView(BaseView): ...@@ -44,27 +45,41 @@ class ConfirmationView(BaseView):
ctx.rgb(*colours.BLACK) ctx.rgb(*colours.BLACK)
ctx.font = "Camp Font 3" ctx.font = "Camp Font 3"
ctx.font_size = 24
ctx.text_align = ctx.CENTER ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE ctx.text_baseline = ctx.MIDDLE
ctx.font_size = 16
ctx.move_to(0, -60) ctx.move_to(0, -60)
ctx.text("Install") ctx.text("Install")
ctx.font_size = 24
ctx.move_to(0, -30) ctx.move_to(0, -30)
ctx.text(self.name) ctx.text(self.name)
ctx.font_size = 16
ctx.move_to(0, 0) ctx.move_to(0, 0)
ctx.text("by") ctx.text("by")
ctx.font_size = 24
ctx.move_to(0, 30) ctx.move_to(0, 30)
ctx.text(self.author) ctx.text(self.author)
ctx.font_size = 16
ctx.move_to(0, 60) ctx.move_to(0, 60)
ctx.text("?") ctx.text("(Right shoulder to abort)")
ctx.restore() ctx.restore()
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
self.input.think(ins, delta_ms) self.input.think(ins, delta_ms)
self.background.think(ins, delta_ms) self.background.think(ins, delta_ms)
if self.vm is None:
raise RuntimeError("vm is None")
if self.input.buttons.app.middle.pressed:
self.vm.push(
DownloadView(
url=self.url,
)
)
import network
from st3m.input import InputState from st3m.input import InputState
from st3m.goose import Optional
import urequests import urequests
import gzip import gzip
import utarfile from utarfile import TarFile, DIRTYPE
import io import io
import os import os
from st3m.ui.view import BaseView from st3m.ui.view import BaseView
...@@ -10,6 +10,8 @@ from ctx import Context ...@@ -10,6 +10,8 @@ from ctx import Context
class DownloadView(BaseView): class DownloadView(BaseView):
response: Optional[urequests.Response]
def __init__(self, url: str) -> None: def __init__(self, url: str) -> None:
super().__init__() super().__init__()
self._state = 1 self._state = 1
...@@ -38,7 +40,8 @@ class DownloadView(BaseView): ...@@ -38,7 +40,8 @@ class DownloadView(BaseView):
try: try:
print("Getting it") print("Getting it")
self.response = urequests.get(self._url) self.response = urequests.get(self._url)
if self.response.content is not None:
if self.response is not None and self.response.content is not None:
print("Got something") print("Got something")
self._state = 3 self._state = 3
return return
...@@ -49,12 +52,15 @@ class DownloadView(BaseView): ...@@ -49,12 +52,15 @@ class DownloadView(BaseView):
self._try += 1 self._try += 1
elif self._state == 4: elif self._state == 4:
if self.response is None:
raise RuntimeError("response is None")
tar = gzip.decompress(self.response.content) tar = gzip.decompress(self.response.content)
self.response = None self.response = None
t = utarfile.TarFile(fileobj=io.BytesIO(tar)) t = TarFile(fileobj=io.BytesIO(tar))
for i in t: for i in t:
print(i.name) print(i.name)
if i.type == utarfile.DIRTYPE: if i.type == DIRTYPE:
print("dirtype") print("dirtype")
dirname = "/flash/sys/apps/" + i.name dirname = "/flash/sys/apps/" + i.name
if not os.path.exists(dirname): if not os.path.exists(dirname):
...@@ -69,4 +75,7 @@ class DownloadView(BaseView): ...@@ -69,4 +75,7 @@ class DownloadView(BaseView):
with open(filename, "wb") as of: with open(filename, "wb") as of:
of.write(f.read()) of.write(f.read())
self._state = 5 self._state = 5
if self.vm is None:
raise RuntimeError("vm is None")
self.vm.pop() self.vm.pop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment