-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSE1FanProgrammer.pyw
845 lines (685 loc) · 34.9 KB
/
SE1FanProgrammer.pyw
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# -*- coding: utf-8 -*-
###############################################################################
# (c) 2016 Schneider Electric SE. All rights reserved.
# All trademarks are owned or licensed by Schneider Electric SE,
# its subsidiaries or affiliated companies.
#
# FILE NAME: SE1FanProgrammer.pyw
#
# PURPOSE:
# This program is used to program the fans in SE1 during manufacturing.
# It uses the pyqt GUI framework.
#
#
# FUNCTION(S):
#
# local:
#
# NOTES:
#
# CHANGE HISTORY :
# 0.0.1 Dec2016 Francis Kwok - Created
#
##############################################################################
###############################################################################
# Includes
###############################################################################
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import qrc_resources
import sys
import platform
import copy
import SE1FanProgrammerTest
import time
import re
import ctypes
myappid = u'schneider-electric.fan.programmer' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
###############################################################################
# Logging Module Setup
###############################################################################
# It's something I don't understand.... We have to leave logging not imported
# to see the logging and print messages from the threads in the text window...
#
# import logging
# if __name__ == "__main__":
# logging.basicConfig(level=logging.DEBUG)
###############################################################################
# Constant Data
###############################################################################
__version__ = "x.x.x"
SERNUM_PATT = re.compile('^(\\d\\d)([0-5][0-9])00([A-Z0-9]{4})')
SERNUM_INIT_STATUS = 'Please enter valid serial number:'
###############################################################################
# Function/Class Definitions
###############################################################################
## Class providing a table to display the test results.
class ResultsTable(QTableWidget):
"""
Class providing a table to display the test results. Sub-classed from a QTableWidget.
"""
## Object Constructor
def __init__(self, parent = None):
"""
Constructor
"""
super(ResultsTable, self).__init__()
self.dictTestItems = {}
def fnResetforNewTest(self):
self.dictTestItems = {}
self.clearContents()
## Checks if results table has changed
## @param self The object pointer.
## @param newtabledict The dictionary received from the script.
def setTableDictionary(self, newtabledict):
"""Checks if the results table had changed. If it has, then emit the TableDictChanged signal"""
if newtabledict != self.dictTestItems:
self.dictTestItems = copy.deepcopy(newtabledict) #need deep copy for future compares to work
self.emit(SIGNAL("TableDictChanged"))
## Refresh the results table
## @param self The object pointer.
def fnRefreshTable(self):
"""Used to refresh the results table contents when there was a change"""
self.clear()
self.setRowCount(len(self.dictTestItems))
self.setColumnCount(8)
HorizontalHeaders = QStringList(["TCID", "Min", "Max", "Description", "Type", "Prop", "Meas", "Result"])
self.setHorizontalHeaderLabels(HorizontalHeaders)
row = 0
for entry in sorted(self.dictTestItems.keys()):
self.setItem(row, 0, QTableWidgetItem(self.dictTestItems[entry]['TCID']))
self.setItem(row, 1, QTableWidgetItem(self.dictTestItems[entry]['Min']))
self.setItem(row, 2, QTableWidgetItem(self.dictTestItems[entry]['Max']))
self.setItem(row, 3, QTableWidgetItem(self.dictTestItems[entry]['Descript']))
self.setItem(row, 4, QTableWidgetItem(self.dictTestItems[entry]['Type']))
self.setItem(row, 5, QTableWidgetItem(self.dictTestItems[entry]['Prop']))
self.setItem(row, 6, QTableWidgetItem(str(self.dictTestItems[entry]['Meas'])))
if self.dictTestItems[entry]['Result'] == 'Pass':
item = QTableWidgetItem('Pass')
item.setBackground(QColor(0x00,0x95,0x30))
elif self.dictTestItems[entry]['Result'] == 'FAIL':
item = QTableWidgetItem('FAIL')
item.setBackgroundColor(QColor(0xF9,0x42,0x3A))
else:
item = QTableWidgetItem('')
#item.setBackgroundColor(QColor(0xFF,0xD1,0x00)) #maybe do this on last pass..
self.setItem(row, 7, item )
row = row + 1
self.resizeColumnsToContents()
self.resizeRowsToContents()
self.horizontalHeader().setStretchLastSection(True)
class COMCfgDialog(QDialog):
def __init__(self, parent = None):
#Don't want the Help Icon...
super(COMCfgDialog, self).__init__(parent, Qt.WindowSystemMenuHint | Qt.WindowTitleHint)
self.settings = QSettings()
########Modbus COMM PORTS########
self.FanMBPortGroupBox = QGroupBox("")
self.FanMBPortCliQLabel = QLabel("Fan Modbus Port:")
self.FanMBPortLineEdit = QLineEdit()
self.FanMBPortGridLayout = QGridLayout()
self.FanMBPortGridLayout.addWidget(self.FanMBPortCliQLabel,0,0,)
self.FanMBPortGridLayout.addWidget(self.FanMBPortLineEdit,0,1,)
self.FanMBPortGroupBox.setLayout(self.FanMBPortGridLayout)
########Save/Restore Buttons########
self.SaveButton = QPushButton("Save")
self.RestoreButton = QPushButton("Restore")
buttonlayout = QHBoxLayout()
buttonlayout.addWidget(self.RestoreButton)
buttonlayout.addWidget(self.SaveButton)
self.ButtonGroupBox = QGroupBox("")
self.ButtonGroupBox.setLayout(buttonlayout)
v1layout = QVBoxLayout()
v1layout.addWidget(self.FanMBPortGroupBox)
v1layout.addWidget(self.ButtonGroupBox)
v1layout.addStretch()
layout = QHBoxLayout()
layout.addLayout(v1layout)
layout.setSizeConstraint(QLayout.SetFixedSize)
self.setLayout(layout)
self.setWindowTitle("COM Port Configuration")
#self.setFixedSize(self.frameGeometry().width(),self.frameGeometry().height())
#self.setFixedSize(self.sizeHint())
self.connect(self.SaveButton, SIGNAL("clicked()"), self.fnSaveCurrentSettings)
self.connect(self.RestoreButton, SIGNAL("clicked()"), self.fnRestoreSettings)
self.fnRestoreSettings()
def fnRestoreSettings(self):
self.FanMBPortLineEdit.setText(self.settings.value("fan/mb_comm").toString())
def fnSaveCurrentSettings(self):
self.settings.setValue("fan/mb_comm", self.FanMBPortLineEdit.text())
self.close()
def closeEvent(self, event):
if self.fnValidSavedCommSettings():
event.accept()
else:
event.ignore()
def fnDisplayError(self, str):
ErrorMessageBox = QMessageBox()
newfont = QFont()
newfont.setPointSize(10)
ErrorMessageBox.setFont(newfont)
ErrorMessageBox.setIcon(QMessageBox.Warning)
ErrorMessageBox.setWindowTitle("Error")
ErrorMessageBox.setText(str)
ErrorMessageBox.exec_()
def fnValidSavedCommSettings(self):
commpatt = re.compile('com[0-9]+', re.IGNORECASE)
returnvalue = True
lstCommPorts = ["fan/mb_comm"]
for port in lstCommPorts:
if commpatt.match(self.settings.value(port).toString()):
pass
else:
returnvalue = False
self.fnDisplayError("Saved port for " + port + " is not formated correctly. Format should 'com1' or 'COM1'")
return returnvalue
class Logger(QObject):
printSig = pyqtSignal(QString)
clearSig = pyqtSignal()
def __init__(self):
QObject.__init__(self)
self.stdout = sys.stdout
self.count = 0
def write(self, text):
if self.count > 200:
self.clearSig.emit()
self.count = 0
self.printSig.emit(text)
self.count = self.count+1
def close(self):
self.stdout.close()
## Class that creates the Main Window for the application
class MainWindow(QMainWindow):
"""Class that creates the Main Window for the application. Subclasses from QMainWindow."""
# GREEN2: #009530 SE Spruce Green
# GREY6: #262E38 SE Dark Grey
# GREY11: #404A54 SE Light Grey
# GREY1: #C5C7C4 SE Ultra Light Grey
# RED1: #F9423A SE Red
# YELLOW1: #FFD100 SE Yellow
## Object Constructor
## @param self The object pointer.
## @param parent Widget parent if any
def __init__(self, parent = None, logger = None):
super(MainWindow, self).__init__(parent)
self.setStyleSheet("""QMenuBar { background-color: #009530 }
QMenuBar::item { color: #FFFFFF;
background-color: transparent;
}
QMenuBar::item:selected { border: 1px solid #FFFFFF;
border-radius: 3px;
}
QMenu { color: #000000;
background-color: #FFFFFF;
font-family: "Arial Rounded MT", Arial, Helvetica, sans-serif;
}
QMenu::item:selected { color: #FFFFFF;
background-color: #262E38;
}
QPushButton::checked {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #262E38, stop: 1 #404A54);
color: #FFFFFF;
border: 2px solid #009530;
border-radius: 2px;
}
QPushButton::pressed {
background-color: qlineargradient(x1: 0,
y1: 0,
x2: 0,
y2: 1,
stop: 0 #262E38,
stop: 1 #404A54);
color: #FFFFFF;
border-color:#009530;
border-radius: 2px;
border-style: solid;
border-radius: 2px;
}
""");
self.logger = logger
#Setup the Window Title
self.setWindowTitle("SE1 Fan Programmer")
#Create Log Dock Widget
logDockWidget = QDockWidget("Toggle Log View", self)
logDockWidget.setObjectName("LogDockWidget")
logDockWidget.setAllowedAreas(Qt.NoDockWidgetArea)
logDockWidget.setFloating(True)
logDockWidget.close()
self.textDisplayArea = QTextEdit()
self.textDisplayArea.setLineWrapMode(QTextEdit.NoWrap)
self.textDisplayArea.setReadOnly(True)
font = QFont('Consolas')
font.setStyleHint(QFont.TypeWriter)
font.setPointSize(9)
self.textDisplayArea.setFont(font)
logDockWidget.setWidget(self.textDisplayArea)
self.addDockWidget(Qt.BottomDockWidgetArea, logDockWidget)
#Create status bar
self.status = self.statusBar()
self.status.showMessage("Ready")
#Create actions
#Note: that is creates the connections too...
helpAboutAction = self.createAction("&About...", slot = self.helpAbout, icon = "help.ico")
toggleLogWindowAction = logDockWidget.toggleViewAction() #Class has helper to create an Action for us.
toggleLogWindowAction.setIcon(QIcon(":/openbook.ico"))
commSettingsAction = self.createAction("COM Settings", slot = self.fnOpenCOMCfgDialog, icon = "serial.ico")
quitAction = self.createAction("E&xit", slot = qApp.quit, icon = "close.ico" )
saveTableAction = self.createAction("Save Table as CSV", slot = self.fnSaveTableCsv, icon = "save.ico")
saveLogAction = self.createAction("Save Log to File", slot = self.fnSaveLog, icon = "book.ico")
#Create Menu
fileMenu = self.menuBar().addMenu("&File")
editMenu = self.menuBar().addMenu("Edit")
helpMenu = self.menuBar().addMenu("&Help")
#Help Menu
self.addActions(helpMenu, (helpAboutAction, None))
#Edit Menu
self.addActions(editMenu, (commSettingsAction, None))
#File Menu
self.addActions(fileMenu, (toggleLogWindowAction, saveLogAction, saveTableAction, quitAction, None))
#Draw the widgets....
self.fnDrawTestControlsWidgets()
self.fnDrawUUTSerWidgets()
self.fnDrawFan1Widgets()
self.fnDrawFan2Widgets()
self.fnDrawFan3Widgets()
#Create the table widget
self.TableWidget = ResultsTable()
# Main layout
layout = QVBoxLayout()
layout.addWidget(self.TestControlsGroupBox)
layout.addWidget(self.UUTSerGroupBox)
layout.addWidget(self.Fan1GroupBox)
layout.addWidget(self.Fan2GroupBox)
layout.addWidget(self.Fan3GroupBox)
layout.addWidget(self.TableWidget)
#layout.addStretch()
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
#Create the the test thread
self.TestThread = SE1FanProgrammerTest.TestScript()
self.lock = QReadWriteLock()
#Update Test Info Timer
self.TestInfoTimer = QTimer()
self.TestInfoTimer.setSingleShot(False)
self.TestInfoTimer.setInterval(1000) #1 second refresh
#Make connections
#Logger Related Connections...
self.connect(self.logger, SIGNAL("printSig(QString)"), self.fnAppend)
#The logger class sends a clearSig after 200 chars.
#self.connect(self.logger, SIGNAL("clearSig()"), self.fnClearLogger)
self.connect(self.TestThread, SIGNAL("started()"), self.TestInfoTimer, SLOT("start()"))
self.connect(self.TestThread, SIGNAL("finished()"), self.TestInfoTimer, SLOT("stop()") )
self.connect(self.TestInfoTimer, SIGNAL("timeout()"), self.fnUpdateTestInformation)
self.connect(self.TableWidget, SIGNAL("TableDictChanged"), self.TableWidget.fnRefreshTable )
self.connect(self.StartButton, SIGNAL("clicked()"), self.fnRunScript)
self.connect(self.TestThread, SIGNAL("Exception(QString)"), self.fnDisplayError)
self.connect(self.TestThread, SIGNAL("FinishPending"), self.fnUpdateTestInformation)
self.connect(self.TestThread, SIGNAL("FinishPending"), self.fnTestDone)
self.connect(self.ClearButton, SIGNAL("clicked()"), self.fnClearForm)
self.connect(self.BL601ProgEnableButton, SIGNAL("clicked()"),
lambda grpbox = self.Fan1GroupBox : self.fnCheckSerialNumber(grpbox))
self.connect(self.BL602ProgEnableButton, SIGNAL("clicked()"),
lambda grpbox = self.Fan2GroupBox : self.fnCheckSerialNumber(grpbox))
self.connect(self.BL603ProgEnableButton, SIGNAL("clicked()"),
lambda grpbox = self.Fan3GroupBox : self.fnCheckSerialNumber(grpbox))
self.connect(self.AbortButton, SIGNAL("clicked()"), self.TestThread.fnSetAbortFlag)
#Setup the Settings so it saves and restores last settings
self.settings = QSettings()
size = self.settings.value("MainWindow/Size", QVariant(QSize(300, 100))).toSize()
self.resize(size)
position = self.settings.value("MainWindow/Position", QVariant(QPoint(0, 0))).toPoint()
self.move(position)
self.restoreState(self.settings.value("MainWindow/State").toByteArray())
def fnClearForm(self):
self.BL601LineEdit.setText("")
self.BL602LineEdit.setText("")
self.BL603LineEdit.setText("")
self.BL601LineEdit.setEnabled(True)
self.BL602LineEdit.setEnabled(True)
self.BL603LineEdit.setEnabled(True)
self.BL601ProgEnableButton.setChecked(False)
self.BL602ProgEnableButton.setChecked(False)
self.BL603ProgEnableButton.setChecked(False)
self.Fan1GroupBox.setTitle(self.Fan1GroupBox.prefix + SERNUM_INIT_STATUS)
self.Fan2GroupBox.setTitle(self.Fan2GroupBox.prefix + SERNUM_INIT_STATUS)
self.Fan3GroupBox.setTitle(self.Fan3GroupBox.prefix + SERNUM_INIT_STATUS)
self.TableWidget.fnResetforNewTest()
self.PassFailLabel.setText("")
self.UUTSerLineEdit("")
self.fnClearLogger()
def fnCheckSerialNumber(self, grpbox):
if grpbox.buttonref.isChecked():
#print 'pressed'
entered_sn = str(grpbox.lineref.text())
#Barcode scanned
if len(entered_sn) > 20:
entered_sn = entered_sn[9:]
#print entered_sn
matchObj = SERNUM_PATT.match(entered_sn)
if matchObj:
year_dec = matchObj.group(1)
year_full = '20' + year_dec
mth_dec = matchObj.group(2)
seq_ascii = matchObj.group(3)
dictseradd = {}
dictseradd['serialnum'] = matchObj.group(0)
dictseradd['year_hex'] = format(int(year_dec), 'x').zfill(2).upper()
dictseradd['mth_hex'] = format(int(mth_dec), 'x').zfill(2).upper()
dictseradd['seq_hex1'] = format(ord(seq_ascii[0:1]), 'x').zfill(2).upper()
dictseradd['seq_hex2'] = format(ord(seq_ascii[1:2]), 'x').zfill(2).upper()
dictseradd['seq_hex3'] = format(ord(seq_ascii[2:3]), 'x').zfill(2).upper()
dictseradd['seq_hex4'] = format(ord(seq_ascii[3:4]), 'x').zfill(2).upper()
dictseradd['full_add'] = "{} {} {} {} {} {}".format(dictseradd['year_hex'],
dictseradd['mth_hex'],
dictseradd['seq_hex1'],
dictseradd['seq_hex2'],
dictseradd['seq_hex3'],
dictseradd['seq_hex4'])
grpbox.lineref.setEnabled(False)
grpbox.setTitle(grpbox.prefix +
"Year Code:" +
year_full +
" Week Code:" +
mth_dec +
" Seq Num:" +
seq_ascii)
grpbox.dictadd = dictseradd
else:
#did not match reg-ex, bring button back up
grpbox.buttonref.setChecked(False)
grpbox.setTitle(grpbox.prefix + SERNUM_INIT_STATUS)
else:
#Button got un-pressed, re-enable the line input box
grpbox.lineref.setEnabled(True)
grpbox.setTitle(grpbox.prefix + SERNUM_INIT_STATUS)
def fnSaveLog(self):
default_fileName = time.strftime("%Y%m%d-%H%M%S") + '.log'
fileName = QFileDialog.getSaveFileName(self, 'Save Results Table to...',
'./DebugLogs/{}'.format(default_fileName),
"log files (*.log);;All Files (*)")
if fileName:
#print fileName
f = open(fileName,"w") #opens file with name of "test.txt"
f.write(self.textDisplayArea.toPlainText())
f.close()
def fnSaveTableCsv(self):
if len(self.UUTSerLineEdit.text()) == 0:
default_fileName = time.strftime("%Y%m%d-%H%M%S") + '.csv'
else:
default_fileName = self.UUTSerLineEdit.text() + '.csv'
fileName = QFileDialog.getSaveFileName(self, 'Save Results Table to...',
'./TestResults/{}'.format(default_fileName),
"CSV files (*.csv);;All Files (*)")
if fileName:
#print fileName
#Check if there is already a file with the same name.
#if os.path.exists(fileName):
# print 'Choose a different file name'
self.TestThread.testcontroller.fnWriteToCsv(fileName)
def fnOpenCOMCfgDialog(self):
#Create COMCfgDialog
self.commcfgdialog = COMCfgDialog()
self.commcfgdialog.exec_()
def fnRunScript(self):
self.PassFailLabel.setText("")
self.TableWidget.fnResetforNewTest()
self.textDisplayArea.clear()
self.StartButton.setEnabled(False)
self.ClearButton.setEnabled(False)
self.AbortButton.setEnabled(True)
self.TestThread.dictTestSelection = self.fnGetTestSelection()
self.TestThread.start()
def fnGetTestSelection(self):
#TestSelectionButtonsStruct
dictTestSelection = {}
dictTestSelection['boolRunFan1'] = self.BL601ProgEnableButton.isChecked()
dictTestSelection['dictSerFan1'] = self.Fan1GroupBox.dictadd
dictTestSelection['boolRunFan2'] = self.BL602ProgEnableButton.isChecked()
dictTestSelection['dictSerFan2'] = self.Fan2GroupBox.dictadd
dictTestSelection['boolRunFan3'] = self.BL603ProgEnableButton.isChecked()
dictTestSelection['dictSerFan3'] = self.Fan3GroupBox.dictadd
return dictTestSelection
def fnUpdateTestInformation(self):
TestStatus = None
TestInfomation = None
self.lock.lockForRead()
try:
TestStatus = self.TestThread.fnGetTestStatus()
TestInfomation = self.TestThread.testcontroller.PassCurrentStatus()
except AttributeError:
pass #object wasn't created yet.
self.lock.unlock()
#Update Table
if TestInfomation:
self.TableWidget.setTableDictionary(TestInfomation)
#Update Status Message
if TestStatus:
if TestStatus == SE1FanProgrammerTest.STATUS_STARTING_TEST:
self.PassFailLabel.setText("<h1>Starting up the program...</h1>")
elif TestStatus == SE1FanProgrammerTest.STATUS_FAN1_RUNNING:
self.PassFailLabel.setText("<h1>Programming FAN1...</h1>")
elif TestStatus == SE1FanProgrammerTest.STATUS_FAN2_RUNNING:
self.PassFailLabel.setText("<h1>Programming FAN2...</h1>")
elif TestStatus == SE1FanProgrammerTest.STATUS_FAN3_RUNNING:
self.PassFailLabel.setText("<h1>Programming FAN3...</h1>")
elif TestStatus == SE1FanProgrammerTest.STATUS_ABORTING_TEST:
self.PassFailLabel.setText("<h1>Aborting Pending... Finishing this fan...</h1>")
def fnTestDone(self):
time.sleep(0.5)
self.StartButton.setEnabled(True)
self.ClearButton.setEnabled(True)
self.AbortButton.setEnabled(False)
self.TableWidget.fnRefreshTable()
self.lock.lockForRead()
testpass = self.TestThread.testcontroller.PassCurrentPassCount()
testfail = self.TestThread.testcontroller.PassCurrentFailCount()
testtotal = self.TestThread.testcontroller.PassTestCount()
if testpass == testtotal:
self.PassFailLabel.setText(u"<span style=\"color:#009530\"><h1>PASS</h1><span>")
elif ((testpass + testfail) < testtotal):
self.PassFailLabel.setText(u"<span style=\"color:#F9423A\"><h1>FAIL</h1><span>") #not complete whole suite
elif (testfail > 0):
self.PassFailLabel.setText(u"<span style=\"color:#F9423A\"><h1>FAIL</h1><span>") #One or more test fail
else:
self.PassFailLabel.setText(u"<span style=\"color:#F9423A\"><h1>FAIL</h1><span>") #Catch all...
self.lock.unlock()
def fnDisplayError(self, str):
ErrorMessageBox = QMessageBox()
newfont = QFont()
newfont.setPointSize(20)
ErrorMessageBox.setFont(newfont)
ErrorMessageBox.setIcon(QMessageBox.Warning)
ErrorMessageBox.setWindowTitle("Error")
ErrorMessageBox.setText(str)
ErrorMessageBox.exec_()
###########################################################################
# Widget Layout Functions
###########################################################################
def fnDrawTestControlsWidgets(self):
self.TestResultLabel = QLabel("<h1>Status:</h1>")
self.PassFailLabel = QLabel("")
#Start Buttons
ButtonText = QString(u"Start")
self.StartButton = QPushButton(ButtonText)
newfont = QFont()
newfont.setPointSize(15)
self.StartButton.setFont(newfont)
#Abort Button
ButtonText = QString(u"Abort")
self.AbortButton = QPushButton(ButtonText)
newfont = QFont()
newfont.setPointSize(15)
self.AbortButton.setFont(newfont)
self.AbortButton.setEnabled(False)
#Clear Buttons
ButtonText = QString(u"Clear")
self.ClearButton = QPushButton(ButtonText)
newfont = QFont()
newfont.setPointSize(15)
self.ClearButton.setFont(newfont)
self.TestConstrolsPositionList = [
{'x':0,'y':0,'widget':self.TestResultLabel},{'x':0,'y':1,'widget': None},
{'x':1,'y':0,'widget':self.PassFailLabel }, {'x':1,'y':1,'widget': None},
{'x':2,'y':0,'widget':self.StartButton}, {'x':2,'y':1,'widget':self.AbortButton }, {'x':2,'y':2,'widget':self.ClearButton }]
self.TestConstrolsGridLayout = QGridLayout()
for pos in self.TestConstrolsPositionList:
if pos['widget']:
self.TestConstrolsGridLayout.addWidget(pos['widget'], pos['x'], pos['y'])
self.TestControlsGroupBox = QGroupBox("Test Controls")
self.TestControlsGroupBox.setLayout(self.TestConstrolsGridLayout)
def fnDrawUUTSerWidgets(self):
self.UUTSerLineEdit = QLineEdit()
self.UUTSerLineEdit.setFixedWidth(200)
self.UUTSerHLayout = QHBoxLayout()
self.UUTSerHLayout.addWidget(self.UUTSerLineEdit)
self.UUTSerHLayout.addStretch()
self.UUTSerGroupBox = QGroupBox("UUT Serial Number:")
self.UUTSerGroupBox.setLayout( self.UUTSerHLayout )
def fnDrawFan1Widgets(self):
self.BL601LineEdit = QLineEdit()
self.BL601LineEdit.setFixedWidth(200)
self.BL601ProgEnableButton = QPushButton("Program Internal Fan")
self.BL601ProgEnableButton.setFixedWidth(200)
self.BL601ProgEnableButton.setCheckable(True)
self.BL601StatusLabel = QLabel()
self.Fan1HLayout = QHBoxLayout()
self.Fan1HLayout.addWidget(self.BL601LineEdit)
self.Fan1HLayout.addStretch()
self.Fan1HLayout.addWidget(self.BL601ProgEnableButton)
self.Fan1GroupBox = QGroupBox()
self.Fan1GroupBox.prefix = "(BL601) "
self.Fan1GroupBox.setTitle(self.Fan1GroupBox.prefix + SERNUM_INIT_STATUS)
self.Fan1GroupBox.setLayout( self.Fan1HLayout )
self.Fan1GroupBox.buttonref = self.BL601ProgEnableButton
self.Fan1GroupBox.lineref = self.BL601LineEdit
self.Fan1GroupBox.dictadd = {}
def fnDrawFan2Widgets(self):
self.BL602LineEdit = QLineEdit()
self.BL602LineEdit.setFixedWidth(200)
self.BL602ProgEnableButton = QPushButton("Program External Top Fan")
self.BL602ProgEnableButton.setFixedWidth(200)
self.BL602ProgEnableButton.setCheckable(True)
self.Fan2HLayout = QHBoxLayout()
self.Fan2HLayout.addWidget(self.BL602LineEdit)
self.Fan2HLayout.addStretch()
self.Fan2HLayout.addWidget(self.BL602ProgEnableButton)
self.Fan2GroupBox = QGroupBox()
self.Fan2GroupBox.prefix = "(BL602) "
self.Fan2GroupBox.setTitle(self.Fan2GroupBox.prefix + SERNUM_INIT_STATUS)
self.Fan2GroupBox.setLayout( self.Fan2HLayout )
self.Fan2GroupBox.buttonref = self.BL602ProgEnableButton
self.Fan2GroupBox.lineref = self.BL602LineEdit
self.Fan2GroupBox.dictadd = {}
def fnDrawFan3Widgets(self):
self.BL603LineEdit = QLineEdit()
self.BL603LineEdit.setFixedWidth(200)
self.BL603ProgEnableButton = QPushButton("Program External Bottom Fan")
self.BL603ProgEnableButton.setFixedWidth(200)
self.BL603ProgEnableButton.setCheckable(True)
self.Fan3HLayout = QHBoxLayout()
self.Fan3HLayout.addWidget(self.BL603LineEdit)
self.Fan3HLayout.addStretch()
self.Fan3HLayout.addWidget(self.BL603ProgEnableButton)
self.Fan3GroupBox = QGroupBox()
self.Fan3GroupBox.prefix = "(BL603) "
self.Fan3GroupBox.setTitle(self.Fan3GroupBox.prefix + SERNUM_INIT_STATUS)
self.Fan3GroupBox.setLayout( self.Fan3HLayout )
self.Fan3GroupBox.buttonref = self.BL603ProgEnableButton
self.Fan3GroupBox.lineref = self.BL603LineEdit
self.Fan3GroupBox.dictadd = {}
###########################################################################
# Logging Related Class Methods
###########################################################################
def fnAppend(self, message):
"""Used to append stuff to the Text Edit Box in the Log Window"""
cursor = self.textDisplayArea.textCursor()
cursor.beginEditBlock()
cursor.movePosition(QTextCursor.End)
cursor.insertText(message)
cursor.endEditBlock()
self.textDisplayArea.setTextCursor(cursor)
def fnClearLogger(self):
"""Used to clear the Log window"""
self.textDisplayArea.clear()
###########################################################################
# Helper Functions....
###########################################################################
## Helper Function used to add an list of Action Object to another widget
## @param self The object pointer.
## @param target The target widget you want to add actions too
## @param actions The list of actions you want to add to an widget
def addActions(self, target, actions):
"""Helper Function used to add an list of Action Object to another widget"""
for action in actions:
if action is None:
target.addSeparator()
else:
target.addAction(action)
## Creates an action object and configures the possible parameters
## @param self The object pointer.
## @param text The name of the action
## @param slot Assign an optional slot to the action
## @param shortcut Assign an optional shortcut to the action
## @param icon Assign an optional icon to the action
## @param tip Assign an optional status bar tip to the action
## @param checkable Indicate if the action is checkable or not
## @param signal Assign an optional signal to the action
def createAction(self, text, slot=None, shortcut=None, icon=None,
tip=None, checkable=False, signal="triggered()"):
"""Creates an action object and configures the possible parameters"""
action = QAction(text, self)
if icon is not None:
action.setIcon(QIcon(":/%s" % icon))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
return action
###########################################################################
# Menu Bar Functions
###########################################################################
## This function is called when the window is closed and the close event is generated
## @param self The object pointer.
## @param event The close event is passed to the function
def closeEvent(self, event):
"""When the window is closed, the current window state, size and
position are saved to the registry"""
# Save Main Window settings
self.settings.setValue("MainWindow/Size", QVariant(self.size()))
self.settings.setValue("MainWindow/Position", QVariant(self.pos()))
self.settings.setValue("MainWindow/State", QVariant(self.saveState()))
event.accept()
## Displays the Help information for the program
## @param self The object pointer.
def helpAbout(self):
"""Displays the Help information for the program"""
QMessageBox.about(self, "About SE1 Fan Programmer",
"""<b>SE1 Fan Programmer</b> v %s
<p>Copyright © 2016 Schneider Electric Inc.
All rights reserved.
<p>This program is used to program the SE1 fans during manufacturing.
<p>Python %s - Qt %s - PyQt %s on %s""" % (
__version__, platform.python_version(),
QT_VERSION_STR, PYQT_VERSION_STR, platform.system()))
def main():
app = QApplication(sys.argv)
app.setOrganizationName("Schneider Electric Inc.")
app.setOrganizationDomain("schneider-electric.com")
app.setApplicationName("SE1 Fan Programmer")
app.setWindowIcon(QIcon(":/fan.ico"))
#pipe all the stdout and stderr to the LoggerWidget
logger = Logger()
sys.stdout = logger
sys.stderr = logger
form = MainWindow(logger = logger)
form.show()
app.exec_()
main()