-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManualControlWidget.py
834 lines (733 loc) · 31.1 KB
/
ManualControlWidget.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
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
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt, QLine, QPoint
from PyQt5.QtGui import QPolygon, QFont
from twisted.internet.defer import inlineCallbacks
import labrad
#import time
from os.path import join
class EvaporatorWidget(QtWidgets.QWidget):
"""
Manual control widget pops up as a separate window from the main window.
"""
def __init__(self, main, frame):
super().__init__(frame)
self.main = main # The main interface
self.setGeometry(0, 0, 500, 750)
self.equip = dict() #: dict attribute for all dynamic elements
self.defineElements()
# self.names = ['leak valve', 'gate valve', 'chamber valve', 'turbo valve', 'turbo pump', 'scroll pump',
# 'evaporator power', 'effusion power', 'sputterer power',
# 'evaporator shutter', 'effusion shutter']
# EMERGENCY STOP DEPRACATED as it doesn't add much, in any real situation we would deal with
# the valves/pumps in a better way and the turb would spin down automatically
# it only adds the potential of someone clicking it when they are not supposed to
# self.emergencystopbutton = QtWidgets.QPushButton('Emergency Stop', self)
# self.emergencystopbutton.setToolTip('Valves will be closed and pumps will be turned off')
# self.emergencystopbutton.setGeometry(225-50, 600, 150, 50)
# self.emergencystopbutton.setStyleSheet("QPushButton{background-color : #cf0000;} "
# "QPushButton::pressed{background-color : #b90000;}")
# self.emergencystopbutton.setFont(QFont('Times', 15))
# self.emergencystopbutton.clicked.connect(self.emergencystop)
self.refreshbutton = QtWidgets.QPushButton('Refresh', self)
self.refreshbutton.setToolTip('Refresh the status of all components')
self.refreshbutton.setGeometry(25, 25, 75, 25)
self.refreshbutton.setStyleSheet("QPushButton{background-color : #ffffff;} "
"QPushButton::pressed{background-color : #eeeeee;}")
self.refreshbutton.setFont(QFont('Times', 12))
self.refreshbutton.clicked.connect(self.refresh)
self.setWindowIcon(QtGui.QIcon(join('Interfaces','images','squid_tip.png')))
self.isConnected = False
self.connect()
self.show()
#
def defineElements(self):
"""
Defines all the dynamic elements on the widget.
returns: None
"""
name = 'Heater'
self.heaterbutton = QtWidgets.QPushButton('Heater', self)
self.heaterbutton.setCheckable(True)
self.heaterbutton.setToolTip('Toggle the heater')
self.heaterbutton.setGeometry(280-50, 600, 75, 25)
self.heaterbutton.setStyleSheet("QPushButton{background-color : #ffffff;} "
"QPushButton::pressed{background-color : #eeeeee;}")
self.heaterbutton.setFont(QFont('Times', 12))
self.heaterbutton.clicked.connect(self.heater)
# self.setpointinput = QtWidgets.QLineEdit(self)
# self.equip[name].input.setReadOnly(False) # Until we implement a way for it to display the setpoint
# self.equip[name].input.setPlaceholderText('Pressure')
# self.equip[name].input.setGeometry(85-50, 310, 50, 20
name = 'leak valve'
self.equip[name] = Valve(self, 80-50, 358, 'hor', 'blue', name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(75-50, 290)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
self.equip[name].input = QtWidgets.QLineEdit(self)
self.equip[name].input.setReadOnly(False) # Until we implement a way for it to display the setpoint
self.equip[name].input.setPlaceholderText('Pressure')
self.equip[name].input.setGeometry(85-50, 310, 50, 20)
#self.equip[name].input.returnPressed.connect(self.helium_setpoint) # Comment until we implement a way for it to display the setpoint
name = 'gate valve'
self.equip[name] = Valve(self, 150-50, 460, 'ver', 'blue', name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel('gate\nvalve', self)
self.equip[name].label.move(90-50, 470)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'chamber valve'
self.equip[name] = Valve(self, 270-50, 430, 'hor', 'blue', name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(260-50, 450)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'turbo valve'
self.equip[name] = Valve(self, 425-50, 460, 'ver', 'blue', name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel('turbo\nvalve', self)
self.equip[name].label.move(450-50, 470)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'evaporator shutter'
self.equip[name] = Shutter(self, 185-50, 190, 'ver', 'red', name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel('evaporator\nshutter', self)
self.equip[name].label.move(100-50, 190)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'effusion shutter'
self.equip[name] = Shutter(self, 350-50, 190, 'ver', QtGui.QColor(20, 30, 30), name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel('effusion\nshutter', self)
self.equip[name].label.move(285-50, 190)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'scroll pump'
self.equip[name] = Pump(self, 475-50, 410, name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(460-50, 390)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'turbo pump'
self.equip[name] = Pump(self, 280-50, 530, name)
self.equip[name].clicked.connect(self.equip[name].toggle)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(260-50, 510)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'evaporator power'
self.equip[name] = Power(self, 165-50, 110, name)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(135-50, 80)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'effusion power'
self.equip[name] = Power(self, 330-50, 110, name)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(295-50, 80)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
name = 'sputterer power'
self.equip[name] = Power(self, 455-50, 110, name)
self.equip[name].label = QtWidgets.QLabel(name, self)
self.equip[name].label.move(435-50, 80)
self.equip[name].label.setStyleSheet('font-size: 16px; qproperty-alignment: AlignJustify;')
for key in self.equip.keys():
self.equip[key].status = True
def helium_setpoint(self):
"""
Sets the pressure on the leak valve after QLineEdit is filled and Return button pressed.
QMessage box pops up if the turbo pump is in danger.
return: None
"""
name = 'leak valve'
if self.equip['turbo pump'].status and self.equip['gate valve'].status:
msg = QtWidgets.QMessageBox()
msg.setWindowTitle("Dangerous situation")
msg.setText("Are you sure you want to open the leak valve while the turbo pump is active"
"and the gate valve is open?")
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel)
msg.setDefaultButton(QtWidgets.QMessageBox.Cancel)
# msg.exec_()
returnvalue = msg.exec()
if returnvalue == QtWidgets.QMessageBox.Cancel:
pass
self.equip[name].input.clear()
else:
prs = self.equip[name].input.text()
#prs = "{:.2E}".format(prs)
self.equip[name].input.clear()
print('helium pressure is ', prs)
yield self.rvc.set_mode_prs()
yield self.rvc.set_nom_prs(prs)
# DEPRECATED, see comment in initilizer
# def emergencystop(self):
# """
# Closes gate valve, chamber valve and turn off turbo pump. Turn on scroll pump and open turbo valve
# to have the access to the pump outlet.
#
# return: None
# """
# self.main.abort()
#
# self.vrs.gate_close()
# self.vrs.chamber_valve_close()
# self.vrs.turbo_valve_close()
# self.vrs.turbo_off()
# #self.vrs.scroll_off()
#
# self.rvc.close_valve()
#
# self.refresh()
@inlineCallbacks
def heater(self, c):
"""
toggle the heater between off and high heat range.
Active only if the leak valve is open.
"""
if self.heaterbutton.isChecked():
if self.equip['leak valve'].state:
yield self.lakeshore.ramp(1, 0, 0)
print('flag 1')
yield self.lakeshore.read()
cur_temp = yield self.lakeshore.read_temp()
cur_temp = cur_temp.split(';')[0]
print('Temperature is ', cur_temp)
yield self.lakeshore.set_p(1, cur_temp)
print('flag 2')
yield self.lakeshore.set_heater_range(1,4)
yield self.lakeshore.ramp(1, 1, 5)
setp = yield self.lakeshore.read_p(1)
print(setp)
yield self.lakeshore.set_p(1, 300)
print('flag 4')
else:
print('Leak valve is closed')
else:
yield self.lakeshore.set_heater_range(1,0)
cur_temp = yield self.lakeshore.read_temp()
cur_temp = cur_temp.split(';')[0]
print('Temperature is ', cur_temp)
yield self.lakeshore.set_p(1, cur_temp)
yield self.lakeshore.ramp(1, 0, 0)
def refresh(self):
"""
Refresh the widget
return: None
"""
self.equip['gate valve'].state = self.vrs.returnstate('gate valve')
self.equip['chamber valve'].state = self.vrs.returnstate('chamber valve')
self.equip['turbo pump'].state = self.vrs.returnstate('turbo pump')
self.equip['scroll pump'].state = self.vrs.returnstate('scroll pump')
self.equip['turbo valve'].state = self.vrs.returnstate('turbo valve')
self.equip['leak valve'].state = self.rvc.returnstate()
self.equip['evaporator shutter'].state = self.evss.returnstate()
# self.equip['evaporator power'].state = self.tdk.onoff() # Have it keep track of state like the others
'''
Future Equipment integration
'''
# self.equip['effusion power'].state = self.
# self.equip['sputterer power'].state = self.dcxs.returnstate()
# self.equip['effusion shutter'].state = self.
self.update()
def stopprocess(self):
"""
Called when the stop button in pop up window is pressed, aborts
an active process.
return: None
"""
self.main.abort()
def paintEvent(self, event):
"""
Paints all the static elements.
return: None
"""
painter = QtGui.QPainter(self)
pen = QtGui.QPen()
pen.setWidth(4)
pen.setColor(QtGui.QColor(0, 0, 255)) # r, g, b
painter.setPen(pen)
#####Main vacuum part######
# Leak valve#
painter.drawLine(140-50, 358, 175-50, 358) # (80, 358) -> (140, 358)
painter.drawLine(60-50, 358, 80-50, 358)
# gate valve
painter.drawLine(175-50, 390, 150-50, 390) # (150, 460) -> (150, 520)
painter.drawLine(150-50, 390, 150-50, 460)
painter.drawLine(150-50, 520, 150-50, 550)
# scroll valve
painter.drawLine(150-50, 430, 270-50, 430) # (270, 430) -> (330, 430)
painter.drawLine(330-50, 430, 475-50, 430)
# turbo valve
painter.drawLine(425-50, 430, 425-50, 460) # (425, 460) -> (425, 520)
painter.drawLine(425-50, 520, 425-50, 550)
# turbo pump
painter.drawLine(150-50, 550, 280-50, 550) # (270, 550) -> (330, 550)
painter.drawLine(320-50, 550, 425-50, 550)
# Evaporator
pen.setColor(QtGui.QColor(255, 0, 0))
painter.setPen(pen)
painter.drawLine(185-50, 275, 185-50, 230) # (185, 250) -> (185, 190)
painter.drawLine(185-50, 190, 185-50, 150)
# Effusion
pen.setColor(QtGui.QColor(20, 30, 30))
painter.setPen(pen)
painter.drawLine(350-50, 275, 350-50, 230) # (350, 250) -> (350, 190)
painter.drawLine(350-50, 190, 350-50, 150)
# Sputterer
pen.setColor(QtGui.QColor(20, 100, 30))
painter.setPen(pen)
painter.drawLine(425-50, 358, 475-50, 358) # (475, 250) -> (475, 190)
painter.drawLine(475-50, 358, 475-50, 150)
pen.setWidth(4)
pen.setColor(QtGui.QColor(0, 0, 0)) # r, g, b
painter.setPen(pen)
painter.drawRects(QtCore.QRect(175-50, 275, 250, 125))
def connect(self):
"""
Connects to the LabRAD servers and prepares the devices to listen to the commands
return: None
"""
if self.isConnected:
self.disconnect()
self.isConnected = False
self.cxn = labrad.connect('localhost', password='pass')
# Connectors to the valve/relay controller, the rvc pressure controller,
# the stepper controller and the power supply controller.
self.vrs = self.cxn.valve_relay_server
self.vrs.select_device()
#Iden command added so that arduino will respond to first command given from GUI.
self.vrs.iden()
self.rvc = self.cxn.rvc_server
self.rvc.select_device()
self.evss = self.cxn.evaporator_shutter_server
self.evss.select_device()
self.tdk = self.cxn.power_supply_server
self.tdk.select_device()
self.tdk.adr('6')
self.tdk.rmt_set('REM')
self.ftm = self.cxn.ftm_server
self.ftm.select_device()
self.lakeshore = self.cxn.lakeshore_336
self.lakeshore.select_device()
'''
Other Servers we may integrate later
'''
#self.dcxs = self.cxn.DCXS_power
#self.dcxs.select_device()
# self.turbo450 = self.cxn.turbo450
# self.turbo450.select_device()
self.isConnected = True
self.refresh()
def closeEvent(self, event):
'''
To make closing consistent with the other windows
'''
if hasattr(self, 'main'):
self.main.closeEvent(event)
else:
event.accept()
#
#
class Valve(QtWidgets.QPushButton):
"""
Defines all the valves in the Widget
"""
def __init__(self, EvaporatorWidget, posx, posy, orient, color, name):
"""
param EvaporatorWidget: parent class
param posx: left-most point
param posy: top-most point
param orient: Orientation 'hor' for horizontal or vertical otherwise
param color: example QtGui.QColor(255, 255, 255)
param name: name of the valve, i.e. 'gate valve'
"""
super().__init__(EvaporatorWidget)
self.parent = EvaporatorWidget
self.state = True # True for open
self.setToolTip('Open')
self.posx = posx
self.posy = posy
self.orient = orient
self.color = color
self.name = name
if self.orient == 'hor':
self.move(self.posx, self.posy - 20)
self.resize(60, 40)
else:
self.move(self.posx - 20, self.posy)
self.resize(40, 60)
def paintEvent(self, event):
"""
Paints valve
return: None
"""
painter = QtGui.QPainter(self)
brush = QtGui.QBrush()
pen = QtGui.QPen()
pen.setWidth(1)
pen.setColor(QtGui.QColor(0, 0, 0))
painter.setPen(pen)
if not self.state: # close
brush.setColor(QtGui.QColor(255, 255, 255))
else: # open
brush.setColor(QtGui.QColor(self.color))
brush.setStyle(Qt.Dense1Pattern)
painter.setBrush(brush)
if self.orient == 'hor':
points = QPolygon([
QPoint(0, 0),
QPoint(0, 40),
QPoint(58, 0),
QPoint(58, 40)
])
painter.drawPolygon(points)
else:
points = QPolygon([
QPoint(0, 0),
QPoint(40, 0),
QPoint(0, 58),
QPoint(40, 58)
])
painter.drawPolygon(points)
@inlineCallbacks
def toggle(self, c):
"""
Change the state of the valve. If the process is active QMessageBox appears. You can stop the process
by pressing 'Stop'. If you want ot pause the process or dismiss the action press 'Cancel'.
return: None
"""
# if self.parent.main.status == "active":
# msg = QtWidgets.QMessageBox()
# msg.setWindowTitle("System is active")
# msg.setText("Please pause or stop the recipe before activating the manual control.")
#
# msg.setIcon(QtWidgets.QMessageBox.Critical)
#
# stop = QtWidgets.QPushButton("Stop")
# msg.addButton(stop, QtWidgets.QMessageBox.YesRole)
# stop.clicked.connect(self.parent.stopprocess)
#
# cancel = QtWidgets.QPushButton("Cancel")
# msg.addButton(cancel, QtWidgets.QMessageBox.YesRole)
# msg.setDefaultButton(cancel)
# msg.exec_()
# else:
if self.state:
if self.name == 'leak valve':
print(self.parent.equip[self.name].input.text())
if self.parent.equip[self.name].input.text() == '':
ans = yield self.parent.rvc.close_valve()
print(ans)
self.state = False
self.setToolTip('Closed')
self.parent.equip[self.name].status = False
print(self.name + " manually closed")
elif (self.parent.equip[self.name].input.text() == 'vent') or \
(self.parent.equip[self.name].input.text() == 'Vent'):
self.parent.equip[self.name].input.clear()
print('Venting')
yield self.parent.rvc.set_mode_flo()
yield self.parent.rvc.set_nom_flo('100.0')
else:
prs = self.parent.equip[self.name].input.text()
# prs = "{:.2E}".format(prs)
self.parent.equip[self.name].input.clear()
yield self.parent.rvc.set_mode_prs()
yield self.parent.rvc.set_nom_prs(prs)
else:
self.state = False
self.setToolTip('Closed')
self.parent.equip[self.name].status = False
print(self.name + " manually closed")
if self.name == 'gate valve':
yield self.parent.vrs.gate_close()
elif self.name == 'chamber valve':
yield self.parent.vrs.chamber_valve_close()
elif self.name == 'turbo valve':
yield self.parent.vrs.turbo_valve_close()
else:
print('Incorrect name')
else:
self.state = True
self.setToolTip('Open')
self.parent.equip[self.name].status = True
print(self.name + " manually opened")
if self.name == 'gate valve':
yield self.parent.vrs.gate_open()
elif self.name == 'chamber valve':
yield self.parent.vrs.chamber_valve_open()
elif self.name == 'turbo valve':
yield self.parent.vrs.turbo_valve_open()
elif self.name == 'leak valve':
if self.parent.equip[self.name].input.text() == '':
prs = str('5.00E-03')
print(prs)
ans = yield self.parent.rvc.set_mode_prs()
print(ans)
ans = yield self.parent.rvc.set_nom_prs(prs)
print(ans)
elif (self.parent.equip[self.name].input.text() == 'vent') or \
(self.parent.equip[self.name].input.text() == 'Vent'):
self.parent.equip[self.name].input.clear()
print('Venting')
yield self.parent.rvc.set_mode_flo()
yield self.parent.rvc.set_nom_flo('100.0')
else:
prs = self.parent.equip[self.name].input.text()
print(prs)
self.parent.equip[self.name].input.clear()
ans = yield self.parent.rvc.set_mode_prs()
print(ans)
ans = yield self.parent.rvc.set_nom_prs(str(prs))
print(ans)
else:
print('Incorrect name')
self.update()
def popup_clicked(self, i):
"""
What to do in case any button on QMessageBox is pressed.
:param i: message
:return: None
"""
if i.text() == 'Cancel':
pass
elif i.text() == 'Stop':
self.parent.stopprocess()
class Pump(QtWidgets.QPushButton):
"""
Defines all the pumps in the Widget
"""
def __init__(self, EvaporatorWidget, posx, posy, name):
"""
param EvaporatorWidget: parent class
param posx: left-most point
param posy: top-most point
param name: name of the valve, i.e. 'turbo pump'
"""
super().__init__(EvaporatorWidget)
self.parent = EvaporatorWidget
self.state = False # True for on
self.setToolTip('Off')
self.posx = posx
self.posy = posy
self.name = name
self.move(self.posx, self.posy)
self.resize(41, 41)
def paintEvent(self, event):
"""
Paints pump
return: None
"""
painter = QtGui.QPainter(self)
brush = QtGui.QBrush()
if not self.state: # close
brush.setColor(QtGui.QColor(255, 255, 255))
brush.setStyle(Qt.Dense1Pattern)
painter.setBrush(brush)
painter.drawEllipse(0, 0, 40, 40)
else: # open
brush.setColor(QtGui.QColor("#FFD141"))
brush.setStyle(Qt.Dense1Pattern)
painter.setBrush(brush)
painter.drawEllipse(0, 0, 40, 40)
def toggle(self):
"""
Change the state of the pump. If the process is active QMessageBox appears. You can stop the process
by pressing 'Stop'. If you want ot pause the process or dismiss the action press 'Cancel'.
return: None
"""
# if self.parent.main.status == "active":
# msg = QtWidgets.QMessageBox()
# msg.setWindowTitle("System is active")
# msg.setText("Please pause or stop the recipe before activating the manual control.")
#
# msg.setIcon(QtWidgets.QMessageBox.Critical)
#
# stop = QtWidgets.QPushButton("Stop")
# msg.addButton(stop, QtWidgets.QMessageBox.YesRole)
# stop.clicked.connect(self.parent.stopprocess)
#
# cancel = QtWidgets.QPushButton("Cancel")
# msg.addButton(cancel, QtWidgets.QMessageBox.YesRole)
# msg.setDefaultButton(cancel)
# msg.exec_()
# elif self.name == 'scroll pump' and self.state and self.parent.equip['turbo pump'].state:
# msg = QtWidgets.QMessageBox()
# msg.setWindowTitle("Turbo Pump Active")
# msg.setText("Cannot turn off the scroll pump while the turbo pump is running.")
#
# msg.setIcon(QtWidgets.QMessageBox.Critical)
# cancel = QtWidgets.QPushButton("Continue")
# msg.addButton(cancel, QtWidgets.QMessageBox.YesRole)
# msg.setDefaultButton(cancel)
# msg.exec_()
# elif self.name == 'turbo pump' and not self.state and (not self.parent.equip['scroll pump'].state or not self.parent.equip['turbo valve'].state):
# msg = QtWidgets.QMessageBox()
# msg.setWindowTitle("Scroll Pump Off")
# msg.setText("Cannot turn on turbo with the scroll pump off or turbo valve closed.")
#
# msg.setIcon(QtWidgets.QMessageBox.Critical)
# cancel = QtWidgets.QPushButton("Continue")
# msg.addButton(cancel, QtWidgets.QMessageBox.YesRole)
# msg.setDefaultButton(cancel)
# msg.exec_()
# else:
if self.state:
self.state = False
self.setToolTip('Off')
self.parent.equip[self.name].status = False
print(self.name + " manually turned off")
if self.name == 'turbo pump':
self.parent.vrs.turbo_off()
elif self.name == 'scroll pump':
self.parent.vrs.scroll_off()
else:
print('Incorrect Pump Name')
else:
self.state = True
self.setToolTip('On')
self.parent.equip[self.name].status = True
print(self.name + " manually turned on")
if self.name == 'turbo pump':
self.parent.vrs.turbo_on()
elif self.name == 'scroll pump':
self.parent.vrs.scroll_on()
else:
print('Incorrect Pump Name')
self.update()
def popup_clicked(self, i):
"""
What to do in case any button on QMessageBox is pressed.
param i: message
return: None
"""
if i.text() == 'Cancel':
pass
elif i.text() == 'Stop':
self.parent.stopprocess()
class Power(QtWidgets.QPushButton):
"""
Defines all the power supplies in the Widget
"""
def __init__(self, EvaporatorWidget, posx, posy, name):
"""
param EvaporatorWidget: parent class
param posx: left-most point
param posy: top-most point
param name: name of the valve, i.e. 'turbo pump'
"""
super().__init__(EvaporatorWidget)
self.parent = EvaporatorWidget
self.state = False # True for on
self.setToolTip('Off')
self.posx = posx
self.posy = posy
self.name = name
self.move(self.posx, self.posy)
self.resize(41, 41)
def paintEvent(self, event):
"""
Paints power supply
return: None
"""
painter = QtGui.QPainter(self)
brush = QtGui.QBrush()
if not self.state: # close
brush.setColor(QtGui.QColor(255, 255, 255))
brush.setStyle(Qt.Dense1Pattern)
painter.setBrush(brush)
painter.drawEllipse(0, 0, 40, 40)
else: # open
brush.setColor(QtGui.QColor("#FFD141"))
brush.setStyle(Qt.Dense1Pattern)
painter.setBrush(brush)
painter.drawEllipse(0, 0, 40, 40)
def toggle(self):
"""
Change the state (On/Off) of the power supply. Can be accessed only from the main window.
return: None
"""
if self.state:
self.state = False
self.setToolTip('Off')
self.parent.equip[self.name].status = False # Not sure we need that
else:
self.state = True
self.setToolTip('On')
self.parent.equip[self.name].status = True # Not sure we need that
self.update()
class Shutter(QtWidgets.QPushButton):
"""
Defines all the shutters in the Widget
"""
def __init__(self, EvaporatorWidget, posx, posy, orient, color, name):
super().__init__(EvaporatorWidget)
self.name = name
self.parent = EvaporatorWidget
self.state = False # True for Open
self.setToolTip('Closed')
self.posx = posx
self.posy = posy
self.orient = orient
self.color = color
if self.orient == 'hor':
self.move(self.posx, self.posy + 2)
self.resize(60, 40)
else:
self.move(self.posx - 4, self.posy)
self.resize(40, 60)
"""First define the line for open and close position for each valve"""
# close
if orient == 'hor':
self.close = QLine(0, 4, 35, 19)
else:
self.close = QLine(4, 0, 19, 35)
# open
if orient == 'hor':
self.open = QLine(5, 4, 35, 4)
else:
self.open = QLine(4, 5, 4, 35)
def paintEvent(self, event):
"""
Paints shutter
return: None
"""
painter = QtGui.QPainter(self)
pen_close = QtGui.QPen()
pen_close.setWidth(4)
pen_close.setColor(QtGui.QColor(self.color)) # r, g, b
pen_open = QtGui.QPen()
pen_open.setWidth(4)
pen_open.setColor(QtGui.QColor(self.color))
if not self.state: # close
painter.setPen(pen_close)
painter.drawLine(self.close)
else: # open
painter.setPen(pen_open)
painter.drawLine(self.open)
def toggle(self):
"""
Change the state (Open/Closed) of the shutter. Can be accessed only from the main window.
return: None
"""
if self.state:
self.state = False
self.setToolTip('Closed')
if self.name == 'evaporator shutter':
self.parent.evss.close_shutter()
print('closed evaporator shutter')
elif self.name == 'effusion shutter':
self.parent.evss.close_effusion_shutter()
print('closed evaporator shutter')
else:
self.state = True
self.setToolTip('Open')
if self.name == 'evaporator shutter':
self.parent.evss.open_shutter()
print('opened evaporator shutter')
elif self.name == 'effusion shutter':
self.parent.evss.open_effusion_shutter()
print('opened evaporator shutter')
self.update()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
ex = EvaporatorWidget(None)
ex.show()
sys.exit(app.exec_())