forked from ryandoherty/RaceCapture_App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbarview.py
120 lines (97 loc) · 5.25 KB
/
toolbarview.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import kivy
kivy.require('1.9.0')
from utils import *
from kivy.uix.stacklayout import StackLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.progressbar import ProgressBar
from kivy.app import Builder
from kivy.clock import Clock
from iconbutton import IconButton
from kivy.logger import Logger
Builder.load_file('toolbarview.kv')
TOOLBAR_LED_DURATION = 2.0
PROGRESS_COMPLETE_LINGER_DURATION = 5.0
ACTIVITY_MESSAGE_LINGER_DURATION = 10.0
class ToolbarView(BoxLayout):
TELEMETRY_IDLE = 0
TELEMETRY_ACTIVE = 1
TELEMETRY_CONNECTING = 2
TELEMETRY_ERROR = 3
telemetry_color = {TELEMETRY_IDLE:[0.0, 1.0, 0.0, 0.2],
TELEMETRY_ACTIVE:[0.0, 1.0, 0.0, 1.0],
TELEMETRY_CONNECTING:[1.0, 1.0, 0.0, 1.0],
TELEMETRY_ERROR:[1.0, 0.0, 0.0, 1.0]
}
txOffColor = [0.0, 1.0, 0.0, 0.2]
rxOffColor = [0.0, 0.8, 1.0, 0.2]
txOnColor = [0.0, 1.0, 0.0, 1.0]
rxOnColor = [0.0, 0.8, 1.0, 1.0]
normalStatusColor = [0.8, 0.8, 0.8, 1.0]
alertStatusColor = [1.0, 0.64, 0.0, 1.0]
progressBar = None
teleStatus = None
rcTxStatus = None
rcRxStatus = None
def __init__(self, **kwargs):
super(ToolbarView, self).__init__(**kwargs)
self.register_event_type('on_main_menu')
self.register_event_type('on_progress')
self.register_event_type('on_rc_tx')
self.register_event_type('on_rc_rx')
self.register_event_type('on_tele_status')
self.register_event_type('on_status')
self.register_event_type('on_activity')
self._rcTxDecay = Clock.create_trigger(self.on_rc_tx_decay, TOOLBAR_LED_DURATION)
self._rcRxDecay = Clock.create_trigger(self.on_rc_rx_decay, TOOLBAR_LED_DURATION)
self._activityDecay = Clock.create_trigger(self.on_activity_decay, ACTIVITY_MESSAGE_LINGER_DURATION)
self._progressDecay = Clock.create_trigger(self.on_progress_decay, PROGRESS_COMPLETE_LINGER_DURATION)
def on_activity(self, msg):
self.setActivityMessage(msg)
self._activityDecay()
def setActivityMessage(self, msg):
activityLabel = kvFind(self, 'rcid', 'activity')
activityLabel.text = msg
def on_status(self, msg, isAlert):
statusLabel = kvFind(self, 'rcid', 'status')
statusLabel.text = msg
if isAlert == True:
statusLabel.color = self.alertStatusColor
else:
statusLabel.color = self.normalStatusColor
def update_progress(self, value):
if not self.progressBar:
self.progressBar = kvFind(self, 'rcid', 'pbar')
self.progressBar.value = value
if value == 100:
self._progressDecay()
def on_progress(self, value):
self.update_progress(value)
def on_main_menu(self, instance, *args):
pass
def mainMenu(self):
self.dispatch('on_main_menu', None)
def on_progress_decay(self, dt):
self.update_progress(0)
def on_activity_decay(self, dt):
self.setActivityMessage('')
def on_rc_tx_decay(self, dt):
self.on_rc_tx(False)
def on_rc_tx(self, value):
if not self.rcTxStatus:
self.rcTxStatus = kvFind(self, 'rcid', 'rcTxStatus')
self.rcTxStatus.color = self.txOnColor if value else self.txOffColor
self._rcTxDecay()
def on_rc_rx_decay(self, dt):
self.on_rc_rx(False)
def on_rc_rx(self, value):
if not self.rcRxStatus:
self.rcRxStatus = kvFind(self, 'rcid', 'rcRxStatus')
self.rcRxStatus.color = self.rxOnColor if value else self.rxOffColor
self._rcRxDecay()
def on_tele_status(self, status):
if not self.teleStatus:
self.teleStatus = kvFind(self, 'rcid', 'teleStatus')
try:
self.teleStatus.color = self.telemetry_color[status]
except:
Logger.error("ToolbarView: Invalid telemetry status: " + str(status))