Skip to content
Snippets Groups Projects
Commit a109bf32 authored by schneider's avatar schneider
Browse files

app: give applications a context object

parent d2b100d3
No related branches found
No related tags found
No related merge requests found
......@@ -357,7 +357,7 @@ Let's introduce the final class you should actually be using for application dev
.. code-block:: python
from st3m.application import Application
from st3m.application import Application, ApplicationContext
import st3m.run
class SecondScreen(BaseView):
......@@ -381,8 +381,8 @@ Let's introduce the final class you should actually be using for application dev
class MyDemo(Application):
def __init__(self) -> None:
super().__init__(name="My demo")
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
def draw(self, ctx: Context) -> None:
# Paint the background black
......@@ -399,7 +399,7 @@ Let's introduce the final class you should actually be using for application dev
if self.input.right_shoulder.middle.pressed:
self._view_manager.push(SecondScreen())
st3m.run.run_view(Example())
st3m.run.run_view(Example(ApplicationContext()))
The `Application` class gives you the following extras:
......
from st3m import application, logging
from st3m import logging
from st3m.application import Application, ApplicationContext
from st3m.goose import List
from st3m.input import InputState
from ctx import Context
......@@ -32,9 +33,9 @@ class Dot:
).fill()
class CapTouchDemo(application.Application):
def __init__(self, name: str) -> None:
super().__init__(name)
class CapTouchDemo(Application):
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self.dots: List[Dot] = []
self.last_calib = None
# self.ui_autocalib = ui.IconLabel("Autocalib done", size=30)
......
......@@ -17,12 +17,12 @@ chords = [
[3, 7, 10, 14, 15],
]
from st3m.application import Application
from st3m.application import Application, ApplicationContext
class HarmonicApp(Application):
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self.color_intensity = 0.0
self.chord_index = 0
......
......@@ -83,13 +83,13 @@ def foreground() -> None:
adjust_playing_field_to_octave()
from st3m.application import Application
from st3m.application import Application, ApplicationContext
# TODO(q3k): properly port this app
class MelodicApp(Application):
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
init()
def draw(self, ctx: Context) -> None:
......
......@@ -5,7 +5,7 @@ import math
# flow3r imports
from st3m import InputState
from st3m.application import Application
from st3m.application import Application, ApplicationContext
from st3m.property import BLUE, WHITE
from st3m.goose import Optional
from st3m.utils import xy_from_polar, tau
......@@ -16,8 +16,8 @@ from ctx import Context
class ScrollDemo(Application):
PETAL_NO = 8
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self.scroll = CapScrollController()
def draw(self, ctx: Context) -> None:
......
......@@ -5,7 +5,7 @@ import math
# flow3r imports
from st3m import InputState
from st3m.application import Application
from st3m.application import Application, ApplicationContext
from st3m.property import BLUE, WHITE
from st3m.goose import Optional
from st3m.utils import xy_from_polar
......@@ -18,8 +18,8 @@ tau = 2 * math.pi
# Subclass Application
class AppWorms(Application):
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
# HACK: we work against double buffering by keeping note of how many
# times on_draw got called.
......
from st3m.application import Application
from st3m.application import Application, ApplicationContext
from st3m.property import PUSH_RED, GO_GREEN, BLACK
from st3m.goose import Dict, Any
from st3m.input import InputState
......@@ -48,8 +48,8 @@ class Configuration:
class NickApp(Application):
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self._scale = 1.0
self._led = 0.0
self._phase = 0.0
......
......@@ -5,7 +5,7 @@ import math
import leds
from st3m import InputState, Responder
from st3m.application import Application
from st3m.application import Application, ApplicationContext
from st3m.property import BLUE, WHITE
from st3m.goose import Optional
from st3m.utils import xy_from_polar, tau
......@@ -77,8 +77,8 @@ class Otamatone(Application):
PETAL_NO = 3
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self._ts = 0
self._blob = Blob()
......@@ -136,4 +136,4 @@ class Otamatone(Application):
if __name__ == "__main__":
from st3m.run import run_view
run_view(Otamatone("otamatone"))
run_view(Otamatone(ApplicationContext()))
......@@ -3,7 +3,7 @@ import hardware
import captouch
import leds
from st3m.application import Application
from st3m.application import Application, ApplicationContext
from st3m.input import InputState
from st3m.goose import Tuple
from ctx import Context
......@@ -37,8 +37,8 @@ class Dot:
class SimpleDrums(Application):
def __init__(self, name: str) -> None:
super().__init__(name)
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
# ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill()
self.blm = bl00mbox.Channel()
self.seq = self.blm.new(bl00mbox.patches.step_sequencer)
......
......@@ -18,9 +18,20 @@ import sys
log = Log(__name__)
class ApplicationContext:
"""
Container for future application context.
Envisioned are: path to the bundle, bundle data,
path to a data directory, etc...
"""
pass
class Application(BaseView):
def __init__(self, name: str = __name__) -> None:
self._name = name
def __init__(self, app_ctx: ApplicationContext) -> None:
self._app_ctx = app_ctx
super().__init__()
def on_exit(self) -> None:
......@@ -152,7 +163,7 @@ class BundleMetadata:
log.info(f"Loaded {self.name} module: {m}")
klass = getattr(m, class_entry)
log.info(f"Loaded {self.name} class: {klass}")
inst = klass(package_name)
inst = klass(ApplicationContext())
log.info(f"Instantiated {self.name} class: {inst}")
return inst # type: ignore
except Exception as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment