-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcnled.py
89 lines (70 loc) · 3.52 KB
/
cnled.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
# -*- coding: UTF-8 -*-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' '
' Copyright 2018-2024 Gauthier Brière (gauthier.briere "at" gmail.com) '
' '
' This file is part of cn5X++ '
' '
' cn5X++ is free software: you can redistribute it and/or modify it '
' under the terms of the GNU General Public License as published by '
' the Free Software Foundation, either version 3 of the License, or '
' (at your option) any later version. '
' '
' cn5X++ is distributed in the hope that it will be useful, but '
' WITHOUT ANY WARRANTY; without even the implied warranty of '
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the '
' GNU General Public License for more details. '
' '
' You should have received a copy of the GNU General Public License '
' along with this program. If not, see <http://www.gnu.org/licenses/>. '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import sys, os
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import pyqtSignal, pyqtSlot, QSize, pyqtProperty
class cnLed(QtWidgets.QLabel):
''' QLabel affichant une image de Led eteinte ou allumee '''
statusChanged = pyqtSignal(bool) # signal emis a chaque changement de valeur
def __init__(self, parent=None):
super(cnLed, self).__init__(parent=parent)
self.__couleur = "Rouge" # Rouge ou Verte
# Chemin des images dans le fichier de resources
self.__imagePath = os.path.join(os.path.dirname(__file__), "images/")
self.iconOff = QtGui.QPixmap(self.__imagePath + "led" + self.__couleur + "Eteinte.svg")
self.iconOn = QtGui.QPixmap(self.__imagePath + "led" + self.__couleur + "Alumee.svg")
# Proprietes du label
self.setMaximumSize(QSize(20, 20))
self.setText("")
self.setPixmap(self.iconOff)
self.setScaledContents(True)
self.__ledStatus = False # led eteinte a l'initialisation
@pyqtSlot()
def Couleur(self):
return self.__couleur
@pyqtSlot()
def setCouleur(self, couleur):
if self.__couleur != couleur:
self.__couleur = couleur
self.iconOff = QtGui.QPixmap(self.__imagePath + "led" + self.__couleur + "Eteinte.svg")
self.iconOn = QtGui.QPixmap(self.__imagePath + "led" + self.__couleur + "Alumee.svg")
if self.__ledStatus:
self.setPixmap(self.iconOn)
else:
self.setPixmap(self.iconOff)
@pyqtSlot()
def ledStatus(self):
''' Renvoie le status de la Led '''
return self.__ledStatus
@pyqtSlot(bool)
def setLedStatus(self, s: bool):
''' Allume (s=True) ou eteind (s=False) la Led '''
if self.__ledStatus != s:
if s:
self.setPixmap(self.iconOn)
else:
self.setPixmap(self.iconOff)
self.__ledStatus = s
self.statusChanged.emit(s)
# Definie les propriétés pour permettre la configuration par Designer
ledStatus = pyqtProperty("bool", fget=ledStatus, fset=setLedStatus)
Couleur = pyqtProperty("QString", fget=Couleur, fset=setCouleur)