-
Notifications
You must be signed in to change notification settings - Fork 9
/
Qt4_LightControlBrick.py
152 lines (125 loc) · 6.17 KB
/
Qt4_LightControlBrick.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#
# Project: MXCuBE
# https://github.com/mxcube.
#
# This file is part of MXCuBE software.
#
# MXCuBE 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.
#
# MXCuBE 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 MXCuBE. If not, see <http://www.gnu.org/licenses/>.
from BlissFramework.Qt4_BaseComponents import BlissWidget
from BlissFramework.Bricks import Qt4_MotorSpinBoxBrick
from BlissFramework import Qt4_Icons
import logging
from QtImport import *
'''
Controls both the light on/off (light_actuator) and intensity (motor)
'''
__category__ = 'General'
STATE_OUT, STATE_IN, STATE_MOVING, STATE_FAULT, STATE_ALARM, STATE_UNKNOWN = \
(0,1,9,11,13,23)
class Qt4_LightControlBrick(Qt4_MotorSpinBoxBrick.Qt4_MotorSpinBoxBrick):
def __init__(self, *args):
Qt4_MotorSpinBoxBrick.Qt4_MotorSpinBoxBrick.__init__(self, *args)
self.light_actuator_hwo = None
self.light_saved_pos=None
self.addProperty('light_actuator', 'string', '')
self.addProperty('icons', 'string', '')
self.addProperty('out_delta', 'string', '')
self.light_off_button=QPushButton("",self.extra_button_box)
self.light_off_button.setIcon(Qt4_Icons.load_icon('BulbDelete'))
self.light_on_button=QPushButton("",self.extra_button_box)
self.light_on_button.setIcon(Qt4_Icons.load_icon('BulbCheck'))
self.light_on_button.clicked.connect(self.lightButtonOffClicked)
self.light_off_button.clicked.connect(self.lightButtonOnClicked)
self.extra_button_box_layout.addWidget(self.light_off_button)
self.extra_button_box_layout.addWidget(self.light_on_button)
#self.position_spinbox.close()
#self.step_button.close()
#self.stop_button.close()
self.light_off_button.setToolTip("Switches off the light and sets the intensity to zero")
self.light_on_button.setToolTip("Switches on the light and sets the intensity back to the previous setting")
self.light_off_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
self.light_on_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
### Light off pressed: switch off lamp and set out the wago
def lightButtonOffClicked(self):
#self.lightOffButton.setDown(True)
if self.light_actuator_hwo is not None:
if self.light_actuator_hwo.getState() != STATE_OUT:
if self.motor_hwobj is not None:
try:
self.light_saved_pos=self.motor_hwobj.getPosition()
except:
logging.exception("could not get light actuator position")
self.light_saved_pos=None
if self['out_delta']!="":
delta=float(self['out_delta'])
else:
delta=0.0
light_limits=self.motor_hwobj.getLimits()
self.motor_hwobj.move(light_limits[0]+delta)
self.lightStateChanged(STATE_UNKNOWN)
self.light_actuator_hwo.cmdOut()
else:
self.light_off_button.setDown(True)
### Light on pressed: set in the wago and set lamp to previous position
def lightButtonOnClicked(self):
if self.light_actuator_hwo is not None:
if self.light_actuator_hwo.getState() != STATE_IN:
self.lightStateChanged(STATE_UNKNOWN)
self.light_actuator_hwo.cmdIn()
if self.light_saved_pos is not None and self.motor_hwobj is not None:
self.motor_hwobj.move(self.light_saved_pos)
else:
self.light_on_button.setDown(True)
### Wago light events
def lightStateChanged(self,state):
#print "LightControlBrick.wagoLightStateChanged",state
if state== STATE_IN:
self.light_on_button.setDown(True)
self.light_off_button.setDown(False)
self.move_left_button.setEnabled(True)
self.move_right_button.setEnabled(True)
elif state== STATE_OUT:
self.light_on_button.setDown(False)
self.light_off_button.setDown(True)
self.move_left_button.setEnabled(False)
self.move_right_button.setEnabled(False)
else:
self.light_on_button.setDown(False)
self.light_off_button.setDown(False)
def propertyChanged(self,property,oldValue,newValue):
if property=='light_actuator':
if self.light_actuator_hwo is not None:
self.disconnect(self.light_actuator_hwo,'wagoStateChanged',self.lightStateChanged)
self.light_actuator_hwo=self.getHardwareObject(newValue)
if self.light_actuator_hwo is not None:
self.connect(self.light_actuator_hwo,'wagoStateChanged',self.lightStateChanged)
self.lightStateChanged(self.light_actuator_hwo.getState())
elif property=='icons':
icons_list=newValue.split()
try:
self.light_off_button.setIcon(Qt4_Icons.load_icon(icons_list[0]))
self.light_on_button.setIcon(Qt4_Icons.load_icon(icons_list[1]))
except IndexError:
pass
elif property=='mnemonic':
Qt4_MotorSpinBoxBrick.Qt4_MotorSpinBoxBrick.propertyChanged(self,property,oldValue,newValue)
if self.motor_hwobj is not None:
if self.motor_hwobj.isReady():
limits=self.motor_hwobj.getLimits()
motor_range=float(limits[1]-limits[0])
self['delta']=str(motor_range/10.0)
else:
self['delta']=1.0
else:
Qt4_MotorSpinBoxBrick.Qt4_MotorSpinBoxBrick.propertyChanged(self,property,oldValue,newValue)