-
Notifications
You must be signed in to change notification settings - Fork 9
/
MotorListBrick2.py
235 lines (202 loc) · 8.9 KB
/
MotorListBrick2.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
from BlissFramework import BaseComponents
from BlissFramework.Bricks import MotorBrick
from BlissFramework import Icons
from qt import *
import os
import logging
from HardwareRepository.HardwareObjects import SpecMotor
'''
Displays a combo-box with all the motors from spec and opens a
dedicated motor dialog box with the click of a button
'''
__category__ = 'Motor'
class MotorListBrick2(BaseComponents.BlissWidget):
def __init__(self, *args):
BaseComponents.BlissWidget.__init__(self, *args)
self.inExpert=None
self.addProperty('mnemonic','string','')
self.addProperty('icons','string','')
self.addProperty('hideInUser', 'boolean', False)
self.addProperty('disableInUser', 'boolean', False)
self.addProperty('defaultWhenUserDisabled', 'boolean', False)
self.addProperty('showDialogButton', 'boolean', True)
self.addProperty('defaultSpecMotor', 'string', '')
self.addProperty('showBox', 'boolean', True)
self.defineSlot('setEnabled',())
self.defineSignal('specMotorSelected',())
self.containerBox=QHGroupBox('Available motors',self)
self.containerBox.setInsideMargin(4)
self.containerBox.setInsideSpacing(0)
self.motorsList=QComboBox(self.containerBox)
self.motorsList.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
QObject.connect(self.motorsList,SIGNAL('activated(int)'),self.motorSelected)
self.openButton=QToolButton(self.containerBox)
self.openButton.setUsesTextLabel(True)
self.openButton.setTextLabel("Open")
self.openButton.setTextPosition(QToolButton.BesideIcon)
self.connect(self.openButton,SIGNAL('clicked()'),self.openCurrentMotor)
self.openButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
QToolTip.add(self.containerBox,"Lists the available motors")
QToolTip.add(self.openButton,"Opens a dialog box to control the selected motor")
self.motors={}
self.dialogs={}
self.listObj=None
self.instanceSynchronize("motorsList")
QVBoxLayout(self)
self.layout().addWidget(self.containerBox)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
# Open a motor dialog box
def openCurrentMotor(self):
motor_username=str(self.motorsList.currentText())
try:
motor_specname=self.motors[motor_username]
except KeyError:
pass
else:
if motor_username not in self.dialogs:
m=SpecMotor.SpecVersionMotor(self.listObj.getSpecVersion(),motor_specname,motor_username)
dialog=MotorBrick.MotorControlDialog(self,motor_username)
s=self.font().pointSize()
f = dialog.font()
f.setPointSize(s)
dialog.setFont(f)
dialog.motorWidget['fontSize']=s
dialog.updateGeometry()
dialog.setFixedSize(dialog.sizeHint())
dialog.setMotorObject(m)
self.dialogs[motor_username]=dialog
else:
dialog=self.dialogs[motor_username]
dialog.show()
dialog.setActiveWindow()
dialog.raiseW()
def setEnabled(self,state):
override=False
try:
if state and not self.inExpert and self['disableInUser']:
override=True
except:
override=False
if not override:
BaseComponents.BlissWidget.setEnabled(self,state)
def motorSelected(self,motor_index):
motor_username=str(self.motorsList.currentText())
try:
motor_specname=self.motors[motor_username]
except KeyError:
self.emit(PYSIGNAL('specMotorSelected'), (None,None,None))
else:
self.emit(PYSIGNAL('specMotorSelected'), (self.listObj.getSpecVersion(),motor_specname,motor_username))
def run(self):
if self.inExpert is not None:
self.setExpertMode(self.inExpert)
def stop(self):
self.containerBox.show()
def closeAllMotors(self):
for d in self.dialogs:
dialog=self.dialogs[d]
dialog.reject()
self.dialogs={}
def instanceModeChanged(self,mode):
if mode==BaseComponents.BlissWidget.INSTANCE_MODE_SLAVE:
self.closeAllMotors()
# Hide or show the brick
def setExpertMode(self,state):
self.inExpert=state
#print "MotorListBrick.setExpertMode",state
if self['hideInUser']:
if state:
self.containerBox.show()
else:
self.closeAllMotors()
self.containerBox.hide()
if self['disableInUser']:
if state:
self.setEnabled(True)
QToolTip.add(self.containerBox,"Select the motor you desire to control")
else:
self.setEnabled(False)
if self['defaultWhenUserDisabled']:
def_motor=self['defaultSpecMotor']
if def_motor!="":
for m in self.motors:
if self.motors[m]==def_motor:
self.motorsList.setCurrentText(m)
self.motorSelected(self.motorsList.currentItem())
QToolTip.add(self.containerBox,"Only in expert mode you're allowed to change this motor")
def connected(self):
if self.inExpert is not None:
self.setExpertMode(self.inExpert)
def disconnected(self):
if self.inExpert is not None:
self.setExpertMode(self.inExpert)
def motorsChanged(self,specversion,motors):
#print "motorsChanged",specversion,motors
self.motors={}
self.motorsList.clear()
for d in self.dialogs:
self.dialogs[d].accept()
self.dialogs={}
if motors is not None:
motors2={}
for motor_mne in motors:
motors2[motors[motor_mne]]=motor_mne
keys=list(motors2.keys())
keys.sort()
for motor_username in keys:
self.motors[motor_username]=motors2[motor_username]
self.motorsList.insertItem(motor_username)
def_motor=self['defaultSpecMotor']
if def_motor!="":
try:
username=motors[def_motor]
self.motorsList.setCurrentText(username)
except KeyError:
pass
self.motorSelected(self.motorsList.currentItem())
def propertyChanged(self,propertyName,oldValue,newValue):
#print "propertyChanged",propertyName,newValue
if propertyName=='mnemonic':
if self.listObj is not None:
self.disconnect(self.listObj,PYSIGNAL('connected'),self.connected)
self.disconnect(self.listObj,PYSIGNAL('disconnected'),self.disconnected)
self.disconnect(self.listObj,PYSIGNAL('motorListChanged'),self.motorsChanged)
self.listObj=self.getHardwareObject(newValue)
if self.listObj is not None:
self.connect(self.listObj,PYSIGNAL('connected'),self.connected)
self.connect(self.listObj,PYSIGNAL('disconnected'),self.disconnected)
self.connect(self.listObj,PYSIGNAL('motorListChanged'),self.motorsChanged)
if self.listObj.isConnected():
self.connected()
else:
self.disconnected()
self.motorsChanged(self.listObj.getSpecVersion(),self.listObj.getMotorList())
else:
self.disconnected()
self.motorsChanged(None,None)
elif propertyName=='icons':
icons_list=newValue.split()
try:
self.openButton.setPixmap(Icons.load(icons_list[0]))
self.motorsList.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
self.openButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
except IndexError:
pass
elif propertyName=='showDialogButton':
if newValue:
self.openButton.show()
else:
self.openButton.hide()
elif propertyName=='showBox':
if newValue:
self.containerBox.setFrameShape(self.containerBox.GroupBoxPanel)
self.containerBox.setInsideMargin(4)
self.containerBox.setInsideSpacing(0)
self.containerBox.setTitle("Available motors")
else:
self.containerBox.setFrameShape(self.containerBox.NoFrame)
self.containerBox.setInsideMargin(0)
self.containerBox.setInsideSpacing(0)
self.containerBox.setTitle("")
else:
BaseComponents.BlissWidget.propertyChanged(self,propertyName,oldValue,newValue)