-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhil_widget.py
110 lines (88 loc) · 3.3 KB
/
hil_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
#!/usr/bin/python
"""
Author: Ellen Sawitzki
"""
import time
from PyQt5.QtWidgets import (QLabel, QWidget, QSlider, QApplication,
QHBoxLayout, QVBoxLayout, QGridLayout,
QStyleOption, QStyle)
from PyQt5.QtCore import QObject, Qt, pyqtSignal
from PyQt5.QtGui import QPainter, QFont, QColor, QPen
import sys
class HILWidget(QWidget):
def __init__(self, num = None):
super().__init__()
if num is None:
self.HILnum = QLabel("NA")
else:
self.HILnum = QLabel(num)
self.curDistance = QLabel("0")
self.curTime = QLabel("0")
self.lifeDistance = QLabel("0")
self.lifeTime = QLabel("0")
curQL = QLabel("session")
lifeQL = QLabel("lifetime")
dUnit = QLabel("miles")
tUnit = QLabel("hours")
layout = QGridLayout()
layout.addWidget(self.HILnum, 0, 0, 3, 0)
layout.addWidget(curQL, 0, 1)
layout.addWidget(lifeQL, 0, 2)
layout.addWidget(self.curDistance, 1, 1)
layout.addWidget(self.curTime, 2, 1)
layout.addWidget(self.lifeDistance, 1, 2)
layout.addWidget(self.lifeTime, 2, 2)
layout.addWidget(dUnit, 1, 3)
layout.addWidget(tUnit, 2, 3)
self.setLayout(layout)
#self.setStyleSheet("HILWidget{ border: 3px solid white; background-color: rgba(255, 255, 255, 95); } QLabel{ color: white; font: 18px }")
self.setStyleSheet("HILWidget{ background-color: rgba(255, 255, 255, 95); } QLabel{ color: white; font: 18px }")
self.HILnum.setStyleSheet("font: bold 50px") #70
#self.initUI()
def initUI(self, num = None):
# if num is None:
# self.HILnum = QLabel("not initialized")
# else:
# self.HILnum = QLabel(num)
layout = QVBoxLayout()
layout.addWidget(self.HILnum)
self.setLayout(layout)
# self.setGeometry(300, 300, 390, 210)
# self.setWindowTitle('Burning widget')
# self.show()
def paintEvent(self, e):
opt = QStyleOption()
opt.initFrom(self)
p = QPainter(self)
self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)
def changeBackground(self, color):
if color == 'r':
styleColor = "252, 87, 45, 90"
elif color == 'g':
styleColor = "71, 156, 89, 90"
elif color == 'y':
styleColor = "255, 201, 101, 90"
elif color == 'h':
styleColor = "109, 113, 117, 90"
elif color == 'b':
styleColor = "0, 0, 0, 90"
elif color == 't':
styleColor = "0, 0, 0, 0"
else:
return
#self.setStyleSheet("HILWidget{ border: 3px solid white; background-color: rgba(" + styleColor + "); } QLabel{ color: white; font: 18px }")
self.setStyleSheet("HILWidget{ background-color: rgba(" + styleColor + "); } QLabel{ color: white; font: 18px }")
# self.style().unpolish(self)
# self.style().polish(self)
# self.update()
#print("check2")
# self.c.updateBW.emit(value)
# self.wid.repaint()
def main():
app = QApplication(sys.argv)
hw = HILWidget()
hw.show()
#hw.changeBackground('r')
sys.exit(app.exec_())
if __name__ == '__main__':
main()