-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.py
More file actions
78 lines (65 loc) · 1.87 KB
/
window.py
File metadata and controls
78 lines (65 loc) · 1.87 KB
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
from ui import *
from mqtt import MqttClient
import json # To decode messages from MQTT (used by subclasses)
class WindowBase(Log):
_Mqtt = MqttClient
_Ui = Ui
def __init__(self, name: str):
super().__init__(name)
self._is_active = False
@staticmethod
def set_mqtt(mqtt: MqttClient):
WindowBase._Mqtt = mqtt
@staticmethod
def set_ui(ui: Ui):
WindowBase._Ui = ui
def _start(self) -> None:
"""
To be overwritten by subclasses.
Called by start()
"""
pass
def _stop(self) -> None:
"""
To be overwritten by subclasses.
Called by stop()
"""
pass
def _receive(self, client, userdata, msg) -> None:
"""
To be overwritten by subclasses.\n
Passed to MQTT to be called on message receive when subscribing, eg:\n
self._Mqtt.sub("miniplayer/window/topic", self._receive)
"""
pass
def start(self) -> None:
"""
Run when the window becomes active
"""
if self._is_active:
self.log('Started without stopping, aborted', LogLevel.WRN)
return
self._start()
self._is_active = True
self.log('Started', LogLevel.INF)
def stop(self) -> None:
"""
Run when the window becomes inactive
"""
if not self._is_active:
self.log('Stopped without starting, aborted', LogLevel.WRN)
return
self._stop()
self._is_active = False
self.log('Stopped', LogLevel.INF)
def draw(self) -> None:
"""
Draws the window to the screen
"""
self._Ui.background()
self._Ui.text(self.name, 20)#, center=(self._Ui.Center, 25))
def update(self) -> None:
"""
Update the window (run inputs, updates, etc)
"""
pass