-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQLedIndicator.py
More file actions
57 lines (41 loc) · 1.76 KB
/
Copy pathQLedIndicator.py
File metadata and controls
57 lines (41 loc) · 1.76 KB
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
from PyQt5.QtCore import Qt, QUrl, pyqtProperty, pyqtSlot
from PyQt5.QtWidgets import QWidget
from PyQt5.QtQuick import QQuickView
class QLedIndicator(QWidget):
def __init__(self, title: str, parent=None) -> None:
QWidget.__init__(self, parent)
self.viewer = QQuickView()
self.viewer.setSource(QUrl("resources/LedIndicator.qml"))
self.viewer.setResizeMode(QQuickView.SizeRootObjectToView)
self.container = QWidget.createWindowContainer(self.viewer)
self.container.setFocusPolicy(Qt.TabFocus)
self.title = title
self.refreshPalette()
@pyqtProperty(str)
def title(self) -> None:
return self.viewer.rootObject().property("indicatorTitle")
@title.setter
def title(self, title: str) -> None:
self.viewer.rootObject().setProperty("indicatorTitle", title)
@pyqtProperty(bool)
def status(self) -> bool:
return self.viewer.rootObject().property("isStatusOn")
@status.setter
def status(self, on: bool) -> None:
self.viewer.rootObject().setProperty("isStatusOn", on)
@pyqtSlot()
def enable(self) -> None:
self.status = True
@pyqtSlot()
def disable(self) -> None:
self.status = False
def refreshPalette(self) -> None:
p = self.palette()
self.viewer.setColor(p.window().color())
self.viewer.rootObject().setProperty("textColor", p.text().color())
self.viewer.rootObject().setProperty("borderColor", p.text().color())
backgroundColor = p.highlight().color()
backgroundColor.setAlpha(90)
self.viewer.rootObject().setProperty("backgroundColor", backgroundColor)
titleColor = p.highlight().color()
self.viewer.rootObject().setProperty("titleColor", titleColor)