-
Notifications
You must be signed in to change notification settings - Fork 9
/
ShutterBrick.py
87 lines (65 loc) · 2.51 KB
/
ShutterBrick.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
from qt import *
import SynopticBrick
__category__ = 'Synoptic'
class ShutterBrick(SynopticBrick.SynopticBrick):
shutterState = {
'unknown': 'gray',
'closed': '#ffffef',
'opened': '#00ff00',
'moving': '#663300',
'automatic': '#009900',
'fault': '#990000',
'disabled': '#ff00ff',
'error': '#990000'
}
def __init__(self, *args):
SynopticBrick.SynopticBrick.__init__.im_func(self, *args)
self.addProperty('mnemonic', 'string')
self.shutter = None
#
# GUI elements
#
self.lblShutter = QLabel('shutter', self.containerBox)
self.cmdOpenCloseShutter = QPushButton('', self.containerBox)
self.lblShutter.setAlignment(Qt.AlignCenter)
#
# connect signals/slots
#
self.connect(self.cmdOpenCloseShutter, SIGNAL('clicked()'), self.cmdOpenCloseShutterClicked)
#
# configuration
#
self.cmdOpenCloseShutter.setEnabled(False)
def updateGUI(self):
self.shutter = self.getHardwareObject(self['mnemonic'])
if self.shutter is not None:
if self.isRunning():
self.setEnabled(True)
self.shutterStateChanged(self.shutter.getShutterState())
self.connect(self.shutter, PYSIGNAL('shutterStateChanged'), self.shutterStateChanged)
else:
self.cmdOpenCloseShutter.setEnabled(False)
def shutterStateChanged(self, state):
self.lblShutter.setPaletteBackgroundColor(QColor(ShutterBrick.shutterState[state]))
self.lblShutter.setText('<b>%s</b>' % state)
if state == 'opened' or state == 'automatic':
self.cmdOpenCloseShutter.setText('Close')
self.cmdOpenCloseShutter.setEnabled(True)
elif state == 'closed':
self.cmdOpenCloseShutter.setText('Open')
self.cmdOpenCloseShutter.setEnabled(True)
else:
self.cmdOpenCloseShutter.setEnabled(False)
def cmdOpenCloseShutterClicked(self):
if self.cmdOpenCloseShutter.text() == 'Open':
self.shutter.openShutter()
else:
self.shutter.closeShutter()
def setMnemonic(self, mne):
self.getProperty('mnemonic').setValue(mne)
self.updateGUI()
def propertyChanged(self, propertyName, oldValue, newValue):
if propertyName == 'mnemonic':
self.updateGUI()
else:
SynopticBrick.SynopticBrick.propertyChanged.im_func(self, propertyName, oldValue, newValue)