-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestsWidgets.py
285 lines (246 loc) · 10.7 KB
/
TestsWidgets.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# !/usr/bin/env python
# coding:utf-8
"""
:Author: Sonia Karkar -- karkar@in2p3.fr
:What: Widgets for the tests to be used in TestStucture
"""
from PyQt4 import QtGui, QtCore
import ShowResult
import ressources
from qtUtils import WidgetTimer, centerOnScreen, BlinkingInputDialog
# import analyseL0PedScan
import os
import subprocess
import TakeDataTest1
from TestStucture import ShowTestResult
from LogUtils import MyLog
if __name__ == "__main__":
logname = os.path.basename(__file__)[:-3]
else:
logname = __name__
if len(logname) > 20:
logname = logname[:9] + "--" + logname[-9:]
log = MyLog(logname, qt=True, logdir=os.getenv("HOME") + "/log/")
import logging
# log.setLevel(logging.DEBUG)
def CreateWidgetLabel(widget):
"""
* This function takes a widget and adds to it a QGridLayout.
* Then it adds a QLabel as a first element to that layout.
* The QLabel text is set to the name of the widget class.
* It returns the QLabel and the QGridLayout
"""
instructionLabel = QtGui.QLabel(widget)
log.debug("instructionLabel {}".format(instructionLabel))
instructionLabel.setText(
"This is the test " + str(type(widget).__name__))
instructionLabel.setStyleSheet('padding: 5px; border-radius: 20px')
grid = QtGui.QGridLayout()
log.debug("grid {}".format(grid))
grid.addWidget(instructionLabel, 0, 1)
widget.setLayout(grid)
return instructionLabel, grid
class Test0(QtGui.QWidget):
"""
Widget used by TestStucture.py as part of the MainWindow.
The Run() method of this widget ask the user to enter some input
that will be used.
As an exemple, this input could be the serial number of the item under test
read from a QR code
"""
done = QtCore.pyqtSignal()
QRCode = QtCore.pyqtSignal(QtCore.QString)
def __init__(self, parent):
super(Test0, self).__init__(parent)
log.debug("creating widget " + str(type(self).__name__))
log.debug("parent {}".format(parent))
self.myWin = parent
self.itest = self.myWin.testsList.index("Test0")
log.debug("self.myWin {}".format(self.myWin))
self.done.connect(lambda: ShowTestResult(parent, self.itest))
log.debug("just connected self.done {}".format(self.done))
self.initUI()
def initUI(self):
log.debug("initUI Widget" + str(type(self).__name__))
self.instructionLabel, self.Gridlayout = CreateWidgetLabel(self)
self.timer = WidgetTimer("in " + logname + str(type(self).__name__))
self.Gridlayout.addWidget(self.timer)
self.imageLabel = QtGui.QLabel()
self.imageLabel.setPixmap(QtGui.QPixmap(":/images/ScanFeb.jpg"))
self.dialog = BlinkingInputDialog()
self.dialog.startBlink(color1=QtGui.QColor(188, 16, 16),
color2=QtGui.QColor(229, 131, 2))
self.dialog.setWindowTitle(str(type(self).__name__))
centerOnScreen(self.dialog)
self.dialog.setLabelText("Please enter some input")
self.dialog.setOkButtonText("Use this input")
layout = self.dialog.layout()
layout.addWidget(self.imageLabel)
self.dialog.accepted.connect(self.mybuttonClicked)
def Run(self):
try:
self.timer.start()
self.dialog.exec_()
log.debug("{} is ready ".format(self))
log.info("waiting for Feb to be scanned")
except Exception as err:
mymsg = ("{}".format(err.args[0]))
log.error(mymsg)
self.SafeExit()
raise
def mybuttonClicked(self):
log.debug("in buttonClicked self.done {}".format(self.done))
self.QRCodefield = str(self.dialog.textValue())
log.debug("self.QRCodefield {}".format(self.QRCodefield))
duration = self.timer.stop()
log.debug("this test took {} ".format(duration))
self.myWin.TestTimers[self.itest] = duration
self.done.emit()
def giveObjectTestedNumber(self):
"""uses the qt signal/slot mechanism to communicate across threads"""
self.QRCode.emit(QtCore.QString(self.QRCodefield))
def SafeExit(self):
"""Does whatever needs to be done with the testbench to exit safely
an exemple is to turn off the power supply
and disconnect from all instruments"""
pass
class Test1(QtGui.QWidget):
done = QtCore.pyqtSignal()
datadir = QtCore.pyqtSignal(QtCore.QString)
def __init__(self, parent):
super(Test1, self).__init__(parent)
log.debug("creating widget " + str(type(self).__name__))
self.myWin = parent
self.itest = self.myWin.testsList.index(str(type(self).__name__))
# link with the next operation: result of this test
self.done.connect(lambda: ShowTestResult(parent, self.itest))
log.debug("self.datadir {}".format(self.datadir))
self.initUI()
def initUI(self):
log.debug("initUI Widget" + str(type(self).__name__))
self.instructionLabel, self.layout = CreateWidgetLabel(self)
self.timer = WidgetTimer("in " + logname + str(type(self).__name__))
self.layout.addWidget(self.timer)
def Run(self):
try:
self.timer.start()
log.debug("should be doing test " + str(type(self).__name__))
log.info(str(type(self).__name__) + " Test starting")
# Prevent stopping the test while connecting to instruments
self.myWin.tabs.widget(
self.itest).StopThisTestBtn.setEnabled(False)
self.myWin.ObjectTested.prepareForTest1()
# allow stopping while in main loop
self.myWin.tabs.widget(self.itest).StopThisTestBtn.setEnabled(True)
self.myWin.ObjectTested.mainTest1Loop()
# prevent stopping while cleaning connections
self.myWin.tabs.widget(
self.itest).StopThisTestBtn.setEnabled(False)
self.Test1datadir = self.myWin.ObjectTested.cleanAfterTest1()
log.info("Test1 Data in {} ".format(self.Test1datadir))
duration = self.timer.stop()
log.debug("this test took {} ".format(duration))
self.myWin.TestTimers[self.itest] = duration
self.done.emit()
except Exception as err:
mymsg = ("{}".format(err.args[0]))
log.error(mymsg)
self.SafeExit()
raise
def giveDatadir(self):
self.datadir.emit(QtCore.QString(self.Test1datadir))
def SafeExit(self):
pass
class Test3(QtGui.QWidget):
done = QtCore.pyqtSignal()
def __init__(self, parent):
super(Test3, self).__init__(parent)
log.debug("creating widget " + str(type(self).__name__))
self.myWin = parent
self.itest = self.myWin.testsList.index(str(type(self).__name__))
# link with the next operation: result of this test
self.done.connect(lambda: ShowTestResult(parent, self.itest))
self.initUI()
def getDiagBackColor(self):
return self.dialog.palette().color(QtGui.QPalette.Background)
def setDiagBackColor(self, color):
pal = self.dialog.palette()
pal.setColor(QtGui.QPalette.Background, color)
self.dialog.setPalette(pal)
def initUI(self):
log.debug("initUI Widget" + str(type(self).__name__))
self.instructionLabel, self.layout = CreateWidgetLabel(self)
self.timer = WidgetTimer("in " + logname + str(type(self).__name__))
self.layout.addWidget(self.timer, 0, 0)
self.imageLabel2 = QtGui.QLabel()
self.imageLabel2.setPixmap(
QtGui.QPixmap(":/images/DisConnectSignal.png"))
self.imageLabel2.setScaledContents(True)
self.imageLabel2.setMaximumSize(600, 300)
self.layout.addWidget(self.imageLabel2, 1, 0)
self.imageLabel = QtGui.QLabel()
self.imageLabel.setPixmap(
QtGui.QPixmap(":/images/ConnectHVPA.png"))
self.imageLabel.setScaledContents(True)
self.imageLabel.setMaximumSize(600, 300)
self.layout.addWidget(self.imageLabel, 1, 1)
self.dialog = QtGui.QMessageBox(self)
self.dialog.setIcon(QtGui.QMessageBox.Warning)
self.dialog.setWindowTitle(str(type(self).__name__))
self.dialog.setText("Please (1) disconnet the injection board \n"
+ "then (2) connect the HVPA test board \n"
+ " and THEN click OK to continue")
self.dialog.setStandardButtons(QtGui.QMessageBox.Ok)
# HVPAfilename = ":/images/ConnectHVPA.png"
# image = QtGui.QImage(HVPAfilename)
# self.imageLabel = QtGui.QLabel()
# self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))
# # diaglayout = QtGui.QVBoxLayout()
# diaglayout = self.dialog.layout()
# diaglayout.addWidget(self.imageLabel)
# # self.dialog.setLayout(diaglayout)
geom = self.dialog.geometry()
geom.moveCenter(self.myWin.frameGeometry().center())
# TODO this is what should work to center the message but fails
# self.mydialog.move(geom.topLeft())
# this is the closest to center i've managed to reach
self.dialog.move(geom.center())
# this doesnt seem to work with standard button
# self.mydialog.setButtonText(int, QString)
self.dialog.setWindowModality(QtCore.Qt.ApplicationModal)
log.debug("self.mydialog.buttonClicked {}".format(
self.dialog.buttonClicked))
self.dialog.buttonClicked.connect(self.Finish)
color1 = QtGui.QColor(188, 16, 16)
color2 = QtGui.QColor(229, 131, 2)
self.color_anim = QtCore.QPropertyAnimation(self, 'DialogBackColor')
self.color_anim.setStartValue(color2)
self.color_anim.setKeyValueAt(0.3, color1)
self.color_anim.setEndValue(color1)
self.color_anim.setDuration(800)
self.color_anim.setLoopCount(-1)
self.color_anim.start()
def Run(self):
try:
# before anything turn off power supply
self.myWin.PS.AllOFF()
self.timer.start()
log.debug("should be doing test " + str(type(self).__name__))
log.info(str(type(self).__name__) + " Test starting")
# allow stopping the test
self.myWin.tabs.widget(self.itest).StopThisTestBtn.setEnabled(True)
self.dialog.exec_()
except Exception as err:
mymsg = ("{}".format(err.args[0]))
log.error(mymsg)
self.SafeExit()
raise
def Finish(self):
duration = self.timer.stop()
log.debug("this test took {} ".format(duration))
self.myWin.TestTimers[self.itest] = duration
self.done.emit()
def SafeExit(self):
pass
DialogBackColor = QtCore.pyqtProperty(
QtGui.QColor, getDiagBackColor, setDiagBackColor)