Initial commit

This commit is contained in:
2023-05-01 10:40:03 +02:00
commit 0ff63ddb4a
31 changed files with 3782 additions and 0 deletions
Binary file not shown.
+705
View File
@@ -0,0 +1,705 @@
import inspect
import os
import platform
import random
import sys
import time
from datetime import timedelta
from qtpy import QtCore, QtGui
from qtpy.QtGui import QColor, QFont, QIcon
from qtpy.QtCore import __version__ as QT_VERSION_STR
from qtpy.QtCore import (
PYQT_VERSION_STR, QDate, QDateTime, QEventLoop, Qt, Signal, Slot)
from qtpy.QtWidgets import (
QApplication, QDockWidget, QFrame, QGridLayout, QGroupBox, QHBoxLayout,
QLabel, QMainWindow, QMessageBox, QProgressBar, QPushButton, QSizePolicy,
QSpacerItem, QStackedWidget, QTabBar, QTabWidget, QTableWidget,
QTableWidgetItem, QVBoxLayout, QWidget)
from apps4ops.bdbase.base import BaseWindow
from apps4ops.bdbase.enumkind import MsgSeverity, UserMode, Facility
from caqtwidgets.pvwidgets import CAQLabel, CAQLineEdit, CAQTableWidget, QHLine
_pymodule = os.path.basename(__file__)
def _line():
"""Macro to return the current line number.688
The current line number within the file is used when
reporting messages to the message logging window.
Returns:
int: Current line number.
"""
return inspect.currentframe().f_back.f_lineno
class AppGui(QWidget):
def __init__(self, parent):
super(AppGui, self).__init__()
self.parent = parent
self.cafe = self.parent.cafe
self.cyca = self.parent.cyca
self.gui_frame = self.parent.gui_frame
self.gui_header = self.parent.gui_header
self.font_gui = self.parent.gui_frame.font_gui
self.input_parameters = self.parent.input_parameters
self.input_labels = self.parent.input_labels
self.expert_parameters = self.parent.expert_parameters
self.gui_frame.expert_parameters_group.setFixedWidth(260)
self.gui_frame.operator_parameters_group.setFixedWidth(260)
#self.gui_frame.operator_parameters_group.setFixedHeight(260)
self.gui_frame.measurement_tab_wgt.setMinimumWidth(440)
self.gui_frame.measurement_tab_wgt.setFixedHeight(280)
#self.gui_frame.operator_wgt.setFixedHeight(240)
#self.gui_frame.expert_wgt.setFixedHeight(240)
self.gui_frame.central_tab_widget.tabBar().setTabText(0, "Control")
self.gui_frame.central_tab_widget.tabBar().setTabText(1, "Savings")
self.expert_labels = self.parent.expert_labels
self.settings = self.parent.settings
self.obj_to_upper = True if random.randint(1, 10) > 3 else False
self.table_sol_dict = {}
self.table_pwr_dict = {}
self.offtime_dict = {}
wgt = self.group_sector_qtabwidget()
self.gui_frame.measurement_layout.addWidget(
wgt, 0, 1, 6, 3, alignment=Qt.AlignTop)
status_wgt = self.group_sector_status()
self.gui_frame.measurement_layout.addWidget(
status_wgt, 2, 0, 2, 1, alignment=Qt.AlignTop) # | Qt.AlignHCenter)
qf = QFrame()
qf.setFixedHeight(6)
self.gui_frame.measurement_layout.addWidget(
qf, 4, 0, 1, 1, alignment=Qt.AlignTop)
self.sectorI_dict = {}
self.sectorI_dict['IP2'] = 0
self.sectorI_dict['IW2'] = 0
self.sectorI_dict['PK1'] = 0
self.sectorI_dict['PK2'] = 0
self.sectorI_dict['SINQ'] = 0
self.sectorI_dict['UCN'] = 0
self.I_min = 0.009
ucn_line = ["PK1", "PK2"]
sinq_line = ["PK1", "PK2"]
pk1_line = ["IW2"]
pk2_line = ["IW2"]
def enable_disable_end(sector, sector_line, value):
self.sectorI_dict[sector] = value
for sector in sector_line:
if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
'SINQ'] > self.I_min:
if self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
def enable_disable_pk(sector, sector_line, value):
self.sectorI_dict[sector] = value
for sector in sector_line:
if self.sectorI_dict['PK1'] > self.I_min or self.sectorI_dict[
'PK2'] > self.I_min:
if self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
def receive_ucn_update(value, status, alarm_severity):
enable_disable_end('UCN', ucn_line, value)
def receive_sinq_update(value, status, alarm_severity):
enable_disable_end('SINQ', sinq_line, value)
def receive_pk1_update(value, status, alarm_severity):
enable_disable_pk('PK1', pk1_line, value)
def receive_pk2_update(value, status, alarm_severity):
enable_disable_pk('PK2', pk2_line, value)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_ucn_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_sinq_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_pk1_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_pk2_update)
#self.cafe.monitor("MWC2:IST:2", cb)
#print(dir(self.gui_header.header_wgt.layout().widget()), flush=True)
def group_sector_status(self):
qgrid = QGridLayout()
#Connect all channels
#Heading
idx = self.settings.data["header"].index("IP2")
#Sector
qlp = QLabel("Power \n(kW)")
f = qlp.font()
f.setPixelSize(13)
qlp.setFont(f)
qlp.setAlignment(Qt.AlignCenter)
qli = QLabel("Initial \n(kW)")
f = qli.font()
f.setPixelSize(13)
qli.setFont(f)
qli.setAlignment(Qt.AlignCenter)
qgrid.addWidget(qli, 0, 1, 1, 1)
qsa = QLabel("Saving \n(MWh)")
f = qsa.font()
f.setPixelSize(13)
qsa.setFont(f)
qsa.setAlignment(Qt.AlignCenter)
qti = QLabel("Time \nin Standby")
f = qti.font()
f.setPixelSize(13)
qti.setFont(f)
qti.setAlignment(Qt.AlignCenter)
qtotsav = QLabel("Tot Saved \n(MWh)")
f = qtotsav.font()
f.setPixelSize(13)
qtotsav.setFont(f)
qtotsav.setAlignment(Qt.AlignCenter)
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)
for i, sector in enumerate(self.settings.data["header"][idx:]):
a, b, c, d, e, f = self.sector_status(sector)
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)
_line = QHLine()
_line.setFixedHeight(10)
_row = qgrid.rowCount()
qgrid.addWidget(_line, _row, 1, 1, 5)
#qgrid.setRowMinimumHeight(_row, 60)
qtot = QLabel("Total:")
f = qtot.font()
f.setPixelSize(13)
qtot.setFont(f)
qgrid.addWidget(qtot, _row+1, 0, 1, 1)
qgrid.addWidget(
CAQLineEdit(self, pv_name="HUSH:TOTPWR", show_units=True),
_row+1, 2, 1, 2)
qgrid.addWidget(
CAQLineEdit(self, pv_name="HUSH:TOTSAVE", show_units=False),
_row+1, 5, 1, 1)
qgrid.setContentsMargins(9, 20, 9, 9)
qw = QGroupBox("Savings Overview")
qw.setContentsMargins(9, 9, 9, 9)
qw.setObjectName("OUTER")
qw.setLayout(qgrid)
qw.setFixedWidth(490) #480
return qw
def sector_status(self, sector):
'''Create each sector line for inclusion into group
'''
device = "SEC-" + sector
#Qlabel
qsector = QLabel(sector+":")
f = qsector.font()
f.setPixelSize(13)
qsector.setFont(f)
_color = "black"
try:
_color = self.settings.data[sector]["color"]
except KeyError as ex:
print(ex, self.settings.data[sector])
_color_str = "color : {0};".format(_color)
_incolor = "QLabel {" + _color_str + "}"
qsector.setStyleSheet(_incolor)
#Savings
pv_pwr_tot = device + ":TOTPWR"
pv_pwr_last = device + ":LASTPWR"
pv_pwr_saved = device + ":LASTSAVE"
pv_pwr_timeout = device + ":OFFTIME"
pv_pwr_totsave = device + ":TOTSAVE"
self.cafe.openPrepare()
self.cafe.open([pv_pwr_tot, pv_pwr_last, pv_pwr_saved, pv_pwr_timeout])
self.cafe.openNowAndWait(2.0)
time.sleep(0.5)
#print("device", device, flush=True)
def cb_outtime(handle, pv, pvdata):
#print("cb", pv, handle, pvdata.value[0])
#_off = 6000000
_delta = "{}".format(str(timedelta(seconds=(pvdata.value[0]))))
if ", " in _delta:
_split = _delta.split(", ")
if len(_split[1]) == len("0:00:00"):
_delta = _split[0] + ", " + _split[1]
if 'days,' in _delta:
_delta = _delta.replace("days,", "d")
elif 'day,' in _delta:
_delta = _delta.replace("day,", "d")
try:
self.offtime_dict[pv].setText(_delta)
except KeyError:
pass
now = QDateTime.currentDateTime()
xdate = QDate(now.date().year(), 1, 15)
xstart = QDateTime(xdate)
#print("delta t ", xstart.secsTo(now))
#print("{}".format(str(timedelta(seconds=xstart.secsTo(now)))))
qpinit = CAQLineEdit(self, pv_name=pv_pwr_last, show_units=False)
qpnow = CAQLineEdit(self, pv_name=pv_pwr_tot, show_units=False)
qpsave = CAQLineEdit(self, pv_name=pv_pwr_saved, show_units=False)
qptotsave = CAQLineEdit(self, pv_name=pv_pwr_totsave, show_units=False)
qptime = CAQLineEdit(self, pv_name=pv_pwr_timeout,
monitor_callback=cb_outtime, show_units=True)
self.offtime_dict[pv_pwr_timeout] = qptime
qptime.setFixedWidth(104)
#qtdis = QBasicTimer()
#qpnow.setAlignment(Qt.AlignRight)
#qpnow.style().polish(qpnow)
return qsector, qpinit, qpnow, qpsave, qptime, qptotsave
def group_sector_qtabwidget(self):
idx_inj = self.settings.data["header"].index("INJ2")
idx = self.settings.data["header"].index("IP2")
#open all PVS
pv = []
for sector in self.settings.data["header"][idx_inj:]:
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
for att in attribute_list:
for dev in device_list:
pv.append(dev + ":" + att)
self.cafe.openPrepare()
self.cafe.open(pv)
self.cafe.openNowAndWait(1.0)
#self.cafe.supplementHandles()
sector_wgt_dict = {}
sector_wgt_dict["INJ2"] = self.ca_table_rf_widget(sector="INJ2")
for sector in self.settings.data["header"][idx:]:
sector_wgt_dict[sector] = self.ca_table_sector_widget(sector=sector)
sector_tab_widget = QTabWidget()
sector_tab_widget.setFont(self.font_gui)
sector_tab_widget.setStyleSheet("QTabBar {font-size: 12pt;}")
sector_tab_widget.tabBar().setShape(QTabBar.TriangularNorth)
for i, sector in enumerate(self.settings.data["header"][idx:]):
#if sector == "INJ2":
# _title = "RF"
#else:
# _title = sector
sector_tab_widget.addTab(sector_wgt_dict[sector], sector)
color = self.settings.data[sector]["color"]
sector_tab_widget.tabBar().setTabTextColor(i, QColor(color))
sector_tab_widget.addTab(sector_wgt_dict["INJ2"], "RF")
color = self.settings.data["INJ2"]["color"]
sector_tab_widget.tabBar().setTabTextColor(
len(self.settings.data["header"][idx:]), QColor(color))
return sector_tab_widget
def ca_table_rf_widget(self, sector: str="", color: str="MACHINE"):
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
pv_dict = {}
for att in attribute_list:
pv_dict[att] = [] #[None] * len(device_list)
for dev in device_list:
pv_dict[att].append(dev + ":" + att)
table_pwr = [None] * 2
table_pwr[0] = CAQTableWidget(
self, pv_list=pv_dict['IST:2'][0:4], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, pv_list_show=device_list[0:4])
table_pwr[1] = CAQTableWidget(
self, pv_list=pv_dict['IST:2'][4:], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, pv_list_show=device_list[4:])
for tab in table_pwr:
header_item = QTableWidgetItem()
header_init = QTableWidgetItem()
header_standby = QTableWidgetItem()
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_item.setFont(f)
header_item.setText('Device')
header_init.setFont(f)
header_init.setText('Init. Value')
header_value.setFont(f)
header_value.setText('IST:2')
tab.setContentsMargins(15, 0, 15, 10)
tab.setHorizontalHeaderItem(0, header_item)
tab.setHorizontalHeaderItem(1, header_init)
tab.setHorizontalHeaderItem(2, header_value)
tab.setColumnWidth(0, 80)
tab.setColumnWidth(1, 88)
tab.setColumnWidth(2, 88)
tab.setFixedWidth(304)
# _table_height = 700
#tab.setFixedHeight(_table_height)
tab.restore_layout.removeWidget(tab.restore_value_button)
tab.restore_value_button.deleteLater()
tab.restore_value_button= None
tab.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
box = QVBoxLayout()
box.addWidget(table_pwr[0])
box.addWidget(table_pwr[1])
box.setAlignment(Qt.AlignTop | Qt.AlignRight)
box.setSpacing(10)
qw = QWidget()
qw.setLayout(box)
obj_name = self.settings.data[sector]["colorObj"]
if self.obj_to_upper:
obj_name = obj_name.upper()
qw.setObjectName(obj_name)
return qw
def check_status_list(self, pv_list, status_list, line):
_brk = ("------------------------------------------------------" +
"------------------------------------------------------")
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _brk, {})
_options = {}
for pv, stat in zip(pv_list, status_list):
if stat != self.cyca.ICAFE_NORMAL:
_mess = ("Error in 'set' for " + pv + " ")
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(stat)
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line, _mess, _options)
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _brk, {})
_mess = ("The following devices reported an error " +
"in 'set' operation:")
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _mess, {})
def check_status(self, pv, stat, line):
if stat != self.cyca.ICAFE_NORMAL:
_mess = ("Error in 'set' for " + pv + ".")
_options = {}
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(
stat)
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line,
_mess, _options)
def on_sector_standby(self):
target = self.sender()
sector = target.sector
_table = self.table_sol_dict[sector]
##_text = _table.standby_value_button.text()
#_table.standby_value_button
##target.setText("Downing..")
##target.setEnabled(False)
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
#QApplication.processEvents()
#disenable widgets to avoid circular behaviour since
#updates of SOL also update PWR, and vice-versa
self.table_pwr_dict[sector].init_value_button.setEnabled(False)
_table.init_value_button.click()
time.sleep(0.05)
self.table_pwr_dict[sector].init_value_button.setEnabled(True)
_table.init_value_button.setEnabled(False)
self.table_pwr_dict[sector].init_value_button.click()
time.sleep(0.05)
self.table_sol_dict[sector].init_value_button.setEnabled(True)
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
'''
#Now read LAST POWER:
_pv = "SEC-" + target.sector + ":TOTPWR"
tot_power = self.cafe.get(_pv, dt='float')
print("TOTAL PWER===>", tot_power, _pv, flush=True)
status = self.cafe.getStatus(_pv)
print(self.cafe.getStatusCodeAsString(status))
_pv_target = "SEC-" + target.sector + ":LASTPWR"
status = self.cafe.set(_pv_target, tot_power)
print("TOTAL PWER STATUS SET", _pv_target, status, flush=True)
print(self.cafe.getStatusCodeAsString(status))
'''
if not self.input_parameters['simulation']:
status, status_list, pv_list = _table.set_standby_values()
if status != self.cyca.ICAFE_NORMAL:
self.check_status_list(pv_list, status_list, _line())
#time.sleep(1.5)
#QApplication.processEvents()
##target.setText(_text)
##target.setEnabled(False)
##QApplication.processEvents(QEventLoop.AllEvents, 1.0)
#QApplication.flush()
#QApplication.processEvents()
##target.setEnabled(True)
###_table.standby_value_button.style().polish(_table.standby_value_button)
pv = target.sector + ":SAVESTATE"
stat = self.cafe.set(pv, 0)
self.check_status(pv, stat, _line())
def on_sector_restore(self):
target = self.sender()
sector = target.sector
_table = self.table_sol_dict[sector]
if not self.input_parameters['simulation']:
status, status_list, pv_list = _table.restore_init_values()
if status != self.cyca.ICAFE_NORMAL:
self.check_status_list(pv_list, status_list, _line())
pv = target.sector + ":SAVESTATE"
stat = self.cafe.set(pv, 1)
self.check_status(pv, stat, _line())
def ca_table_sector_widget(self, sector: str="", color: str="MACHINE"):
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
try:
_standby_values = self.settings.data[sector]["standby"]
except KeyError as ex:
print("On Standby values not given")
pv_dict = {}
for att in attribute_list:
pv_dict[att] = [] #[None] * len(device_list)
for dev in device_list:
pv_dict[att].append(dev + ":" + att)
_table_height = 700
table_sol = CAQTableWidget(
self, pv_list=pv_dict['SOL:2'], show_units=True, notify_freq_hz=0,
notify_unison=False, scale_factor=1, show_timestamp=False,
init_column=True, pv_list_show=device_list, standby_column=True,
standby_values=_standby_values, standby_delay = 0.09)
table_sol.restore_value_button.setToolTip(
("Restore devices to their pre-standby values"))
table_sol.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
table_sol.standby_value_button.sector = sector
table_sol.standby_value_button.clicked.disconnect()
table_sol.standby_value_button.clicked.connect(self.on_sector_standby)
table_sol.restore_value_button.sector = sector
table_sol.restore_value_button.clicked.disconnect()
table_sol.restore_value_button.clicked.connect(self.on_sector_restore)
self.table_sol_dict[sector] = table_sol
table_ist = CAQTableWidget(
self, pv_list=pv_dict['IST:2'], show_units=True, notify_freq_hz=2,
notify_unison=True, scale_factor=1, show_timestamp=False,
init_column=False, pv_list_show=[False])
table_pwr = CAQTableWidget(
self, pv_list=pv_dict['PWR:2'], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, init_list=pv_dict['PWR:2'], pv_list_show=[False])
table_pwr.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
self.table_pwr_dict[sector] = table_pwr
header_item = QTableWidgetItem()
header_init = QTableWidgetItem()
header_standby = QTableWidgetItem()
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_item.setFont(f)
header_item.setText('Device')
header_init.setFont(f)
header_init.setText('Init. Value')
header_standby.setFont(f)
header_standby.setText('Standby')
header_value.setFont(f)
header_value.setText('SOL:2')
table_sol.setContentsMargins(15, 0, 15, 10)
table_sol.setHorizontalHeaderItem(0, header_item)
table_sol.setHorizontalHeaderItem(1, header_init)
table_sol.setHorizontalHeaderItem(2, header_standby)
table_sol.setHorizontalHeaderItem(3, header_value)
table_sol.setColumnWidth(0, 80)
table_sol.setColumnWidth(1, 88)
table_sol.setColumnWidth(2, 80)
table_sol.setColumnWidth(3, 88)
table_sol.setFixedWidth(386)
#table_sol.setFixedHeight(_table_height)
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_value.setFont(f)
header_value.setText('IST:2')
table_ist.setContentsMargins(15, 0, 15, 10)
table_ist.setHorizontalHeaderItem(0, header_value)
table_ist.setColumnWidth(0, 90)
table_ist.setFixedWidth(140)
#table_ist .setFixedHeight(_table_height)
header_init = QTableWidgetItem()
f = header_init.font()
header_init.setFont(f)
header_init.setText('Init. Value')
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_value.setFont(f)
header_value.setText('PWR:2')
table_pwr.setContentsMargins(15, 0, 15, 10)
table_pwr.setHorizontalHeaderItem(0, header_init)
table_pwr.setHorizontalHeaderItem(1, header_value)
table_pwr.setColumnWidth(0, 88)
table_pwr.setColumnWidth(1, 88)
table_pwr.setFixedWidth(226)
#table_pwr.setFixedHeight(_table_height)
#table_pwr.restore_layout.removeWidget(table_pwr.restore_value_button)
#table_pwr.restore_value_button.deleteLater()
#table_pwr.restore_value_button= None
#update_wgt_item = QTableWidgetItem()
#update_wgt = table_pwr.init_value_button
#table_pwr.init_layout.removeWidget(table_pwr.init_value_button)
#table_pwr.setCellWidget(table_pwr.rowCount()-1, 0, update_wgt)
def on_sol_update():
table_sol.init_value_button.setEnabled(False)
table_pwr.init_value_button.click()
time.sleep(0.1)
table_sol.init_value_button.setEnabled(True)
def on_init_update():
table_pwr.init_value_button.setEnabled(False)
table_sol.init_value_button.click()
time.sleep(0.1)
table_pwr.init_value_button.setEnabled(True)
table_sol.init_value_button.sector = sector
table_sol.init_value_button.clicked.connect(on_sol_update)
table_pwr.init_value_button.sector = sector
table_pwr.init_value_button.clicked.connect(on_init_update)
hbox = QHBoxLayout()
hbox.addWidget(table_sol)
hbox.addWidget(table_ist)
hbox.addWidget(table_pwr)
#hbox.setContentsMargins(40, 40, 40, 40)
hbox.setSpacing(10)
hbox.setAlignment(Qt.AlignTop)
qw = QWidget()
qw.setLayout(hbox)
#qw.setStyleSheet("background-color: {0};".format(
# self.settings.data[sector]["qlingrad"]))
obj_name = self.settings.data[sector]["colorObj"]
if self.obj_to_upper:
obj_name = obj_name.upper()
qw.setObjectName(obj_name)
return qw
+542
View File
@@ -0,0 +1,542 @@
import inspect
import os
import platform
import random
import sys
import time
from qtpy import QtCore, QtGui
from qtpy.QtGui import QColor, QFont, QIcon
from qtpy.QtCore import __version__ as QT_VERSION_STR
from qtpy.QtCore import (
PYQT_VERSION_STR, QFile, QIODevice, Qt, QThread, Signal, Slot)
from qtpy.QtWidgets import (
QApplication, QDockWidget, QFrame, QGridLayout, QGroupBox, QHBoxLayout,
QLabel, QMainWindow, QMessageBox, QProgressBar, QPushButton, QSizePolicy,
QSpacerItem, QStackedWidget, QTabBar, QTabWidget, QTableWidget,
QTableWidgetItem, QVBoxLayout, QWidget)
from apps4ops.bdbase.base import BaseWindow
from apps4ops.bdbase.enumkind import MsgSeverity, UserMode, Facility
from caqtwidgets.pvwidgets import CAQTableWidget
_pymodule = os.path.basename(__file__)
def _line():
"""Macro to return the current line number.688
The current line number within the file is used when
reporting messages to the message logging window.
Returns:
int: Current line number.
"""
return inspect.currentframe().f_back.f_lineno
class AppGui(QWidget):
def __init__(self, parent):
super(AppGui, self).__init__()
self.parent = parent
self.cafe = self.parent.cafe
self.cyca = self.parent.cyca
self.gui_frame = self.parent.gui_frame
self.gui_header = self.parent.gui_header
self.font_gui = self.parent.gui_frame.font_gui
self.input_parameters = self.parent.input_parameters
self.input_labels = self.parent.input_labels
self.expert_parameters = self.parent.expert_parameters
self.gui_frame.expert_parameters_group.setFixedWidth(260)
self.gui_frame.operator_parameters_group.setFixedWidth(260)
#self.gui_frame.operator_parameters_group.setFixedHeight(260)
self.gui_frame.measurement_tab_wgt.setMinimumWidth(280)
self.gui_frame.operator_wgt.setFixedHeight(240)
self.gui_frame.expert_wgt.setFixedHeight(240)
self.gui_frame.central_tab_widget.tabBar().setTabText(0, "Control")
self.gui_frame.central_tab_widget.tabBar().setTabText(1, "Savings")
self.expert_labels = self.parent.expert_labels
self.settings = self.parent.settings
self.obj_to_upper = True if random.randint(1, 10) > 3 else False
self.table_sol_dict = {}
#wgt = self.ca_table_sector_widget(sector="IP2")
wgt = self.group_sector_qtabwidget()
self.gui_frame.measurement_layout.addWidget(
wgt, 0, 1, 3, 3, alignment=Qt.AlignTop)
qf = QFrame()
qf.setFixedHeight(600)
self.gui_frame.measurement_layout.addWidget(
qf, 1, 0, 1, 1, alignment=Qt.AlignTop)
self.sectorI_dict = {}
self.sectorI_dict['IP2'] = 0
self.sectorI_dict['IW2'] = 0
self.sectorI_dict['PK1'] = 0
self.sectorI_dict['PK2'] = 0
self.sectorI_dict['SINQ'] = 0
self.sectorI_dict['UCN'] = 0
self.I_min = 10.10
ucn_line = ["PK1", "PK2"]
sinq_line = ["PK1", "PK2"]
pk1_line = ["IW2"]
pk2_line = ["IW2"]
def enable_disable_end(sector, sector_line, value):
self.sectorI_dict[sector] = value
for sector in sector_line:
if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
'SINQ'] > self.I_min:
if self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
def enable_disable_pk(sector, sector_line, value):
self.sectorI_dict[sector] = value
for sector in sector_line:
if self.sectorI_dict['PK1'] > self.I_min or self.sectorI_dict[
'PK2'] > self.I_min:
if self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
def receive_ucn_update(value, status, alarm_severity):
enable_disable_end('UCN', ucn_line, value)
def receive_sinq_update(value, status, alarm_severity):
enable_disable_end('SINQ', sinq_line, value)
def receive_pk1_update(value, status, alarm_severity):
enable_disable_pk('PK1', pk1_line, value)
def receive_pk2_update(value, status, alarm_severity):
enable_disable_pk('PK2', pk2_line, value)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_ucn_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_sinq_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_pk1_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_pk2_update)
#self.cafe.monitor("MWC2:IST:2", cb)
#print(dir(self.gui_header.header_wgt.layout().widget()), flush=True)
def group_sector_qtabwidget(self):
idx_inj = self.settings.data["header"].index("INJ2")
idx = self.settings.data["header"].index("IP2")
#open all PVS
pv = []
for sector in self.settings.data["header"][idx_inj:]:
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
for att in attribute_list:
for dev in device_list:
pv.append(dev + ":" + att)
self.cafe.openPrepare()
self.cafe.open(pv)
self.cafe.openNowAndWait(0.5)
sector_wgt_dict = {}
sector_wgt_dict["INJ2"] = self.ca_table_rf_widget(sector="INJ2")
for sector in self.settings.data["header"][idx:]:
sector_wgt_dict[sector] = self.ca_table_sector_widget(sector=sector)
sector_tab_widget = QTabWidget()
sector_tab_widget.setFont(self.font_gui)
sector_tab_widget.setStyleSheet("QTabBar {font-size: 12pt;}")
sector_tab_widget.tabBar().setShape(QTabBar.TriangularNorth)
for i, sector in enumerate(self.settings.data["header"][idx:]):
#if sector == "INJ2":
# _title = "RF"
#else:
# _title = sector
sector_tab_widget.addTab(sector_wgt_dict[sector], sector)
color = self.settings.data[sector]["color"]
sector_tab_widget.tabBar().setTabTextColor(i, QColor(color))
sector_tab_widget.addTab(sector_wgt_dict["INJ2"], "RF")
color = self.settings.data["INJ2"]["color"]
sector_tab_widget.tabBar().setTabTextColor(
len(self.settings.data["header"][idx:]), QColor(color))
return sector_tab_widget
def ca_table_rf_widget(self, sector: str="", color: str="MACHINE"):
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
pv_dict = {}
for att in attribute_list:
pv_dict[att] = [] #[None] * len(device_list)
for dev in device_list:
pv_dict[att].append(dev + ":" + att)
table_pwr = [None] * 2
table_pwr[0] = CAQTableWidget(
self, pv_list=pv_dict['IST:2'][0:4], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, pv_list_show=device_list[0:4])
table_pwr[1] = CAQTableWidget(
self, pv_list=pv_dict['IST:2'][4:], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, pv_list_show=device_list[4:])
for tab in table_pwr:
header_item = QTableWidgetItem()
header_init = QTableWidgetItem()
header_standby = QTableWidgetItem()
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_item.setFont(f)
header_item.setText('Device')
header_init.setFont(f)
header_init.setText('Init. Value')
header_value.setFont(f)
header_value.setText('IST:2')
tab.setContentsMargins(15, 0, 15, 10)
tab.setHorizontalHeaderItem(0, header_item)
tab.setHorizontalHeaderItem(1, header_init)
tab.setHorizontalHeaderItem(2, header_value)
tab.setColumnWidth(0, 80)
tab.setColumnWidth(1, 88)
tab.setColumnWidth(2, 88)
tab.setFixedWidth(304)
# _table_height = 700
#tab.setFixedHeight(_table_height)
tab.restore_layout.removeWidget(tab.restore_value_button)
tab.restore_value_button.deleteLater()
tab.restore_value_button= None
tab.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
box = QVBoxLayout()
box.addWidget(table_pwr[0])
box.addWidget(table_pwr[1])
box.setAlignment(Qt.AlignTop | Qt.AlignRight)
box.setSpacing(10)
qw = QWidget()
qw.setLayout(box)
obj_name = self.settings.data[sector]["colorObj"]
if self.obj_to_upper:
obj_name = obj_name.upper()
qw.setObjectName(obj_name)
return qw
'''
def check_status_list(self, pv_list, status_list, line):
_mess = ("The following device(s) reported an error " +
"in 'set' operation: ")
_options = {}
stat_previous = self.cyca.ICAFE_NORMAL
for pv, stat in zip(pv_list, status_list):
if stat != self.cyca.ICAFE_NORMAL:
_mess += pv + " " #("Error in 'set' for " + pv + ".")
if stat != stat_previous:
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(stat)
if stat_previous != self.cyca.ICAFE_NORMAL:
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line, _mess,
_options)
_mess = ""
stat_previous = stat
if _mess:
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line, _mess, _options)
'''
def check_status_list(self, pv_list, status_list, line):
_brk = ("------------------------------------------------------" +
"------------------------------------------------------")
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _brk, {})
_options = {}
for pv, stat in zip(pv_list, status_list):
if stat != self.cyca.ICAFE_NORMAL:
_mess = ("Error in 'set' for " + pv + " ")
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(stat)
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line, _mess, _options)
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _brk, {})
_mess = ("The following devices reported an error " +
"in 'set' operation:")
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _mess, {})
def check_status(self, pv, stat, line):
if stat != self.cyca.ICAFE_NORMAL:
_mess = ("Error in 'set' for " + pv + ".")
_options = {}
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(
stat)
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line,
_mess, _options)
class StandByThread(QThread):
def __init__(self, parent, table):
QThread.__init__(self)
self.parent = parent
self.table = table
self.cafe = self.parent.cafe
self.cyca = self.parent.cyca
print("INIT", flush=True)
def __del__(self):
print("WAITING", flush=True)
##self.wait()
def run(self):
print("RUNNING", flush=True)
_handles = self.cafe.getHandles()[0]
_status = self.cafe.attachContext(_handles[0])
status, status_list, pv_list = self.table.set_standby_values()
time.sleep(3)
print("END RUNNING", flush=True)
#return status, status_list, pv_list
def on_sector_standby(self):
target = self.sender()
_table = self.table_sol_dict[target.sector]
_text = _table.standby_value_button.text()
_table.standby_value_button.setEnabled(False)
_table.standby_value_button.setText("Downing..")
QApplication.processEvents()
status, status_list, pv_list = _table.set_standby_values()
if status != self.cyca.ICAFE_NORMAL:
self.check_status_list(pv_list, status_list, _line())
_table.standby_value_button.setText(_text)
_table.standby_value_button.setEnabled(True)
QApplication.processEvents()
pv = target.sector + ":SAVESTATE"
stat = self.cafe.set(pv, 1)
self.check_status(pv, stat, _line())
'''
@Slot()
def standby_thread_finished():
print("FIN", flush=True)
_table.standby_value_button.setText(_text)
_table.standby_value_button.setEnabled(True)
QApplication.processEvents()
standby_thread = self.StandByThread(self, _table)
print("HERE", flush=True)
standby_thread.finished.connect(standby_thread_finished)
print("HERE2", flush=True)
standby_thread.start()
print("HERE3", flush=True)
time.sleep(0.05)
print("HERE4", flush=True)
'''
def on_sector_restore(self):
target = self.sender()
pv = target.sector + ":SAVESTATE"
stat = self.cafe.set(pv, 0)
self.check_status(pv, stat, _line())
def ca_table_sector_widget(self, sector: str="", color: str="MACHINE"):
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
try:
_standby_values = self.settings.data[sector]["standby"]
except KeyError as ex:
print("On Standby values not given")
pv_dict = {}
for att in attribute_list:
pv_dict[att] = [] #[None] * len(device_list)
for dev in device_list:
pv_dict[att].append(dev + ":" + att)
'''
self.cafe.openPrepare()
self.cafe.open(pv_dict['SOL:2'])
self.cafe.open(pv_dict['IST:2'])
self.cafe.open(pv_dict['PWR:2'])
self.cafe.openNowAndWait(0.5)
'''
_table_height = 700
table_sol = CAQTableWidget(
self, pv_list=pv_dict['SOL:2'], show_units=True, notify_freq_hz=0,
notify_unison=False, scale_factor=1, show_timestamp=False,
init_column=True, pv_list_show=device_list, standby_column=True,
standby_values=_standby_values, standby_delay = 0.09)
table_sol.restore_value_button.setToolTip(
("Restore devices to their pre-standby values"))
table_sol.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
table_sol.standby_value_button.sector = sector
table_sol.standby_value_button.clicked.disconnect()
table_sol.standby_value_button.clicked.connect(self.on_sector_standby)
table_sol.restore_value_button.sector = sector
table_sol.restore_value_button.clicked.connect(self.on_sector_restore)
self.table_sol_dict[sector] = table_sol
table_ist = CAQTableWidget(
self, pv_list=pv_dict['IST:2'], show_units=True, notify_freq_hz=2,
notify_unison=True, scale_factor=1, show_timestamp=False,
init_column=False, pv_list_show=[False])
table_pwr = CAQTableWidget(
self, pv_list=pv_dict['PWR:2'], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, init_list=pv_dict['PWR:2'], pv_list_show=[False])
header_item = QTableWidgetItem()
header_init = QTableWidgetItem()
header_standby = QTableWidgetItem()
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_item.setFont(f)
header_item.setText('Device')
header_init.setFont(f)
header_init.setText('Init. Value')
header_standby.setFont(f)
header_standby.setText('Standby')
header_value.setFont(f)
header_value.setText('SOL:2')
table_sol.setContentsMargins(15, 0, 15, 10)
table_sol.setHorizontalHeaderItem(0, header_item)
table_sol.setHorizontalHeaderItem(1, header_init)
table_sol.setHorizontalHeaderItem(2, header_standby)
table_sol.setHorizontalHeaderItem(3, header_value)
table_sol.setColumnWidth(0, 80)
table_sol.setColumnWidth(1, 88)
table_sol.setColumnWidth(2, 80)
table_sol.setColumnWidth(3, 88)
table_sol.setFixedWidth(386)
#table_sol.setFixedHeight(_table_height)
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_value.setFont(f)
header_value.setText('IST:2')
table_ist.setContentsMargins(15, 0, 15, 10)
table_ist.setHorizontalHeaderItem(0, header_value)
table_ist.setColumnWidth(0, 90)
table_ist.setFixedWidth(140)
#table_ist .setFixedHeight(_table_height)
header_init = QTableWidgetItem()
f = header_init.font()
header_init.setFont(f)
header_init.setText('Init. Value')
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_value.setFont(f)
header_value.setText('PWR:2')
table_pwr.setContentsMargins(15, 0, 15, 10)
table_pwr.setHorizontalHeaderItem(0, header_init)
table_pwr.setHorizontalHeaderItem(1, header_value)
table_pwr.setColumnWidth(0, 88)
table_pwr.setColumnWidth(1, 88)
table_pwr.setFixedWidth(226)
#table_pwr.setFixedHeight(_table_height)
table_pwr.restore_layout.removeWidget(table_pwr.restore_value_button)
table_pwr.restore_value_button.deleteLater()
table_pwr.restore_value_button= None
hbox = QHBoxLayout()
hbox.addWidget(table_sol)
hbox.addWidget(table_ist)
hbox.addWidget(table_pwr)
#hbox.setContentsMargins(40, 40, 40, 40)
hbox.setSpacing(10)
hbox.setAlignment(Qt.AlignTop)
qw = QWidget()
qw.setLayout(hbox)
#qw.setStyleSheet("background-color: {0};".format(
# self.settings.data[sector]["qlingrad"]))
obj_name = self.settings.data[sector]["colorObj"]
if self.obj_to_upper:
obj_name = obj_name.upper()
qw.setObjectName(obj_name)
return qw
+596
View File
@@ -0,0 +1,596 @@
import inspect
import os
import platform
import random
import sys
import time
from datetime import timedelta
from qtpy import QtCore, QtGui
from qtpy.QtGui import QColor, QFont, QIcon
from qtpy.QtCore import __version__ as QT_VERSION_STR
from qtpy.QtCore import (
PYQT_VERSION_STR, QDate, QDateTime, QEventLoop, Qt, Signal, Slot)
from qtpy.QtWidgets import (
QApplication, QDockWidget, QFrame, QGridLayout, QGroupBox, QHBoxLayout,
QLabel, QMainWindow, QMessageBox, QProgressBar, QPushButton, QSizePolicy,
QSpacerItem, QStackedWidget, QTabBar, QTabWidget, QTableWidget,
QTableWidgetItem, QVBoxLayout, QWidget)
from apps4ops.bdbase.base import BaseWindow
from apps4ops.bdbase.enumkind import MsgSeverity, UserMode, Facility
from caqtwidgets.pvwidgets import CAQLabel, CAQLineEdit, CAQTableWidget
_pymodule = os.path.basename(__file__)
def _line():
"""Macro to return the current line number.688
The current line number within the file is used when
reporting messages to the message logging window.
Returns:
int: Current line number.
"""
return inspect.currentframe().f_back.f_lineno
class AppGui(QWidget):
def __init__(self, parent):
super(AppGui, self).__init__()
self.parent = parent
self.cafe = self.parent.cafe
self.cyca = self.parent.cyca
self.gui_frame = self.parent.gui_frame
self.gui_header = self.parent.gui_header
self.font_gui = self.parent.gui_frame.font_gui
self.input_parameters = self.parent.input_parameters
self.input_labels = self.parent.input_labels
self.expert_parameters = self.parent.expert_parameters
self.gui_frame.expert_parameters_group.setFixedWidth(260)
self.gui_frame.operator_parameters_group.setFixedWidth(260)
#self.gui_frame.operator_parameters_group.setFixedHeight(260)
self.gui_frame.measurement_tab_wgt.setMinimumWidth(280)
self.gui_frame.operator_wgt.setFixedHeight(240)
self.gui_frame.expert_wgt.setFixedHeight(240)
self.gui_frame.central_tab_widget.tabBar().setTabText(0, "Control")
self.gui_frame.central_tab_widget.tabBar().setTabText(1, "Savings")
self.expert_labels = self.parent.expert_labels
self.settings = self.parent.settings
self.obj_to_upper = True if random.randint(1, 10) > 3 else False
self.table_sol_dict = {}
self.table_pwr_dict = {}
#wgt = self.ca_table_sector_widget(sector="IP2")
wgt = self.group_sector_qtabwidget()
self.gui_frame.measurement_layout.addWidget(
wgt, 0, 1, 3, 3, alignment=Qt.AlignTop)
status_wgt = self.group_sector_status()
self.gui_frame.measurement_layout.addWidget(
status_wgt, 1, 0, 2, 1, alignment=Qt.AlignTop)
qf = QFrame()
qf.setFixedHeight(600)
self.gui_frame.measurement_layout.addWidget(
qf, 2, 0, 1, 1, alignment=Qt.AlignTop)
self.sectorI_dict = {}
self.sectorI_dict['IP2'] = 0
self.sectorI_dict['IW2'] = 0
self.sectorI_dict['PK1'] = 0
self.sectorI_dict['PK2'] = 0
self.sectorI_dict['SINQ'] = 0
self.sectorI_dict['UCN'] = 0
self.I_min = 0.017
ucn_line = ["PK1", "PK2"]
sinq_line = ["PK1", "PK2"]
pk1_line = ["IW2"]
pk2_line = ["IW2"]
def enable_disable_end(sector, sector_line, value):
self.sectorI_dict[sector] = value
for sector in sector_line:
if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
'SINQ'] > self.I_min:
if self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
def enable_disable_pk(sector, sector_line, value):
self.sectorI_dict[sector] = value
for sector in sector_line:
if self.sectorI_dict['PK1'] > self.I_min or self.sectorI_dict[
'PK2'] > self.I_min:
if self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(False)
else:
if not self.table_sol_dict[
sector].standby_value_button.isEnabled():
self.table_sol_dict[
sector].standby_value_button.setEnabled(True)
def receive_ucn_update(value, status, alarm_severity):
enable_disable_end('UCN', ucn_line, value)
def receive_sinq_update(value, status, alarm_severity):
enable_disable_end('SINQ', sinq_line, value)
def receive_pk1_update(value, status, alarm_severity):
enable_disable_pk('PK1', pk1_line, value)
def receive_pk2_update(value, status, alarm_severity):
enable_disable_pk('PK2', pk2_line, value)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_ucn_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_sinq_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_pk1_update)
self.gui_header.beam_current_wgt_dict[
"INJ2"].trigger_monitor_float.connect(receive_pk2_update)
#self.cafe.monitor("MWC2:IST:2", cb)
#print(dir(self.gui_header.header_wgt.layout().widget()), flush=True)
def group_sector_status(self):
vbox = QVBoxLayout()
#Connect all channels
#Heading
idx = self.settings.data["header"].index("IP2")
#Sector
hbox =QHBoxLayout()
hbox.addWidget(QLabel(" "))
hbox.addWidget(QLabel("Power"))
hbox.addWidget(QLabel("Initial"))
qhead = QWidget()
qhead.setLayout(hbox)
vbox.addWidget(qhead)
for i, sector in enumerate(self.settings.data["header"][idx:]):
vbox.addWidget(self.sector_status(sector))
qw = QWidget()
qw.setLayout(vbox)
return qw
def sector_status(self, sector):
'''Create each sector line for inclusion into group
'''
device = "SEC-" + sector
#Qlabel
qsector = QLabel(sector+":")
#Savings
pv_pwr_tot = device + ":TOTPWR"
pv_pwr_last = device + ":LASTPWR"
pv_pwr_saved = device + ":SAVEPWR"
#print("device", device, flush=True)
now = QDateTime.currentDateTime()
xdate = QDate(now.date().year(), 1, 15)
xstart = QDateTime(xdate)
print("delta t ", xstart.secsTo(now))
print("{}".format(str(timedelta(seconds=xstart.secsTo(now)))))
qpnow = CAQLabel(self, pv_name=pv_pwr_tot, show_units=True)
qpinit = CAQLabel(self, pv_name=pv_pwr_last, show_units=True)
#qpsave = QCALabel(pv=pv_pwr_tot, show_units=True)
#qpsum = QCALabel(pv=pv_pwr_tot, show_units=True)
#qtdis = QBasicTimer()
hbox =QHBoxLayout()
hbox.addWidget(qsector)
hbox.addWidget(qpnow)
hbox.addWidget(qpinit)
qw = QWidget()
qw.setLayout(hbox)
return qw
def group_sector_qtabwidget(self):
idx_inj = self.settings.data["header"].index("INJ2")
idx = self.settings.data["header"].index("IP2")
#open all PVS
pv = []
for sector in self.settings.data["header"][idx_inj:]:
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
for att in attribute_list:
for dev in device_list:
pv.append(dev + ":" + att)
self.cafe.openPrepare()
self.cafe.open(pv)
self.cafe.openNowAndWait(0.5)
self.cafe.supplementHandles()
sector_wgt_dict = {}
sector_wgt_dict["INJ2"] = self.ca_table_rf_widget(sector="INJ2")
for sector in self.settings.data["header"][idx:]:
sector_wgt_dict[sector] = self.ca_table_sector_widget(sector=sector)
sector_tab_widget = QTabWidget()
sector_tab_widget.setFont(self.font_gui)
sector_tab_widget.setStyleSheet("QTabBar {font-size: 12pt;}")
sector_tab_widget.tabBar().setShape(QTabBar.TriangularNorth)
for i, sector in enumerate(self.settings.data["header"][idx:]):
#if sector == "INJ2":
# _title = "RF"
#else:
# _title = sector
sector_tab_widget.addTab(sector_wgt_dict[sector], sector)
color = self.settings.data[sector]["color"]
sector_tab_widget.tabBar().setTabTextColor(i, QColor(color))
sector_tab_widget.addTab(sector_wgt_dict["INJ2"], "RF")
color = self.settings.data["INJ2"]["color"]
sector_tab_widget.tabBar().setTabTextColor(
len(self.settings.data["header"][idx:]), QColor(color))
return sector_tab_widget
def ca_table_rf_widget(self, sector: str="", color: str="MACHINE"):
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
pv_dict = {}
for att in attribute_list:
pv_dict[att] = [] #[None] * len(device_list)
for dev in device_list:
pv_dict[att].append(dev + ":" + att)
table_pwr = [None] * 2
table_pwr[0] = CAQTableWidget(
self, pv_list=pv_dict['IST:2'][0:4], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, pv_list_show=device_list[0:4])
table_pwr[1] = CAQTableWidget(
self, pv_list=pv_dict['IST:2'][4:], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, pv_list_show=device_list[4:])
for tab in table_pwr:
header_item = QTableWidgetItem()
header_init = QTableWidgetItem()
header_standby = QTableWidgetItem()
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_item.setFont(f)
header_item.setText('Device')
header_init.setFont(f)
header_init.setText('Init. Value')
header_value.setFont(f)
header_value.setText('IST:2')
tab.setContentsMargins(15, 0, 15, 10)
tab.setHorizontalHeaderItem(0, header_item)
tab.setHorizontalHeaderItem(1, header_init)
tab.setHorizontalHeaderItem(2, header_value)
tab.setColumnWidth(0, 80)
tab.setColumnWidth(1, 88)
tab.setColumnWidth(2, 88)
tab.setFixedWidth(304)
# _table_height = 700
#tab.setFixedHeight(_table_height)
tab.restore_layout.removeWidget(tab.restore_value_button)
tab.restore_value_button.deleteLater()
tab.restore_value_button= None
tab.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
box = QVBoxLayout()
box.addWidget(table_pwr[0])
box.addWidget(table_pwr[1])
box.setAlignment(Qt.AlignTop | Qt.AlignRight)
box.setSpacing(10)
qw = QWidget()
qw.setLayout(box)
obj_name = self.settings.data[sector]["colorObj"]
if self.obj_to_upper:
obj_name = obj_name.upper()
qw.setObjectName(obj_name)
return qw
def check_status_list(self, pv_list, status_list, line):
_brk = ("------------------------------------------------------" +
"------------------------------------------------------")
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _brk, {})
_options = {}
for pv, stat in zip(pv_list, status_list):
if stat != self.cyca.ICAFE_NORMAL:
_mess = ("Error in 'set' for " + pv + " ")
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(stat)
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line, _mess, _options)
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _brk, {})
_mess = ("The following devices reported an error " +
"in 'set' operation:")
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, line, _mess, {})
def check_status(self, pv, stat, line):
if stat != self.cyca.ICAFE_NORMAL:
_mess = ("Error in 'set' for " + pv + ".")
_options = {}
_options['statusCode'] = (
str(stat) + " " +
self.cafe.getStatusCodeAsString(stat))
_options['statusInfo'] = self.cafe.getStatusInfo(
stat)
self.parent.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, line,
_mess, _options)
def on_sector_standby(self):
target = self.sender()
sector = target.sector
_table = self.table_sol_dict[sector]
_text = _table.standby_value_button.text()
#_table.standby_value_button
target.setText("Downing..")
target.setEnabled(False)
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
#QApplication.processEvents()
#disenable widgets to avoid circular behaviour since
#updates of SOL also update PWR, and vice-versa
self.table_pwr_dict[sector].init_value_button.setEnabled(False)
_table.init_value_button.click()
time.sleep(0.05)
self.table_pwr_dict[sector].init_value_button.setEnabled(True)
_table.init_value_button.setEnabled(False)
self.table_pwr_dict[sector].init_value_button.click()
time.sleep(0.05)
self.table_sol_dict[sector].init_value_button.setEnabled(True)
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
#Now read LAST POWER:
_pv = "SEC-" + target.sector + ":TOTPWR"
tot_power = self.cafe.get(_pv, dt='float')
print("TOTAL PWER===>", tot_power, _pv, flush=True)
status = self.cafe.getStatus(_pv)
print(self.cafe.getStatusCodeAsString(status))
_pv_target = "SEC-" + target.sector + ":LASTPWR"
status = self.cafe.set(_pv_target, tot_power)
print("TOTAL PWER STATUS SET", _pv_target, status, flush=True)
print(self.cafe.getStatusCodeAsString(status))
status, status_list, pv_list = _table.set_standby_values()
if status != self.cyca.ICAFE_NORMAL:
self.check_status_list(pv_list, status_list, _line())
#time.sleep(1.5)
#QApplication.processEvents()
target.setText(_text)
target.setEnabled(False)
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
#QApplication.flush()
#QApplication.processEvents()
target.setEnabled(True)
###_table.standby_value_button.style().polish(_table.standby_value_button)
##pv = target.sector + ":SAVESTATE"
##stat = self.cafe.set(pv, 1)
##self.check_status(pv, stat, _line())
def on_sector_restore(self):
target = self.sender()
pv = target.sector + ":SAVESTATE"
#stat = self.cafe.set(pv, 0)
#self.check_status(pv, stat, _line())
def ca_table_sector_widget(self, sector: str="", color: str="MACHINE"):
device_list = self.settings.data[sector]["device"]
attribute_list = self.settings.data[sector]["attribute"]
try:
_standby_values = self.settings.data[sector]["standby"]
except KeyError as ex:
print("On Standby values not given")
pv_dict = {}
for att in attribute_list:
pv_dict[att] = [] #[None] * len(device_list)
for dev in device_list:
pv_dict[att].append(dev + ":" + att)
_table_height = 700
table_sol = CAQTableWidget(
self, pv_list=pv_dict['SOL:2'], show_units=True, notify_freq_hz=0,
notify_unison=False, scale_factor=1, show_timestamp=False,
init_column=True, pv_list_show=device_list, standby_column=True,
standby_values=_standby_values, standby_delay = 0.09)
table_sol.restore_value_button.setToolTip(
("Restore devices to their pre-standby values"))
table_sol.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
table_sol.standby_value_button.sector = sector
table_sol.standby_value_button.clicked.disconnect()
table_sol.standby_value_button.clicked.connect(self.on_sector_standby)
table_sol.restore_value_button.sector = sector
table_sol.restore_value_button.clicked.connect(self.on_sector_restore)
self.table_sol_dict[sector] = table_sol
table_ist = CAQTableWidget(
self, pv_list=pv_dict['IST:2'], show_units=True, notify_freq_hz=2,
notify_unison=True, scale_factor=1, show_timestamp=False,
init_column=False, pv_list_show=[False])
table_pwr = CAQTableWidget(
self, pv_list=pv_dict['PWR:2'], show_units=False, notify_freq_hz=0,
suffix = "kW",
notify_unison=False, scale_factor=0.001, show_timestamp=False,
init_column=True, init_list=pv_dict['PWR:2'], pv_list_show=[False])
table_pwr.init_value_button.setToolTip(
("Shows initial, pre-standby values. Update is also " +
"executed automatically before the standby procedure."))
self.table_pwr_dict[sector] = table_pwr
header_item = QTableWidgetItem()
header_init = QTableWidgetItem()
header_standby = QTableWidgetItem()
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_item.setFont(f)
header_item.setText('Device')
header_init.setFont(f)
header_init.setText('Init. Value')
header_standby.setFont(f)
header_standby.setText('Standby')
header_value.setFont(f)
header_value.setText('SOL:2')
table_sol.setContentsMargins(15, 0, 15, 10)
table_sol.setHorizontalHeaderItem(0, header_item)
table_sol.setHorizontalHeaderItem(1, header_init)
table_sol.setHorizontalHeaderItem(2, header_standby)
table_sol.setHorizontalHeaderItem(3, header_value)
table_sol.setColumnWidth(0, 80)
table_sol.setColumnWidth(1, 88)
table_sol.setColumnWidth(2, 80)
table_sol.setColumnWidth(3, 88)
table_sol.setFixedWidth(386)
#table_sol.setFixedHeight(_table_height)
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_value.setFont(f)
header_value.setText('IST:2')
table_ist.setContentsMargins(15, 0, 15, 10)
table_ist.setHorizontalHeaderItem(0, header_value)
table_ist.setColumnWidth(0, 90)
table_ist.setFixedWidth(140)
#table_ist .setFixedHeight(_table_height)
header_init = QTableWidgetItem()
f = header_init.font()
header_init.setFont(f)
header_init.setText('Init. Value')
header_value = QTableWidgetItem()
f = header_value.font()
f.setPixelSize(13)
header_value.setFont(f)
header_value.setText('PWR:2')
table_pwr.setContentsMargins(15, 0, 15, 10)
table_pwr.setHorizontalHeaderItem(0, header_init)
table_pwr.setHorizontalHeaderItem(1, header_value)
table_pwr.setColumnWidth(0, 88)
table_pwr.setColumnWidth(1, 88)
table_pwr.setFixedWidth(226)
#table_pwr.setFixedHeight(_table_height)
#table_pwr.restore_layout.removeWidget(table_pwr.restore_value_button)
#table_pwr.restore_value_button.deleteLater()
#table_pwr.restore_value_button= None
#update_wgt_item = QTableWidgetItem()
#update_wgt = table_pwr.init_value_button
#table_pwr.init_layout.removeWidget(table_pwr.init_value_button)
#table_pwr.setCellWidget(table_pwr.rowCount()-1, 0, update_wgt)
def on_sol_update():
table_sol.init_value_button.setEnabled(False)
table_pwr.init_value_button.click()
time.sleep(0.1)
table_sol.init_value_button.setEnabled(True)
def on_init_update():
table_pwr.init_value_button.setEnabled(False)
table_sol.init_value_button.click()
time.sleep(0.1)
table_pwr.init_value_button.setEnabled(True)
table_sol.init_value_button.sector = sector
table_sol.init_value_button.clicked.connect(on_sol_update)
table_pwr.init_value_button.sector = sector
table_pwr.init_value_button.clicked.connect(on_init_update)
hbox = QHBoxLayout()
hbox.addWidget(table_sol)
hbox.addWidget(table_ist)
hbox.addWidget(table_pwr)
#hbox.setContentsMargins(40, 40, 40, 40)
hbox.setSpacing(10)
hbox.setAlignment(Qt.AlignTop)
qw = QWidget()
qw.setLayout(hbox)
#qw.setStyleSheet("background-color: {0};".format(
# self.settings.data[sector]["qlingrad"]))
obj_name = self.settings.data[sector]["colorObj"]
if self.obj_to_upper:
obj_name = obj_name.upper()
qw.setObjectName(obj_name)
return qw