-
Notifications
You must be signed in to change notification settings - Fork 9
/
EquipmentMotorsBrick.py
204 lines (152 loc) · 6.59 KB
/
EquipmentMotorsBrick.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
"""
EquipmentMotorsBrick
[Description]
The EquipmentMotors brick displays the motors found in an Equipment.
[Properties]
-----------------------------------------
| name | type | description
-----------------------------------------
| mnemonic | string | Equipment Hardware Object
| title | string | title to be shown on top of the brick
| formatString | string | format string for motor positions
-----------------------------------------
[Signals]
[Slots]
[HardwareObjects]
Any Equipment-derived Hardware Object can be used with the brick.
Example of a valid Equipment XML file :
=======================================
<equipment>
<username>Slitbox</username>
<motors>
<back>
<device hwrid="/eh2/motors/s2v" role="s2v"/>
<device hwrid="/eh2/motors/t2v" role="t2v"/>
<device hwrid="/eh2/motors/s2h" role="s2h"/>
<device hwrid="/eh2/motors/t2h" role="t2h"/>
</back>
<front>
<device hwrid="/eh2/motors/s1v" role="s1v"/>
<device hwrid="/eh2/motors/t1v" role="t1v"/>
<device hwrid="/eh2/motors/s1h" role="s1h"/>
<device hwrid="/eh2/motors/t1h" role="t1h"/>
</front>
</motors>
</equipment>
"""
from BlissFramework import BaseComponents
from HardwareRepository import HardwareRepository
from BlissFramework.Bricks import MotorBrick
from qt import *
__category__ = ''
class EquipmentMotorsBrick(BaseComponents.BlissWidget):
def __init__(self, *args):
BaseComponents.BlissWidget.__init__(self, *args)
self.panels = {}
self.motors = []
self.hardwareObject = None
self.addProperty('mnemonic', 'string')
self.addProperty('title', 'string', str(self.name()))
self.addProperty('formatString', 'formatString', '+##.####')
#
# create GUI elements
#
self.frame = QFrame(self)
self.lblTitle = QLabel(self)
#
# configure GUI elements
#
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
self.frame.setFrameStyle(QFrame.NoFrame)
self.lblTitle.setText('<nobr><h3>%s</h3></nobr>' % str(self.name()))
#
# layout
#
QHBoxLayout(self.frame, 5, 5)
QVBoxLayout(self, 5, 0)
self.layout().addWidget(self.lblTitle, 0, Qt.AlignTop | Qt.AlignLeft)
self.layout().addWidget(self.frame, 1, Qt.AlignTop | Qt.AlignLeft)
def updateGUI(self):
self.hardwareObject = self.getHardwareObject(self['mnemonic'])
for motor in self.motors:
motor.close()
for panel in self.panels.itervalues():
self.frame.layout().remove(panel)
panel.close()
self.panels = {}
self.motors = []
if self.hardwareObject:
if self.hardwareObject.hasObject('motors'):
ho = self.hardwareObject['motors']
else:
print self.hardwareObject.userName(), 'is not an Equipment : no <motors> section.'
return
for panelName in ho.objectsNames():
newPanel = QWidget(self.frame)
newPanel.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
QVBoxLayout(newPanel, 0, 0)
lbl = QLabel('<b>%s</b>' % panelName, newPanel)
lbl.setAlignment(Qt.AlignCenter)
self.panels[panelName] = newPanel
self.frame.layout().addWidget(newPanel, 0, Qt.AlignTop)
container = QGrid(4, Qt.Vertical, newPanel)
container.setMargin(0)
container.setSpacing(5)
newPanel.layout().addWidget(lbl)
newPanel.layout().addWidget(container)
for motor in ho[panelName].getDevices():
newMotorWidget = MotorBrick.MotorBrick(container, motor.name())
newMotorWidget['mnemonic'] = str(motor.name())
newMotorWidget['formatString'] = self.getProperty('formatString').getUserValue()
newMotorWidget['appearance'] = 'normal'
newMotorWidget['allowConfigure'] = True
self.motors.append(newMotorWidget)
if self.isRunning():
newMotorWidget.run()
newPanel.show()
if len(self.panels) == 0:
#
# object has no sections defined
#
newPanel = QWidget(self.frame)
newPanel.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
QVBoxLayout(newPanel, 5, 5)
self.panels[' '] = newPanel
self.frame.layout().addWidget(newPanel, 0, Qt.AlignTop)
container = QGrid(4, Qt.Vertical, newPanel)
container.setMargin(0)
container.setSpacing(5)
newPanel.layout().addWidget(container)
for motor in ho.getDevices():
newMotorWidget = MotorBrick.MotorBrick(container, motor.name())
newMotorWidget.setMnemonic(motor.name())
newMotorWidget.getProperty('formatString').setValue(self.getProperty('formatString').getUserValue())
newMotorWidget.getProperty('appearance').setValue('normal')
newMotorWidget.getProperty('allowConfigure').setValue(True)
newMotorWidget.readProperties()
self.motors.append(newMotorWidget)
if self.isRunning():
newMotorWidget.run()
newPanel.show()
def setMnemonic(self, mne):
self['mnemonic'] = str(mne)
def propertyChanged(self, propertyName, oldValue, newValue):
if propertyName == 'title':
title = '<nobr><h3>%s</h3></nobr>' % newValue
self.lblTitle.setText(title)
if len(newValue) == 0:
self.lblTitle.hide()
else:
self.lblTitle.show()
elif propertyName == 'showBorder':
if newValue:
self.frame.setMidLineWidth(0)
self.frame.setLineWidth(1)
self.frame.setFrameStyle(QFrame.GroupBoxPanel | QFrame.Sunken)
else:
self.frame.setFrameStyle(QFrame.NoFrame)
elif propertyName == 'formatString':
for motor in self.motors:
motor['formatString'] = newValue
elif propertyName == 'mnemonic':
self.updateGUI()