-
Notifications
You must be signed in to change notification settings - Fork 9
/
SynopticMotorWPredefinedPositionsBrick.py
139 lines (91 loc) · 4.59 KB
/
SynopticMotorWPredefinedPositionsBrick.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
from qt import *
import SynopticBrick
import MotorBrick
__category__ = 'Synoptic'
class SynopticMotorWPredefinedPositionsBrick(SynopticBrick.SynopticBrick):
def __init__(self, *args):
SynopticBrick.SynopticBrick.__init__.im_func(self, *args)
self.addProperty('mnemonic', 'string', '')
self.addProperty('allow_control', 'boolean', False)
self.addProperty('mode', 'combo', ('expert', 'user'), 'user')
self.motor = None
self.buttons = []
self.expertPanel = QVBox(self.containerBox)
self.motorWidget = MotorBrick.MotorBrick(self.expertPanel)
expertPanelButtonsBox = QGrid(2, Qt.Vertical, self.expertPanel)
QLabel('pos. name :', expertPanelButtonsBox)
self.txtPositionName = QLineEdit(expertPanelButtonsBox)
QLabel('', expertPanelButtonsBox) #just a spacer in fact
self.cmdSetPosition = QPushButton('Set pos.', expertPanelButtonsBox)
self.motorWidget['appearance'] = 'tiny'
self.motorWidget['allowDoubleClick'] = True
expertPanelButtonsBox.setMargin(5)
expertPanelButtonsBox.setSpacing(5)
QObject.connect(self.cmdSetPosition, SIGNAL('clicked()'), self.cmdSetPositionClicked)
def propertyChanged(self, propertyName, oldValue, newValue):
if propertyName == 'mnemonic':
for button in self.buttons:
button.close(True)
self.buttons = []
if self.motor is not None:
self.disconnect(self.motor, PYSIGNAL('stateChanged'), self.motorStateChanged)
self.disconnect(self.motor, PYSIGNAL('newPredefinedPositions'), self.fillPositions)
self.disconnect(self.motor, PYSIGNAL('predefinedPositionChanged'), self.predefinedPositionChanged)
self.motor = self.getHardwareObject(newValue)
if self.motor is not None:
self.motorWidget.setMnemonic(newValue)
self.connect(self.motor, PYSIGNAL('stateChanged'), self.motorStateChanged)
self.connect(self.motor, PYSIGNAL('newPredefinedPositions'), self.fillPositions)
self.connect(self.motor, PYSIGNAL('predefinedPositionChanged'), self.predefinedPositionChanged)
self['title'] = self.motor.userName()
self.fillPositions()
else:
self.motorWidget.setMnemonic('')
elif propertyName == 'mode':
if newValue == 'expert':
self.expertPanel.show()
else:
self.expertPanel.hide()
elif propertyName == 'allow_control':
pass
else:
SynopticBrick.SynopticBrick.propertyChanged.im_func(self, propertyName, oldValue, newValue)
def fillPositions(self):
for button in self.buttons:
button.close(True)
self.buttons = []
for position in self.motor.getPredefinedPositionsList():
newButton = QPushButton(position, self.containerBox)
newButton.installEventFilter(self)
newButton.setMinimumWidth(self.fontMetrics().width('0123456789'))
newButton.setToggleButton(True)
newButton.show()
self.buttons.append(newButton)
if self.motor.isReady():
self.predefinedPositionChanged(self.motor.getCurrentPositionName(), 0)
def eventFilter(self, object, event):
if not event.type() in [QEvent.MouseButtonPress, QEvent.MouseButtonRelease, QEvent.MouseButtonDblClick, QEvent.KeyPress, QEvent.KeyRelease]:
return False
if self['allow_control']:
if object.text() == self.motor.getCurrentPositionName():
return True
self.motor.moveToPosition(str(object.text()))
for button in self.buttons:
button.setOn(False)
return False
else:
return True
def motorStateChanged(self, state):
s = state == self.motor.READY
for button in self.buttons:
button.setEnabled(s)
self.predefinedPositionChanged(self.motor.getCurrentPositionName(), 0)
def predefinedPositionChanged(self, positionName, offset):
for button in self.buttons:
if button.text() == positionName:
button.setOn(True)
else:
button.setOn(False)
def cmdSetPositionClicked(self):
self.motor.setNewPredefinedPosition(str(self.txtPositionName.text()), self.motor.getPosition())
self.fillPositions()