-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim_widget.py
165 lines (118 loc) · 4.91 KB
/
sim_widget.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
"""
Author: Ellen Sawitzki
"""
from PyQt5.QtWidgets import (QWidget, QLineEdit, QApplication, QLabel,
QHBoxLayout, QVBoxLayout, QGridLayout,
QStyleOption, QStyle)
from PyQt5.QtCore import QObject, Qt, pyqtSignal
from PyQt5.QtGui import QPainter, QFont, QColor, QPen, QPixmap, QPalette, QBrush
import sys
import queue
import threading
from time import sleep
import hil_widget
import guiData
numHILs = 6
class SIMWidget(QWidget):
def __init__(self, orientation):
super().__init__()
if orientation == 'V':
self.resize(400, 550) #change to 800ish
layout = QVBoxLayout()
topLayout = QGridLayout()
self.distance = QLabel("0 miles")
self.time = QLabel("0 hours")
topLayout.addWidget(self.distance, 0, 0)
topLayout.addWidget(self.time, 0, 1)
layout.addLayout(topLayout)
self.hilVec = []
for i in range (1, numHILs + 1):
hil = hil_widget.HILWidget(str(i))
self.hilVec.append(hil)
layout.addWidget(hil)
self.userInput = QLineEdit()
layout.addWidget(self.userInput)
self.setLayout(layout)
self.setWindowTitle("SIMformation Widget")
self.distance.setStyleSheet("color: white; font: bold 35px")
self.time.setStyleSheet("color: white; font: bold 35px")
elif orientation == 'H':
self.resize(775, 600) #change to 800ish
layout = QGridLayout()
topLayout = QGridLayout()
self.distance = QLabel("0 miles")
self.time = QLabel("0 hours")
topLayout.addWidget(self.distance, 0, 0)
topLayout.addWidget(self.time, 0, 1)
layout.addLayout(topLayout, 0, 0, 1, 0)
if numHILs % 3 == 0: totalRows = int(numHILs / 3)
else: totalRows = int(numHILs / 3) + 1
self.hilVec = []
n = 1
for i in range (0, totalRows):
for j in range (0, 3):
if n <= numHILs:
hil = hil_widget.HILWidget(str(n))
self.hilVec.append(hil)
layout.addWidget(hil, i + 1, j)
n = n + 1
self.userInput = QLineEdit()
layout.addWidget(self.userInput, totalRows + 1, 0, totalRows + 1, 2)
self.setLayout(layout)
self.setWindowTitle("SIMformation Widget")
self.distance.setStyleSheet("color: white; font: bold 35px")
self.time.setStyleSheet("color: white; font: bold 35px")
background = QPixmap("/home/pi/Documents/Orasi/matteo-bernardis-QpIayO5KIRE-unsplash.jpg")
background = background.scaled(self.size(), Qt.IgnoreAspectRatio, Qt.FastTransformation)
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(background))
self.setPalette(palette)
#self.initUI()
self.userInput.returnPressed.connect(self.changeColor)
def paintEvent(self, e):
opt = QStyleOption()
opt.initFrom(self)
p = QPainter(self)
self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)
def dataUpdate(self, data):
#print("check: " , data.test)
self.distance.setText(data.totDistance + " miles")
self.time.setText(data.totTime + " hours")
for i in range(1, numHILS + 1):
self.hilVec[i].curDistance.setText(str(data.hilDataVec[i].hilCurDistance))
self.hilVec[i].curTime.setText(str(data.hilDataVec[i].hilCurTime))
self.hilVec[i].lifeDistance.setText(str(data.hilDataVec[i].hilLifeDistance))
self.hilVec[i].lifeTime.setText(str(data.hilDataVec[i].hilLifeTime))
if data.status == Status.STANDBY:
self.hilVec[i].changeBackground('b')
elif data.status == Status.RUNNING:
self.hilVec[i].changeBackground('g')
def changeColor(self):
t = self.userInput.text()
self.userInput.setText("")
hilNumCheck = ""
for i in range(1, numHILs + 1):
hilNumCheck = hilNumCheck + str(i)
chars = set(hilNumCheck)
if (len(t) == 2) and any((c in chars) for c in t[0]):
self.hilVec[int(t[0]) - 1].changeBackground(t[1])
# def initUI(self):
# self.setMinimumSize(1, 30)
# self.value = 75
# self.num = [75, 150, 225, 300, 375, 450, 525, 600, 675]
def main():
app = QApplication(sys.argv)
q = queue.Queue()
sw = SIMWidget(q)
sw.show()
sys.exit(app.exec_())
# while 1:
# sleep(1)
# countGet = countGet + 1
# getData = q.get()
# guiData = getData
# print(f'data get {countGet}: {getData}')
# q.task_done()
if __name__ == '__main__':
main()