Make skin display default

This commit is contained in:
2025-04-24 16:06:38 +02:00
parent 18c59e1894
commit 4772485231

View File

@@ -54,9 +54,29 @@ class AppGui(QWidget):
self.send_to_log_window = self.parent.send_to_log_window
self.show_log_message = self.parent.show_log_message
self.statusbar = self.parent.statusbar
self.settings = self.parent.settings
self.gui_frame = self.parent.gui_frame
self.gui_header = self.parent.gui_header
self.simple_standby = None
self.simple_awake = None
self.simple_status = None
self.simple_groupbox = None
self.groupbox_awake_sss = self.settings.data[
'statusStyleSheet']['awake-qgroupbox']
self.groupbox_standby_sss = self.settings.data[
'statusStyleSheet']['standby-qgroupbox']
self.label_awake_sss = self.settings.data[
'statusStyleSheet']['awake-qlabel']
self.label_standby_sss = self.settings.data[
'statusStyleSheet']['standby-qlabel']
self.awake_text = self.settings.data[
'statusStyleSheet']['awake-text']
self.standby_text = self.settings.data[
'statusStyleSheet']['standby-text']
self.font_gui = self.parent.gui_frame.font_gui
self.input_parameters = self.parent.input_parameters
self.input_labels = self.parent.input_labels
@@ -74,12 +94,16 @@ class AppGui(QWidget):
self.gui_frame.central_tab_widget.tabBar().setTabText(1, "IOC")
self.expert_labels = self.parent.expert_labels
self.settings = self.parent.settings
self.lock = threading.Lock()
self.timer = QTimer()
self.timer.setSingleShot(True)
self.timer_blink = QTimer()
self.timer_blink.setSingleShot(True)
self.timer_blink.count = 0
self.obj_to_upper = bool(random.randint(1, 10) > 3)
self.table_sol_dict = {}
@@ -113,6 +137,8 @@ class AppGui(QWidget):
for sector in self.settings.data["header"][idx:]:
self.sectorI_dict[sector] = 0
self.simple_sector_list = self.settings.data["header"][idx:]
self.sector_designated_magnet_standby_dict = {}
self.sector_designated_magnet_values_dict = {}
@@ -136,6 +162,24 @@ class AppGui(QWidget):
status_wgt, 2, 0, 2, 1, alignment=Qt.AlignTop) # | Qt.AlignHCenter)
self.groupbox_simple_mode = self.group_simple_mode()
qgridlo = QGridLayout()
qgridlo.setContentsMargins(5, 30, 5, 10)
qgridlo.addWidget(self.groupbox_simple_mode, 0, 0, 1, 1, Qt.AlignCenter)
qgridlo.setAlignment(Qt.AlignTop | Qt.AlignHCenter)
qgridlo.setVerticalSpacing(10)
qwgt = QWidget()
qwgt.setLayout(qgridlo)
qwgt.setFixedWidth(1400)
qwgt.setFixedHeight(800)
self.gui_frame.central_tab_widget.insertTab(0, qwgt, "Skin")
self.gui_frame.central_tab_widget.setCurrentIndex(0)
self.gui_frame.results_wgt.setFixedWidth(1500)
self.gui_frame.results_wgt.setFixedHeight(860)
self.gui_frame.results_wgt.setLayout(self.gui_frame.results_layout)
@@ -202,6 +246,7 @@ class AppGui(QWidget):
for sector in sector_line:
beam_req_flag = False
idx = self.simple_sector_list.index(sector)
if sector == "UCN":
beam_req_flag = self.beam_req_running #is_beam_req_running()
@@ -233,15 +278,20 @@ class AppGui(QWidget):
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
if self.simple_standby:
self.simple_standby[idx].setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
if self.simple_standby:
self.simple_standby[idx].setEnabled(True)
def enable_disable_end(sect, sector_line, value):
self.sectorI_dict[sect] = value
for sector in sector_line:
idx = self.simple_sector_list.index(sector)
# if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
# 'SINQ'] > self.I_min:
if self.sectorI_dict[sector] > self.I_min:
@@ -249,11 +299,15 @@ class AppGui(QWidget):
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
if self.simple_standby:
self.simple_standby[idx].setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
if self.simple_standby:
self.simple_standby[idx].setEnabled(True)
def enable_disable_pk(sect, sector_line, value):
self.sectorI_dict[sect] = value
@@ -261,6 +315,7 @@ class AppGui(QWidget):
#print("==>sector firing", sect, "with value", value)
for sector in sector_line:
idx = self.simple_sector_list.index(sector)
#print("sector", sector, "in line", sector_line,
# "has value", self.sectorI_dict[sector]
#)
@@ -271,11 +326,15 @@ class AppGui(QWidget):
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
if self.simple_standby:
self.simple_standby[idx].setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
if self.simple_standby:
self.simple_standby[idx].setEnabled(True)
def receive_ucnq_update(value, status, alarm_severity):
del status, alarm_severity
@@ -414,8 +473,42 @@ class AppGui(QWidget):
pv_standby_dict[pv_magnet] = standby_value
return pv_standby_dict
def is_sector_standby(self, sector, pv_name, value):
self.sector_designated_magnet_values_dict[sector][pv_name] = value
def is_sector_standby(self, sector, pv_name=None, value=None):
idx = self.simple_sector_list.index(sector)
text_color = self.settings.data[sector]["color"]
text_color_str = f'color: {text_color};'
def paint_awake():
sss = ('QGroupBox {background-color:#ffe87c; font-weight: bold; ' +
text_color_str + '}')
self.simple_groupbox[idx].setStyleSheet(sss)
self.simple_status[idx].setStyleSheet(
'QLabel{color:black; font-weight: bold;}')
self.simple_groupbox[idx].setStyleSheet(sss) #self.groupbox_awake_sss)
self.simple_status[idx].setText('Status: AWAKE')
self.status_dict[sector].setStyleSheet(self.label_awake_sss)
self.status_dict[sector].setText(self.awake_text) #self.settings.data['statusStyleSheet']['awake-text'])
def paint_asleep():
sss = ('QGroupBox {background-color:#546bab; font-weight: bold; ' +
text_color_str + '}')
self.simple_groupbox[idx].setStyleSheet(sss)
self.simple_status[idx].setStyleSheet(
'QLabel{color:white; font-weight: bold;}')
self.simple_groupbox[idx].setStyleSheet(sss) #self.groupbox_standby_sss)
self.simple_status[idx].setText('Status: STANDBY')
self.status_dict[sector].setStyleSheet(self.label_standby_sss)
self.status_dict[sector].setText(self.standby_text) #self.settings.data['statusStyleSheet']['standby-text'])
if value and pv_name:
self.sector_designated_magnet_values_dict[sector][pv_name] = value
#print(self.sector_designated_magnet_values_dict[sector], flush=True)
is_standby = True
for pv in self.sector_designated_magnet_values_dict[sector]:
@@ -445,6 +538,8 @@ class AppGui(QWidget):
):
self.table_pwr_dict[sector].init_value_button.setEnabled(
True)
if self.simple_awake:
paint_awake()
else:
if self.table_sol_dict[sector].init_value_button.isEnabled():
self.table_sol_dict[sector].init_value_button.setEnabled(
@@ -452,7 +547,10 @@ class AppGui(QWidget):
if self.table_pwr_dict[sector].init_value_button.isEnabled():
self.table_pwr_dict[sector].init_value_button.setEnabled(
False)
if self.simple_standby:
paint_asleep()
return is_standby
@Slot(float, int, int)
def designated_magnet_cb(self, value, status, alarm_severity):
@@ -494,6 +592,12 @@ class AppGui(QWidget):
qsa.setFont(f)
qsa.setAlignment(Qt.AlignCenter)
qstat = QLabel("Status \n ")
f = qstat.font()
f.setPixelSize(13)
qstat.setFont(f)
qstat.setAlignment(Qt.AlignCenter)
qti = QLabel("Time in \nSaving Mode")
f = qti.font()
f.setPixelSize(13)
@@ -508,22 +612,29 @@ class AppGui(QWidget):
qgrid.addWidget(qlp, 0, 2, 1, 1)
qgrid.addWidget(qsa, 0, 3, 1, 1)
qgrid.addWidget(qti, 0, 4, 1, 1)
qgrid.addWidget(qtotsav, 0, 5, 1, 1)
qgrid.addWidget(qstat, 0, 4, 1, 1)
qgrid.addWidget(qti, 0, 5, 1, 1)
qgrid.addWidget(qtotsav, 0, 6, 1, 1)
self.status_dict = {}
for i, sector in enumerate(self.settings.data["header"][idx:]):
a, b, c, d, e, f = self.sector_status(sector)
self.status_dict[sector] = QLabel('')
a.setContentsMargins(2, 0, 0, 0)
qgrid.addWidget(a, i + 1, 0, 1, 1)
qgrid.addWidget(b, i + 1, 1, 1, 1)
qgrid.addWidget(c, i + 1, 2, 1, 1)
qgrid.addWidget(d, i + 1, 3, 1, 1)
qgrid.addWidget(e, i + 1, 4, 1, 1)
qgrid.addWidget(f, i + 1, 5, 1, 1)
qgrid.addWidget(self.status_dict[sector], i + 1, 4, 1, 1)
qgrid.addWidget(e, i + 1, 5, 1, 1)
qgrid.addWidget(f, i + 1, 6, 1, 1)
qh_line = QHLine()
qh_line.setFixedHeight(10)
row = qgrid.rowCount()
qgrid.addWidget(qh_line, row, 1, 1, 5)
qgrid.addWidget(qh_line, row, 1, 1, 7)
#qgrid.setRowMinimumHeight(row, 60)
qtot = QLabel("Total:")
@@ -538,11 +649,11 @@ class AppGui(QWidget):
CAQLineEdit(self, pv_name="ZHIPA-HUSH:TOTPWR", show_units=True),
row + 1, 2, 1, 1)
qgrid.addWidget(
CAQLineEdit(self, pv_name="ZHIPA-HUSH:LASTSAVE", show_units=False),
row + 1, 3, 1, 1)
CAQLineEdit(self, pv_name="ZHIPA-HUSH:LASTSAVE", show_units=True),
row + 1, 3, 1, 2)
qgrid.addWidget(
CAQLineEdit(self, pv_name="ZHIPA-HUSH:TOTSAVE", show_units=False),
row + 1, 5, 1, 1)
CAQLineEdit(self, pv_name="ZHIPA-HUSH:TOTSAVE", show_units=True),
row + 1, 6, 1, 2)
qgrid.setContentsMargins(9, 20, 9, 9)
@@ -550,7 +661,7 @@ class AppGui(QWidget):
qw.setContentsMargins(9, 9, 9, 9)
qw.setObjectName("OUTER")
qw.setLayout(qgrid)
qw.setFixedWidth(496) # 480
qw.setFixedWidth(596) # 496
qw.setFixedHeight(346) # 480
return qw
@@ -837,6 +948,10 @@ class AppGui(QWidget):
self.table_pwr_dict[sector].init_value_button.setEnabled(False)
table.init_value_button.setEnabled(False)
self.timer_blink.singleShot(
250, lambda: self.blink_target_beamline(sector, standby=True))
def on_sector_restore(self):
target = self.sender()
sector = target.sector
@@ -856,6 +971,9 @@ class AppGui(QWidget):
#stat = self.cafe.set(pv, 1)
#self.check_status(pv, stat, _line())
self.timer_blink.singleShot(
250, lambda: self.blink_target_beamline(sector, standby=False))
table_pwr = self.table_pwr_dict[sector]
row_pwr_dict = table_pwr.get_init_values()
sum_pwr = sum(list(row_pwr_dict.values()))
@@ -1397,3 +1515,160 @@ class AppGui(QWidget):
qw.setFixedHeight(280)
return qw
def group_simple_mode(self):
self.simple_status = [None] * len(self.simple_sector_list)
self.simple_standby = [None] * len(self.simple_sector_list)
self.simple_awake = [None] * len(self.simple_sector_list)
self.simple_groupbox = [None] * len(self.simple_sector_list)
qgrido = QGridLayout()
qwo = QGroupBox('Skin View')
hlength = 3
irow = 0
icolumn = 0
for i, sector in enumerate(self.simple_sector_list):
self.simple_status[i] = QLabel(' Status: ')
pv = 'Z' + sector + '-HUSH:TOTPWR'
print('pv=', pv, flush=True)
power = CAQLabel(self, pv, show_units=True, notify_freq_hz=1)
self.simple_standby[i] = QPushButton(' Standby ')
self.simple_standby[i].sector = sector
self.simple_standby[i].setObjectName('Controller')
self.simple_standby[i].setProperty('actOnBeam', True)
self.simple_standby[i].setToolTip(
('Restore devices to their standby values'))
self.simple_standby[i].clicked.connect(self.on_sector_standby)
self.simple_awake[i] = QPushButton(' Awake ')
self.simple_awake[i].sector = sector
self.simple_awake[i].setObjectName('Controller')
self.simple_awake[i].setProperty('actOnBeam', True)
self.simple_awake[i].setToolTip(
('Restore devices to their pre-standby values'))
self.simple_awake[i].clicked.connect(self.on_sector_restore)
qgrid = QGridLayout()
qgrid.addWidget(self.simple_status[i], 0, 0, 1, 1, Qt.AlignCenter)
qgrid.addWidget(power, 0, 1, 1, 1, Qt.AlignLeft)
qgrid.addWidget(self.simple_standby[i], 1, 0, 1, 1, Qt.AlignCenter)
qgrid.addWidget(self.simple_awake[i], 1, 1, 1, 1, Qt.AlignCenter)
qgrid.setContentsMargins(5, 20, 5, 0)
self.simple_groupbox[i] = QGroupBox(sector)
self.simple_groupbox[i].setContentsMargins(5, 0, 5, 0)
self.simple_groupbox[i].setAlignment(Qt.AlignCenter)
self.simple_groupbox[i].setObjectName("OUTER")
text_color = self.settings.data[sector]["color"]
text_color_str = f'color: {text_color}; '
sss = ("QGroupBox {" + text_color_str + "font-weight: bold;}")
self.simple_groupbox[i].setStyleSheet(sss)
self.simple_groupbox[i].setLayout(qgrid)
self.simple_groupbox[i].setFixedWidth(270) #280
self.simple_groupbox[i].setFixedHeight(140) #140
irow = 0 if i < (hlength) else 1
icolumn = i%hlength # if i < (hlength) else int(i - hlength)
qgrido.addWidget(self.simple_groupbox[i], irow, icolumn, 1, 1,
Qt.AlignCenter)
#message = ""
#ql = QLabel(message)
#ql.setStyleSheet('QLabel {color:black;}')
#ql.setAlignment(Qt.AlignHCenter|Qt.AlignBottom)
#cspan = qgrido.columnCount()
#qgrido.addWidget(ql, irow+1, 0, 2, cspan,
# Qt.AlignHCenter|Qt.AlignBottom)
qgrido.setContentsMargins(5, 15, 5, 15)
qgrido.setAlignment(Qt.AlignCenter)
qgrido.setVerticalSpacing(20)
qgrido.setHorizontalSpacing(25)
qwo.setContentsMargins(5, 15, 5, 10)
qwo.setAlignment(Qt.AlignCenter)
qwo.setObjectName("OUTER")
qwo.setLayout(qgrido)
wlength = len(self.simple_sector_list) if irow == 0 else int(hlength)
qwo.setFixedWidth(310 * wlength)
qwo.setFixedHeight(240 * (irow+1) - 80*irow)
return qwo
def blink_target_beamline(self, sector, standby=False):
idx = self.simple_sector_list.index(sector)
text_color = self.settings.data[sector]["color"]
text_color_str = f'color: {text_color};'
#Deactivate
standby_enabled = self.simple_standby[idx].isEnabled()
awake_enabled = self.simple_awake[idx].isEnabled()
self.simple_standby[idx].setEnabled(False)
self.simple_awake[idx].setEnabled(False)
is_standby = self.is_sector_standby(sector, None, None)
ready = False
if (standby and not is_standby) or (not standby and is_standby):
endpt = 0 if standby else 1
ramping = 'Ramping down \u21D3' if standby else 'Ramping up \u21D1'
self.simple_status[idx].setText(ramping)
end = 14 #must be even no
for i in range(0, end):
if i%2 == endpt:
sss = ('QGroupBox {background-color:#ffe87c; font-weight: bold; ' +
text_color_str + '}')
self.simple_status[idx].setStyleSheet(
'QLabel{color:black; font-weight: bold;}')
else:
sss = ('QGroupBox {background-color:#546bab;; font-weight: bold; ' +
text_color_str + '}')
self.simple_status[idx].setStyleSheet(
'QLabel{color:white; font-weight: bold;}')
self.simple_groupbox[idx].setStyleSheet(sss)
#self.simple_status[idx].setText('Status: AWAKE')
#self.simple_status[idx].setStyleSheet(
# 'QLabel{color:black; font-weight: bold;}')
self.simple_status[idx].setText(ramping)
QApplication.processEvents()
time.sleep(0.5)
is_standby = self.is_sector_standby(sector, None, None)
if standby and is_standby:
ready = True
break;
elif not standby and not is_standby:
ready = True
break;
#Activate
#if not ready:
self.simple_standby[idx].setEnabled(standby_enabled)
self.simple_awake[idx].setEnabled(awake_enabled)
pv = self.settings.data[sector]['device'][0] + ":SOL:2.PROC"
stat = self.cafe.set(pv, 1)
self.check_status(_pymodule, "set", pv, stat, _line())
QApplication.processEvents()