-
Notifications
You must be signed in to change notification settings - Fork 10
/
apps.py
85 lines (68 loc) · 2.56 KB
/
apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from buttons import Buttons
from display import Display
from speaker import Speaker
class App:
def __init__(self, name):
self.name = name
self.active = False
self.grab_top_button = False
def top_button(self):
print("top_button not implemented for " + self.name)
class Apps:
def __init__(self, scheduler):
self.scheduler = scheduler
self.display = Display(scheduler)
self.buttons = Buttons(scheduler)
self.speaker = Speaker(scheduler)
self.apps = []
self.current_app = 0
self.buttons.add_callback(1, self.app_chooser, min=500)
self.buttons.add_callback(1, self.app_top_button, max=500)
async def start(self):
await self.apps[0].enable()
def add(self, app):
self.apps.append(app)
async def app_chooser(self):
print("APP CHOOSER")
if len(self.apps) == 0:
return
await self.disable_current_app()
self.buttons.add_callback(2, self.next_app, max=500)
self.buttons.add_callback(3, self.previous_app, max=500)
await self.show_current_app_name()
async def enable_current_app(self):
self.buttons.clear_callbacks(2)
self.buttons.clear_callbacks(3)
self.display.display_queue.clear()
self.display.clear_text()
print("SWITCHING TO", self.apps[self.current_app].name)
# self.speaker.beep(200)
await self.apps[self.current_app].enable()
async def disable_current_app(self):
app = self.apps[self.current_app]
app.disable()
app.active = False
app.grab_top_button = False
self.buttons.clear_callbacks(2)
self.buttons.clear_callbacks(3)
async def show_current_app_name(self):
app = self.apps[self.current_app]
self.display.display_queue.clear()
await self.display.animate_text(app.name, force=True)
await self.display.show_text(app.name)
async def next_app(self):
self.current_app = (self.current_app + 1) % len(self.apps)
await self.show_current_app_name()
async def previous_app(self):
self.current_app = (self.current_app - 1) % len(self.apps)
await self.show_current_app_name()
async def app_top_button(self):
app = self.apps[self.current_app]
if app.active and app.grab_top_button:
should_go_next: bool = await app.top_button()
if should_go_next:
await self.app_chooser()
else:
return
else:
await self.enable_current_app()