-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScreenSensors.py
120 lines (92 loc) · 3.58 KB
/
ScreenSensors.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
120
import sys,random
from kivymd.uix.boxlayout import MDBoxLayout
from kivy.lang.builder import Builder
from kivy.uix.label import Label
from kivy import metrics as kmetrics
from kivymd.uix.textfield import MDTextField
from kivy.clock import Clock
from kivymd.uix.expansionpanel import MDExpansionPanel
class ScreenSensors:
def __init__(self):
Clock.schedule_once(self.updateIpsOnScreen, 0.5)
def setGui(self, gui):
self.gui = gui
self.initDone = False
self.wObjs = {}
self.initSensorsWidgets()
def getRowForGui(self, name):
rb = MDBoxLayout( orientation='horizontal' )
vl = MDTextField()
rb.add_widget(vl)
#rb.add_widget( Label(text=" {}:".format(name) ) )
#vl = Label(text="- - -")
#rb.add_widget(vl)
vl.hint_text = "{}:".format(name)
vl.text = "- - -"
vl.disabled = True
return vl,rb
def updateIpsOnScreen(self, *a):
if self.gui.rl.current == 'Sensors':
print("soo?",self.gui.ips)
self.gui.rl.ids.l_phoLocIps.text = "{}".format(
", ".join(self.gui.ips)
)
def update(self, fromWho, vals):
if self.gui.rl.current != "Sensors":
return 0
#print('update',fromWho,'->',vals)
wObj = self.wObjs[fromWho]
#print("wObj",wObj)
objs = wObj['objs']
for ii, o in enumerate(objs):
#print("making ii",ii,' o',o)
ok = list(o.keys())[0]
#print("ok",ok)
if wObj['vType'] == 'list':
#print("list val",vals[ii])
objs[ii][ok].text = str(vals[ii])
if wObj['vType'] == 'dict':
try:
#print("dict val",vals[ok])
objs[ii][ok].text = str(vals[ok])
except:
print("EE - 0032 val key",ok," not pressent :(")
objs[ii][ok].text = 'NaN'
def initSensorsWidgets(self):
if self.initDone == True:
return 1
bw = self.gui.rl.ids.l_sSen
print("ssen - bw children",len(bw.children))
for s in self.gui.sen.sensorsList:
print("\-","(",s.type,")",s)
sDesc = s.getValuesOptions()
sDescType = list(sDesc.keys())[0]
sVals = sDesc[sDescType]
objs = []
self.wObjs[s.type] = {
'name':s.type,
'vType':sDescType
}
print("buildind sensor view for ",s.type,
" [",sDescType,"]->",sDesc[sDescType]
)
mb = MDBoxLayout(
orientation='vertical',
size_hint= (1.0,None)
)
mb.add_widget( Label(text=str(s.type)) )
for ii,v in enumerate(sVals):
vl,rb = self.getRowForGui(v)
objName = v if sDescType == 'dict' else ii
objs.append( { objName:vl } )
mb.add_widget(rb)
s.addCallBack(self,'Sensors', maxUpdateEvery=(random.randrange(1000,2000)/1000.0))
self.wObjs[s.type]['objs'] = objs
mb.size = [
mb.size[0],
(len(sVals)+1)*(self.gui.btH)
]
bw.add_widget(mb)
#print(self.wObjs)
#sys.exit(0)
self.initDone = True