This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQLedIndicator.py
50 lines (36 loc) · 1.56 KB
/
QLedIndicator.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
from PyQt5.QtCore import Q_ENUMS, Qt
from PyQt5.QtWidgets import QGraphicsOpacityEffect, QLabel, QSizePolicy, QVBoxLayout, QFrame, QWidget
class ComponentStatus:
ON = 0
OFF = 1
class QLedIndicator(QFrame):
Q_ENUMS(ComponentStatus)
def __init__(self, title, parent=None):
QFrame.__init__(self, parent)
self.status = ComponentStatus.OFF
self.titleLabel = QLabel(title)
self.titleLabel.setAlignment(Qt.AlignCenter)
self.statusLabel = QLabel(
"On" if self.status == ComponentStatus.ON else "Off")
self.statusLabel.setAlignment(Qt.AlignCenter)
self.vLayout = QVBoxLayout(self)
self.vLayout.addWidget(self.titleLabel)
self.vLayout.addWidget(self.statusLabel)
self.vLayout.setAlignment(
self.vLayout, Qt.AlignHCenter | Qt.AlignVCenter)
self.setLayout(self.vLayout)
self.opacityEffect = QGraphicsOpacityEffect(self)
self.setObjectName("LedIndicatorFrame")
self.setFrameStyle(QFrame.Box | QFrame.Panel)
self.setStyleSheet(
'#LedIndicatorFrame { border: 3px solid #FFFFFF; background-color: #304E6E; }')
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.deactivate()
def activate(self):
self.status = ComponentStatus.ON
self.opacityEffect.setOpacity(0.3)
self.setGraphicsEffect(self.opacityEffect)
def deactivate(self):
self.status = ComponentStatus.OFF
self.opacityEffect.setOpacity(0.3)
self.setGraphicsEffect(self.opacityEffect)