-
Notifications
You must be signed in to change notification settings - Fork 9
/
SynopticEquipmentMotorsBrick.py
133 lines (87 loc) · 4.74 KB
/
SynopticEquipmentMotorsBrick.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
import logging
from qt import *
import MotorBrick
import SynopticBrick
__category__ = 'Synoptic'
class VerticalSpacer(QWidget):
def __init__(self, *args):
QWidget.__init__(self, *args)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
class SynopticEquipmentMotorsBrick(SynopticBrick.SynopticBrick):
def __init__(self, *args):
SynopticBrick.SynopticBrick.__init__.im_func(self, *args)
self.motors = {}
self.hardwareObject = None
self.addProperty('mnemonic', 'string')
self.addProperty('allowControl', 'boolean', True)
self.addProperty('formatString', 'formatString', '+##.####')
self.addProperty('displayMode', 'combo', ('tabs', 'list'), 'list')
self.motorPanel = QVBox(self.containerBox)
def setMnemonic(self, mne):
self['mnemonic'] = mne
def propertyChanged(self, propertyName, oldValue, newValue):
if propertyName == 'mnemonic':
self.hardwareObject = self.getHardwareObject(newValue)
if len(self['title']) == 0:
if self.hardwareObject is None:
self['title'] = ''
else:
self['title'] = self.hardwareObject.userName()+' :'
self.showMotors(self['displayMode'])
elif propertyName == 'allowControl':
for motor in self.motors.itervalues():
motor['allowDoubleClick'] = newValue
elif propertyName == 'formatString':
for motor in self.motors.itervalues():
motor['formatString'] = newValue
elif propertyName == 'displayMode':
self.showMotors(newValue)
else:
SynopticBrick.SynopticBrick.propertyChanged.im_func(self, propertyName, oldValue, newValue)
def showMotors(self, displayMode):
self.motors = {}
self.motorPanel.close(True) #destroy motor panel
self.motorPanel = QVBox(self.containerBox)
if self.hardwareObject is None:
return
else:
if self.hardwareObject.hasObject('motors'):
#an equipment should have a 'motors' section
motors = self.hardwareObject['motors']
else:
logging.getLogger().warning('Equipment %s does not have motors', self.hardwareObject.userName())
if displayMode == 'tabs':
self.motorPanel.close(True)
self.motorPanel = QTabWidget(self.containerBox)
for motorCategory in motors.objectsNames():
motorTab = QVBox(self.motorPanel)
self.motorPanel.addTab(motorTab, motorCategory)
for motor in motors[motorCategory].getDevices():
newMotorWidget = MotorBrick.MotorBrick(motorTab, motor.name())
self.motors[motor.name()] = newMotorWidget
newMotorWidget.getProperty('mnemonic').setValue(str(motor.name())) #['mnemonic'] = str(motor.name())
newMotorWidget.getProperty('appearance').setValue('tiny')
newMotorWidget.getProperty('formatString').setValue(self.getProperty('formatString').getUserValue())
newMotorWidget.getProperty('allowConfigure').setValue(True)
newMotorWidget.getProperty('allowDoubleClick').setValue(self['allowControl'])
newMotorWidget.getProperty('dialogCaption').setValue("%s [%s] - %s" % (self['title'], motorCategory, motor.userName()))
newMotorWidget.readProperties()
if self.isRunning():
newMotorWidget.run()
newMotorWidget.show()
VerticalSpacer(motorTab)
else:
for motor in motors.getDevices():
newMotorWidget = MotorBrick.MotorBrick(self.motorPanel, motor.name())
self.motors[motor.name()] = newMotorWidget
#newMotorWidget['mnemonic'] = str(motor.name())
newMotorWidget.getProperty('mnemonic').setValue(str(motor.name()))
newMotorWidget.getProperty('appearance').setValue('tiny')
newMotorWidget.getProperty('formatString').setValue(self.getProperty('formatString').getUserValue())
newMotorWidget.getProperty('allowConfigure').setValue(True)
newMotorWidget.getProperty('allowDoubleClick').setValue(self['allowControl'])
newMotorWidget.readProperties()
if self.isRunning():
newMotorWidget.run()
newMotorWidget.show()
self.motorPanel.show()