mirror of
https://gitlab.psi.ch/pyqtacc/proscan.git
synced 2025-12-30 22:48:45 +01:00
772 lines
32 KiB
Python
772 lines
32 KiB
Python
""" Gui header for PROSCAN
|
|
"""
|
|
import os
|
|
|
|
from qtpy.QtCore import Qt, QTimer, Slot
|
|
from qtpy.QtGui import QFont, QPixmap
|
|
from qtpy.QtWidgets import (
|
|
QApplication, QFrame, QGridLayout, QGroupBox, QHBoxLayout, QLabel,
|
|
QVBoxLayout, QWidget)
|
|
|
|
from caqtwidgets.pvwidgets import CAQLabel
|
|
from apps4ops.bdbase.enumkind import UserMode
|
|
from apps4ops.bdbase.utils import _line
|
|
|
|
_pymodule = os.path.basename(__file__)
|
|
|
|
|
|
class GUIHeader(QWidget):
|
|
""" GUI Header Class
|
|
"""
|
|
|
|
def __init__(self, parent, user_mode=UserMode.OPERATION, extended=True):
|
|
#super(GUIHeader, self).__init__()
|
|
super().__init__() # Use Python 3 style
|
|
self.parent = parent
|
|
self.appname = parent.appname
|
|
self.title = parent.title
|
|
self.settings = parent.settings
|
|
self.user_mode = user_mode
|
|
self.current_user_mode_name = user_mode.name
|
|
|
|
self.extended = extended
|
|
self.cafe = parent.cafe
|
|
self.cyca = parent.cyca
|
|
self.check_status = self.parent.check_status
|
|
self.check_status_list = self.parent.check_status_list
|
|
|
|
self.input_parameters = parent.input_parameters
|
|
self.input_labels = parent.input_labels
|
|
self.expert_parameters = parent.expert_parameters
|
|
self.expert_labels = parent.expert_labels
|
|
|
|
self.header_groups = self.settings.data["header"]
|
|
self.header_status = [None] * len(self.header_groups)
|
|
self.header_height = 234
|
|
offset = 1
|
|
|
|
self.header_row = {"COMET": 4+offset, "BMA1": 4+offset, "G1": 4+offset,
|
|
"SH": 2+offset, "G2": 3+offset, "O2": 2+offset,
|
|
"BMD1": 1+offset, "PIF": 0, "G3":1+offset,
|
|
"MASTER": 4+offset}
|
|
# self.header_row = {"COMET": 0, "G1": 0, "SH": 0, "G2": 0, "O2": 0,
|
|
# "PIF": 0, "G3": 0, "MASTER": 0}
|
|
|
|
try:
|
|
self.assigned_master = self.settings.data["Master"]
|
|
except KeyError as ex:
|
|
print(ex)
|
|
self.assigned_master = "Controlroom"
|
|
|
|
self.font_gui = QFont("sans serif")
|
|
self.font_gui.setPointSize(11)
|
|
self.font_pts10 = QFont("sans serif")
|
|
self.font_pts10.setPointSize(10)
|
|
self.widget_height = self.settings.data["StyleGuide"]["widgetHeight"]
|
|
self.extra_height = self.settings.data["StyleGuide"]["extraGroupHeight"]
|
|
|
|
pvlist = []
|
|
header_colors = []
|
|
for sector in self.header_groups:
|
|
pvlist.append(self.settings.data[sector]["status"])
|
|
header_colors.append(self.settings.data[sector]["colorObj"])
|
|
|
|
self.cafe.openPrepare()
|
|
self.cafe.open(pvlist)
|
|
self.cafe.openNowAndWait(0.4)
|
|
self.cafe.printDisconnected()
|
|
|
|
self.station_width = 200 # default
|
|
self.station_height = 100
|
|
self.hor_layout = QHBoxLayout()
|
|
self.grid_layout = QGridLayout()
|
|
self.beam_current_wgt_dict = {}
|
|
self.beam_current_wgt_group = {}
|
|
has_hbox_layout = False
|
|
|
|
self.pframe_matrix = {"POST-COMET": {}, "POST-BMA1": {}, "G1": {},
|
|
"PRE-SH": {}, "POST-SH": {}, "G2": {},
|
|
"PRE-O2": {}, "O2": {}, "PRE-PIF": {},
|
|
"PRE-G3": {}}
|
|
|
|
self.op_color = self.settings.data["StyleGuide"]["bgTitleOperation"]
|
|
self.sim_color = self.settings.data["StyleGuide"]["bgTitleSimulation"]
|
|
self.pf_off_color = self.sim_color if self.settings.data["Expert"][
|
|
"simulation"]["data"]["value"] else self.op_color
|
|
|
|
def pframe(color="green"):
|
|
qframe = QFrame()
|
|
qframe.setStyleSheet("background-color: {0};".format(color))
|
|
qframe.setFixedWidth(6)
|
|
qframe.setFixedHeight(6)
|
|
return qframe
|
|
|
|
def draw_box(nheight: int = 10, nwidth: int = 8, area: str = None):
|
|
if area is None:
|
|
return
|
|
qw = QWidget()
|
|
qgrid = QGridLayout()
|
|
for i in range(0, nheight):
|
|
self.pframe_matrix[area][i] = {}
|
|
for j in range(0, nwidth):
|
|
self.pframe_matrix[area][i][j] = {}
|
|
pf = pframe(self.pf_off_color)
|
|
qgrid.addWidget(pf, i, j, 1, 1, Qt.AlignCenter)
|
|
self.pframe_matrix[area][i][j] = pf
|
|
|
|
qgrid.setSpacing(1)
|
|
qgrid.setContentsMargins(0, 0, 0, 0)
|
|
qgrid.setAlignment(Qt.AlignCenter)
|
|
qw.setLayout(qgrid)
|
|
return qw
|
|
|
|
if has_hbox_layout:
|
|
for sector, pv, color in zip(self.header_groups, pvlist,
|
|
header_colors):
|
|
if sector == "MASTER":
|
|
qframe = QFrame()
|
|
qframe.setFixedWidth(200)
|
|
self.hor_layout.addWidget(qframe)
|
|
|
|
self.hor_layout.addWidget(self.beam_current_widget(
|
|
header=sector, pv=pv, color_obj=color))
|
|
self.hor_layout.setSpacing(6)
|
|
self.hor_layout.setAlignment(Qt.AlignLeft)
|
|
self.hor_layout.setContentsMargins(5, 0, 5, 0)
|
|
else:
|
|
j = 0
|
|
align = Qt.AlignCenter
|
|
for (sector, pv, color) in (
|
|
zip(self.header_groups, pvlist, header_colors)):
|
|
if sector == "MASTER":
|
|
#qframe = QFrame()
|
|
# qframe.setFixedWidth(10)
|
|
# self.grid_layout.addWidget(
|
|
# qframe, self.header_row[sector], j, 2, 1)
|
|
self.grid_layout.addWidget(
|
|
self.beam_current_widget(
|
|
header=sector, pv=pv, color_obj=color),
|
|
self.header_row[sector], j-1, 2, 5) # j -3 with_sub_master
|
|
j += 1
|
|
|
|
elif sector == "BMD1":
|
|
self.grid_layout.addWidget(
|
|
self.beam_current_widget(
|
|
header=sector, pv=pv, color_obj=color),
|
|
self.header_row[sector], j-4, 2, 3, Qt.AlignTop) # j -3 with_sub_master
|
|
|
|
else:
|
|
align = Qt.AlignTop
|
|
|
|
self.grid_layout.addWidget(
|
|
self.beam_current_widget(
|
|
header=sector, pv=pv, color_obj=color),
|
|
self.header_row[sector], j, 2, 1, align)
|
|
|
|
if sector == "G3":
|
|
self.grid_layout.addWidget(
|
|
QFrame(), self.header_row[sector], j + 1, 2, 3,
|
|
align)
|
|
j += 1
|
|
offset = 2
|
|
if sector in ["PIF"]:
|
|
qw = draw_box(nheight=10, nwidth=8+16, area="PRE-G3")
|
|
self.grid_layout.addWidget(qw, 0+offset-0, j - 1, 3, 1, align)
|
|
j += 1
|
|
elif sector in ["O2"]:
|
|
qw1 = draw_box(nheight=5, nwidth=16, area="PRE-PIF")
|
|
self.grid_layout.addWidget(qw1, 0+offset, j - 1, 2, 1, align)
|
|
qw = draw_box(nheight=15, nwidth=8, area="O2")
|
|
vbox = QVBoxLayout()
|
|
qf = QFrame()
|
|
qf.setFixedHeight(1)
|
|
vbox.addWidget(qf)
|
|
vbox.addWidget(qw)
|
|
self.grid_layout.addLayout(vbox, 0, j, 4, 1, align)
|
|
#qf = QFrame()
|
|
#qf.setFixedHeight(qw1.height()-10)
|
|
#self.grid_layout.addWidget(qf, 0, 13, 2, 1, align)
|
|
j += 1
|
|
elif sector in ["COMET"]:
|
|
qw = draw_box(nheight=10, nwidth=8, area="POST-COMET")
|
|
self.grid_layout.addWidget(qw, 2+offset, j, 3, 1, align)
|
|
j += 1
|
|
elif sector in ["BMA1"]:
|
|
qw = draw_box(nheight=15, nwidth=12, area="POST-BMA1")
|
|
self.grid_layout.addWidget(qw, 1+offset, j, 4, 1, align)
|
|
j += 1
|
|
elif sector in ["SH"]:
|
|
qw = draw_box(nheight=15, nwidth=10, area="POST-SH")
|
|
self.grid_layout.addWidget(qw, 0+offset, j, 4, 1, align)
|
|
j += 1
|
|
elif sector in ["G1"]:
|
|
qw = draw_box(nheight=5, nwidth=16, area="G1")
|
|
self.grid_layout.addWidget(qw, 1+offset, j - 1, 2, 1, align)
|
|
qw = draw_box(nheight=10, nwidth=8, area="PRE-SH")
|
|
self.grid_layout.addWidget(qw, 1+offset, j, 3, 1, align)
|
|
j += 1
|
|
elif sector in ["G2"]:
|
|
qw = draw_box(nheight=10, nwidth=16, area="G2")
|
|
self.grid_layout.addWidget(qw, 0+offset, j - 1, 2, 1, align)
|
|
qw = draw_box(nheight=10, nwidth=8, area="PRE-O2")
|
|
self.grid_layout.addWidget(qw, 0+offset, j, 3, 1, align)
|
|
j += 1
|
|
elif sector not in ["MASTER", "G3"]:
|
|
qw = draw_box()
|
|
self.grid_layout.addWidget(qw, 0+offset, j-1, 2, 1, align)
|
|
j += 1
|
|
|
|
pv_shift = self.settings.data["Shift"]["type"]
|
|
val = self.cafe.get(pv_shift)
|
|
if val is None:
|
|
pv_shift = "PRO-HUSH:SHIFT-TYPE"
|
|
|
|
self.shift_type = CAQLabel(self, pv_name=pv_shift)
|
|
self.grid_layout.addWidget(self.shift_type, 1, 0, 1, 2,
|
|
Qt.AlignBottom | Qt.AlignLeft)
|
|
|
|
'''
|
|
label = QLabel()
|
|
pixmap = QPixmap(":/Hush.jpg")
|
|
pixmap.scaled(80, 80, Qt.KeepAspectRatio)
|
|
label.setFixedWidth(80)
|
|
label.setFixedHeight(80)
|
|
label.setPixmap(pixmap)
|
|
label.setScaledContents(True)
|
|
self.grid_layout.addWidget(label, 2, 0, 3, 1,
|
|
Qt.AlignHCenter | Qt.AlignVCenter)
|
|
'''
|
|
hbox1 = QHBoxLayout()
|
|
ama1_label = QLabel("AMA1:")
|
|
ama1 = CAQLabel(self, pv_name="AMA1:SOL:2", show_units=True)
|
|
hbox1.addWidget(ama1_label)
|
|
hbox1.addWidget(ama1)
|
|
self.grid_layout.addLayout(hbox1, 1, 2, 1, 2,
|
|
Qt.AlignTop | Qt.AlignRight)
|
|
hbox = QHBoxLayout()
|
|
ama3_label = QLabel("AMA3:")
|
|
ama3 = CAQLabel(self, pv_name="AMA3:SOL:2", show_units=True)
|
|
hbox.addWidget(ama3_label)
|
|
hbox.addWidget(ama3)
|
|
self.grid_layout.addLayout(hbox, 1, 6, 1, 3,
|
|
Qt.AlignTop | Qt.AlignHCenter)
|
|
hbox2 = QHBoxLayout()
|
|
amd2_label = QLabel("AMD2:")
|
|
amd2 = CAQLabel(self, pv_name="AMD2:SOL:2", show_units=True)
|
|
hbox2.addWidget(amd2_label)
|
|
hbox2.addWidget(amd2)
|
|
self.grid_layout.addLayout(hbox2, 1, 9, 1, 2,
|
|
Qt.AlignTop | Qt.AlignRight)
|
|
|
|
b1_label = QLabel("B1")
|
|
self.grid_layout.addWidget(b1_label, 4+offset, 1, 1, 1,
|
|
Qt.AlignVCenter | Qt.AlignHCenter)
|
|
b2_label = QLabel("B2 B3-B6")
|
|
self.grid_layout.addWidget(b2_label, 4+offset, 3, 1, 1,
|
|
Qt.AlignVCenter | Qt.AlignHCenter)
|
|
b7_label = QLabel("B7-B9")
|
|
self.grid_layout.addWidget(b7_label, 2+offset, 5, 1, 1,
|
|
Qt.AlignTop | Qt.AlignHCenter)
|
|
|
|
b10_label = QLabel("B10-B12")
|
|
self.grid_layout.addWidget(b10_label, 3+offset, 7, 1, 1,
|
|
Qt.AlignTop | Qt.AlignHCenter)
|
|
b13_label = QLabel("B13-B15 ")
|
|
self.grid_layout.addWidget(b13_label, 2+offset, 9, 1, 1,
|
|
Qt.AlignTop | Qt.AlignHCenter)
|
|
b16_label = QLabel("B16-B18 ")
|
|
self.grid_layout.addWidget(b16_label, 0+offset, 10, 1, 1,
|
|
Qt.AlignTop| Qt.AlignRight)
|
|
#b19_label = QLabel("B19 B20 ")
|
|
#self.grid_layout.addWidget(b19_label, 0+offset, 12, 1, 1,
|
|
# Qt.AlignTop | Qt.AlignRight)
|
|
|
|
if has_hbox_layout:
|
|
self.grid_layout.setSpacing(6)
|
|
else:
|
|
self.grid_layout.setSpacing(0)
|
|
self.grid_layout.setAlignment(Qt.AlignLeft)
|
|
self.grid_layout.setContentsMargins(5, 0, 5, 0)
|
|
|
|
self.header_wgt = QGroupBox()
|
|
self.header_wgt.setObjectName(self.user_mode.name)
|
|
if has_hbox_layout:
|
|
self.header_wgt.setLayout(self.hor_layout)
|
|
self.header_wgt.setFixedHeight(110)
|
|
else:
|
|
self.header_wgt.setLayout(self.grid_layout)
|
|
self.header_wgt.setFixedHeight(self.header_height)
|
|
|
|
title = "PROSCAN {0}".format(self.user_mode.name)
|
|
if self.title:
|
|
title += ": {0}".format(self.title)
|
|
if "Controlroom" not in self.assigned_master:
|
|
title += "@{0}".format(self.assigned_master)
|
|
self.header_wgt.setTitle(title)
|
|
|
|
self.target_beamline = None
|
|
|
|
self.timer = QTimer()
|
|
#self.timer.timeout.connect(lambda: self.blink_target_beamline(None))
|
|
self.timer.timeout.connect(self.blink_target_beamline)
|
|
self.timer.start(500)
|
|
self.timer_count = 0
|
|
|
|
self.master_to_wgt = {"Gantry 1": "G1", "Gantry 2": "G2",
|
|
"Gantry 3": "G3", "OPTIS2": "O2", "PIF": "PIF"}
|
|
|
|
# previously in src/gui.py of client HLA
|
|
|
|
self.sector_disruptor_dict = {}
|
|
self.sector_disruptor_dict["G1"] = "Geschlossen"
|
|
self.sector_disruptor_dict["SH"] = "Geschlossen"
|
|
self.sector_disruptor_dict["G2"] = "Geschlossen"
|
|
self.sector_disruptor_dict["O2"] = "Geschlossen"
|
|
self.sector_disruptor_dict["PIF"] = "Geschlossen"
|
|
self.sector_disruptor_dict["G3"] = "Geschlossen"
|
|
|
|
self.g3_line = ["SH", "PIF", "G3"]
|
|
self.pif_line = ["SH", "PIF"]
|
|
self.o2_line = ["SH", "O2"]
|
|
self.g2_line = ["SH", "G2"]
|
|
self.g1_line = ["G1"]
|
|
self.sh_line = ["SH"]
|
|
|
|
self.mastership = ""
|
|
|
|
try:
|
|
pv_master = self.settings.data["MASTER"]["status"]
|
|
self.mastership = self.cafe.getCache(pv_master)
|
|
self.check_status(_pymodule, "get", pv_master, None, _line())
|
|
except KeyError as ex:
|
|
print("KeyError: {0}".format(str(ex)))
|
|
|
|
|
|
self.toG1("OFF")
|
|
self.toBMA1("OFF")
|
|
self.toG3("OFF")
|
|
self.toPIF("OFF")
|
|
self.toO2("OFF")
|
|
self.toG2("OFF")
|
|
|
|
@Slot()
|
|
def receive_master_update(value, status, alarm_severity):
|
|
self.mastership = value
|
|
for key, wgt_val in self.master_to_wgt.items():
|
|
master = self.beam_current_wgt_group[wgt_val]
|
|
if value in key:
|
|
master.setObjectName("ARAMIS")
|
|
master.style().polish(master)
|
|
self.target_beamline = wgt_val
|
|
self.timer.start(750)
|
|
self.timer_count = 0
|
|
else:
|
|
# if "BEAMLINE" not in master.objectName():
|
|
# master.setObjectName("BEAMLINE")
|
|
# master.style().polish(master)
|
|
original_object = self.settings.data[
|
|
wgt_val]["colorObj"].upper()
|
|
if original_object not in master.objectName().upper():
|
|
master.setObjectName(original_object)
|
|
master.style().polish(master)
|
|
|
|
self.beam_current_wgt_dict[
|
|
wgt_val].trigger_monitor_str.emit(
|
|
self.sector_disruptor_dict[wgt_val], 1, 0)
|
|
#self.toPIF("ON")
|
|
#self.toG1("ON")
|
|
|
|
def enable_disable_beamline(sect, sector_line, value):
|
|
|
|
def reset_check_mini_post_sh():
|
|
# Redo "G2" in case first two elements
|
|
# are grayed by other beamlines
|
|
if "Offen" in (self.sector_disruptor_dict["G2"],
|
|
self.sector_disruptor_dict["O2"],
|
|
self.sector_disruptor_dict["PIF"]):
|
|
# self.sector_disruptor_dict["G3"]):
|
|
self.toSHOverlap("ON")
|
|
else:
|
|
self.toSHOverlap("OFF")
|
|
|
|
self.sector_disruptor_dict[sect] = value
|
|
#print("sect/value", sect, value)
|
|
for sector in sector_line:
|
|
|
|
action = "OFF" if "Geschlossen" in self.sector_disruptor_dict[
|
|
sector] else "ON"
|
|
|
|
if sector == "SH":
|
|
self.toSH(action)
|
|
if "Geschlossen" not in self.sector_disruptor_dict["G1"]:
|
|
self.toSH("OFF")
|
|
elif sector == "G1":
|
|
self.toG1(action)
|
|
if action == "ON":
|
|
self.toSH("OFF")
|
|
|
|
elif sector == "G2":
|
|
self.toG2(action)
|
|
reset_check_mini_post_sh()
|
|
elif sector == "O2":
|
|
self.toO2(action)
|
|
reset_check_mini_post_sh()
|
|
elif sector == "G3":
|
|
self.toG3(action)
|
|
elif sector == "PIF":
|
|
self.toPIF(action)
|
|
reset_check_mini_post_sh()
|
|
|
|
reset_check_mini_post_sh()
|
|
|
|
def receive_sh_update(value, status, alarm_severity):
|
|
enable_disable_beamline("SH", self.sh_line, value)
|
|
|
|
def receive_g1_update(value, status, alarm_severity):
|
|
enable_disable_beamline("G1", self.g1_line, value)
|
|
|
|
def receive_g3_update(value, status, alarm_severity):
|
|
enable_disable_beamline("G3", self.g3_line, value)
|
|
|
|
def receive_o2_update(value, status, alarm_severity):
|
|
enable_disable_beamline("O2", self.o2_line, value)
|
|
|
|
def receive_g2_update(value, status, alarm_severity):
|
|
enable_disable_beamline("G2", self.g2_line, value)
|
|
|
|
def receive_pif_update(value, status, alarm_severity):
|
|
enable_disable_beamline("PIF", self.pif_line, value)
|
|
|
|
self.beam_current_wgt_dict[
|
|
"G3"].trigger_monitor_str.connect(receive_g3_update)
|
|
self.beam_current_wgt_dict[
|
|
"O2"].trigger_monitor_str.connect(receive_o2_update)
|
|
self.beam_current_wgt_dict[
|
|
"G2"].trigger_monitor_str.connect(receive_g2_update)
|
|
self.beam_current_wgt_dict[
|
|
"PIF"].trigger_monitor_str.connect(receive_pif_update)
|
|
self.beam_current_wgt_dict[
|
|
"BMA1"].trigger_monitor_str.connect(receive_sh_update)
|
|
|
|
self.beam_current_wgt_dict[
|
|
"G1"].trigger_monitor_str.connect(receive_g1_update)
|
|
|
|
self.beam_current_wgt_dict[
|
|
"MASTER"].trigger_monitor_str.connect(receive_master_update)
|
|
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["G3"]["status"], dt="str")
|
|
receive_g3_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["PIF"]["status"], dt="str")
|
|
receive_pif_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["G2"]["status"], dt="str")
|
|
receive_g2_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["O2"]["status"], dt="str")
|
|
receive_o2_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["SH"]["status"], dt="str")
|
|
receive_sh_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["G1"]["status"], dt="str")
|
|
receive_g1_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
pvd = self.cafe.getPVCache(
|
|
self.settings.data["MASTER"]["status"], dt="str")
|
|
receive_master_update(pvd.value[0], pvd.alarmStatus, pvd.alarmSeverity)
|
|
|
|
def is_master(self):
|
|
return bool(self.assigned_master in self.mastership)
|
|
|
|
def color_pframe(self, color="#cccccc"):
|
|
for section in self.pframe_matrix:
|
|
#print(section, flush=True)
|
|
for key, value in self.pframe_matrix[section].items():
|
|
#print(key, value, "\n")
|
|
for key2, pf in value.items():
|
|
#print("===>", key2, pf, "\n", flush=True)
|
|
ss = pf.styleSheet()
|
|
#print(ss, flush=True)
|
|
start_idx = ss.index("#") if "#" in ss else 0
|
|
end_idx = ss.index(";") if ";" in ss else None
|
|
aa = ss[start_idx:end_idx]
|
|
#print(aa, flush=True)
|
|
if "green" in aa or self.pf_bgcolor() in aa:
|
|
#print("PASS", ss, self.pf_bgcolor(), flush=True)
|
|
pass
|
|
else:
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
def pf_bgcolor(self):
|
|
return "#cccccc"
|
|
|
|
def toG3(self, on_off: str = "ON"):
|
|
self.afterBMA1(on_off)
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for key, pf in self.pframe_matrix["PRE-G3"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for key, pf in self.pframe_matrix["O2"][11].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
def toSH(self, on_off: str = "ON"):
|
|
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for key, pf in self.pframe_matrix["G1"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
for key, pf in self.pframe_matrix["PRE-SH"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for i in range(3, 12):
|
|
pf = self.pframe_matrix["POST-BMA1"][15-i][i]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
#for i in range(7, 10):
|
|
# pf = self.pframe_matrix["POST-BMA1"][3][i]
|
|
# pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
#if self.sector_disruptor_dict["G1"] != "Geschlossen":
|
|
# self.toBMA1("ON")
|
|
# self.afterBMA1("ON")
|
|
#else:
|
|
self.toBMA1(on_off)
|
|
self.afterBMA1(on_off)
|
|
|
|
def afterBMA1(self, on_off: str = "ON"):
|
|
if self.sector_disruptor_dict["G1"] != "Geschlossen":
|
|
on_off = "ON"
|
|
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for i in range(0, 3):
|
|
pf = self.pframe_matrix["POST-BMA1"][13][i]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
def toBMA1(self, on_off: str = "ON"):
|
|
if self.sector_disruptor_dict["G1"] != "Geschlossen":
|
|
on_off = "ON"
|
|
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for key, pf in self.pframe_matrix["POST-COMET"][8].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
'''
|
|
for key, pf in self.pframe_matrix["G1"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for key, pf in self.pframe_matrix["PRE-SH"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
'''
|
|
|
|
def toSHOverlap(self, on_off: str = "ON"):
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
pf = self.pframe_matrix["POST-SH"][8][0]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["POST-SH"][8][1]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["POST-SH"][8][2]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
self.afterBMA1(on_off)
|
|
|
|
def toPIF(self, on_off: str = "ON"):
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for i in range(0, 5):
|
|
pf = self.pframe_matrix["POST-SH"][8 - i][i + 2]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for i in range(7, 10):
|
|
pf = self.pframe_matrix["POST-SH"][3][i]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for key, pf in self.pframe_matrix["G2"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for key, pf in self.pframe_matrix["PRE-O2"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
#for key, pf in self.pframe_matrix["O2"][11].items():
|
|
# pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
for key, pf in self.pframe_matrix["PRE-PIF"][3].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
val_amd2 = self.cafe.getCache("AMD2:SOL:2")
|
|
is_closed = self.cafe.getCache("BMD1:STA:2")
|
|
color = self.pf_bgcolor()
|
|
|
|
if val_amd2 is not None and is_closed is not None:
|
|
if "Geschlossen" in is_closed:
|
|
color = self.pf_bgcolor()
|
|
else:
|
|
if val_amd2 > 0.0:
|
|
color = "green"
|
|
|
|
for i in range(5, 8):
|
|
pf = self.pframe_matrix["O2"][5][i]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["O2"][6][4]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["O2"][7][3]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["O2"][8][2]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["O2"][9][1]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
pf = self.pframe_matrix["O2"][10][0]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
self.toSHOverlap(on_off)
|
|
self.afterBMA1(on_off)
|
|
|
|
def toO2(self, on_off: str = "ON"):
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for key, pf in self.pframe_matrix["POST-SH"][8].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for key, pf in self.pframe_matrix["G2"][8].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for key, pf in self.pframe_matrix["PRE-O2"][8].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
self.afterBMA1(on_off)
|
|
|
|
def toG1(self, on_off: str = "ON"):
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for key, pf in self.pframe_matrix["POST-BMA1"][13].items():
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
|
|
self.afterBMA1(on_off)
|
|
|
|
|
|
def toG2(self, on_off: str = "ON"):
|
|
|
|
color = "green" if on_off == "ON" else self.pf_bgcolor()
|
|
for i in range(0, 5):
|
|
pf = self.pframe_matrix["POST-SH"][8 + i][i + 2]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
for i in range(7, 10):
|
|
pf = self.pframe_matrix["POST-SH"][13][i]
|
|
pf.setStyleSheet("background-color:{0};".format(color))
|
|
self.toSHOverlap(on_off)
|
|
self.afterBMA1(on_off)
|
|
|
|
def blink_target_beamline(self):
|
|
target = self.target_beamline
|
|
if target is None:
|
|
return
|
|
self.target_beamline = target
|
|
self.timer_count += 1
|
|
if self.timer_count < 2:
|
|
return
|
|
if self.timer_count % 2 == 0:
|
|
self.reset_beamline()
|
|
else:
|
|
self.set_target_beamline(reset=False)
|
|
if self.timer_count > 8:
|
|
self.timer.stop()
|
|
QApplication.processEvents()
|
|
|
|
def set_target_beamline(self, reset=True):
|
|
""" Select beamline target and modify color scheme accordinly
|
|
"""
|
|
master = self.beam_current_wgt_group[self.target_beamline]
|
|
master.setObjectName("ARAMIS")
|
|
master.style().polish(master)
|
|
|
|
if reset:
|
|
self.reset_beamline()
|
|
|
|
def reset_beamline(self):
|
|
""" Reset QGroupBox for previous target to original colors
|
|
"""
|
|
|
|
master = self.beam_current_wgt_group[self.target_beamline]
|
|
|
|
#if "BEAMLINE" not in master.objectName():
|
|
# master.setObjectName("BEAMLINE")
|
|
# master.style().polish(master)
|
|
original_object = self.settings.data[
|
|
self.target_beamline]["colorObj"].upper()
|
|
if original_object not in master.objectName().upper():
|
|
master.setObjectName(original_object)
|
|
master.style().polish(master)
|
|
|
|
def reset_operation_mode(self):
|
|
""" Reset header colors to application operation mode
|
|
"""
|
|
self.change_operation_mode(user_mode=self.user_mode)
|
|
|
|
def change_operation_mode(self, user_mode=UserMode.OPERATION):
|
|
""" Different operation modes have different color schemes
|
|
"""
|
|
title_name = user_mode.name
|
|
dry_run_tags = ["HUSH", "Dry"]
|
|
#print('title', self.header_wgt.title(), flush=True)
|
|
|
|
if any([x in self.header_wgt.title() for x in dry_run_tags]):
|
|
title_name = "DRY RUN" if user_mode.name == "SIMULATION" \
|
|
else user_mode.name
|
|
|
|
self.header_wgt.setObjectName(user_mode.name)
|
|
self.header_wgt.setTitle(self.header_wgt.title().replace(
|
|
self.current_user_mode_name, title_name))
|
|
self.header_wgt.style().polish(self.header_wgt)
|
|
self.current_user_mode_name = title_name
|
|
|
|
def beam_current_widget(self, header: str = "", pv: str = "",
|
|
color_obj: str = "MACHINE"):
|
|
""" QGroupBox encompassing beam current info
|
|
"""
|
|
station = QGroupBox()
|
|
station.setObjectName(color_obj.upper())
|
|
station.style().polish(station)
|
|
|
|
#print("===============>",header, station.objectName())
|
|
station.setAlignment(Qt.AlignmentFlag(Qt.AlignHCenter | Qt.AlignTop))
|
|
station.setFlat(False)
|
|
# if header == "SH":
|
|
# station.setTitle("BMA1 SH")
|
|
# else:
|
|
hertz = 2 if header == "COMET" else 0
|
|
|
|
with_sub_master = False
|
|
|
|
if header == "SH":
|
|
beam_current = QLabel("SH ")
|
|
beam_current.setStyleSheet("font-weight: bold;")
|
|
beam_current.setAlignment(Qt.AlignmentFlag(Qt.AlignTop|Qt.AlignHCenter))
|
|
extra_height = 15
|
|
extra_width = 0
|
|
else:
|
|
extra_height = self.extra_height
|
|
extra_width = 15
|
|
station.setTitle(header)
|
|
beam_current = CAQLabel(
|
|
self, pv_name=pv, show_units=True, notify_freq_hz=hertz)
|
|
if header == "MASTER" and with_sub_master:
|
|
sub_master = CAQLabel(
|
|
self, pv_name=pv, show_units=True, notify_freq_hz=hertz)
|
|
sub_master.setFixedHeight(self.widget_height)
|
|
sub_master.setFixedWidth(140)
|
|
extra_width += 140
|
|
|
|
beam_current.setFixedHeight(self.widget_height)
|
|
|
|
if header == "MASTER":
|
|
beam_current.setFixedWidth(140)
|
|
elif header == "SH":
|
|
beam_current.setFixedWidth(80)
|
|
else:
|
|
beam_current.setFixedWidth(100)
|
|
|
|
grid_layout = QGridLayout()
|
|
grid_layout.addWidget(beam_current, 0, 0, 1, 1, Qt.AlignCenter)
|
|
|
|
if header == "MASTER" and with_sub_master:
|
|
grid_layout.addWidget(sub_master, 0, 1, 1, 1, Qt.AlignCenter)
|
|
|
|
grid_layout.setVerticalSpacing(0)
|
|
grid_layout.setHorizontalSpacing(0)
|
|
if header == "SH":
|
|
grid_layout.setContentsMargins(0, 2, 0, 2)
|
|
else:
|
|
grid_layout.setContentsMargins(2, 9, 2, 0)
|
|
|
|
station.setLayout(grid_layout)
|
|
station.setFixedHeight(beam_current.height() + extra_height)
|
|
station.setFixedWidth(beam_current.width() + extra_width)
|
|
self.beam_current_wgt_dict[header] = beam_current
|
|
self.beam_current_wgt_group[header] = station
|
|
return station
|