diff --git a/.gitignore b/.gitignore index 2bbbfca..cb9b8cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ -rm *.*~ -rm *.*-* -rm *.*+* -rm pyrcc5 -rm pyrcc5/*.* -rm src/*.*~ -rm src/*.*-* -rm src/*.*+* +*.*~ +*.*-* +*.*+* +pyrcc5 +pyrcc5/*.* +src/*.*~ +src/*.*-* +src/*.*+* +src/__pycache/ +src/__pycache__/* + diff --git a/hush.json- b/hush.json- deleted file mode 100755 index bae95a9..0000000 --- a/hush.json- +++ /dev/null @@ -1,52 +0,0 @@ -{ - "menuFlags":{ - "hasFile": 0, - "loadInitFile": 0, - "hasDaq": 0, - "hasH5": 0, - "hasEpics": 0 - }, - "hdf": { - "destination" : "./" - }, - "SLS" : ["Injector", "Booster", "Ring"], - "SLS2" : {"test": ["Injector", "Booster", "Ring"]}, - "QTabViking":{ - "Vikings": { - "radiobutton" : {"data":{ "widget": "QRadioButton", "text" : "Radio Gaga", "value": ["This", "That", "The Other"], "startIdx": 1}}, - "readonly" : {"data":{ "widget": "QLineRead", "text" :"ReadOnly:", "value" : "input"}}, - "npts" : {"data":{ "widget": "QLineEdit", "text" :"No Events:", "value" : 22, "min": 0.01, "max": 0.99}}, - "nspins" : {"data":{ "widget": "QSpinBox", "text" : "No. Points:", "min": 1, "max": 10, "step": 1,"value": 1 }}, - "ndspins" : {"data":{ "widget": "QDoubleSpinBox", "text" : "No. Points:", "min": 1, "max": 10.0, "step": 0.1,"value": 1.5 }}, - "facility": {"data" : {"widget": "QComboBox", "text" : "Facility:", "link": ["SLS2", "test"],"layout" : "Horizontal"}}, - "checkbox" : {"data":{ "widget": "QCheckBox", "orientation" : "Qt.LeftToRight", "text" : "Checkbox", "value" : 1}} - }, - "Saxons": { - "nevents" : {"data":{ "widget": "QLineEdit", "text" :"No. Iterations:", "value" : 33}}, - "niter" : {"data":{ "widget": "QSpinBox", "text" : "Step size:", "min": 1, "max": 10, "step": 1,"value": 1 }} - } - }, - - "Parameters":{ - "maxmin" : {"flag" : 1, "data":{ "widget": "QRadioButton", "text" : "", "value": ["Maximize", "Minimize" ]}}, - "facility": {"flag": 0, "data" : {"widget": "QComboBox", "text" : "Facility:", - "link": ["SLS"],"layout" : "Horizontal"}}, - "N_events" : {"flag" : 1, "data":{ "widget": "QLineEdit", "text" : "No. events: ", "value": 2 }}, - "N_points" : {"flag" : 1, "data":{ "widget": "QSpinBox", "text" : "No. points:", "min": 1, "max": 10, "step": 1,"value": 1 }}, - "drawLine" : {"flag" : 0, "data":{ "widget": "QHLine", "text" : "None", "value" : "None"}}, - "checkbox" : {"flag" : 1, "data":{ "widget": "QCheckBox", "orientation" : "Qt.LeftToRight", - "text" : " Checkbox", "value" : 1}}, - "drawLine2" : {"flag" : 0, "data":{ "widget": "QHLine", "text" : "None", "value" : "None"}}, - "qtabdata" : {"flag" : 1, "data":{ "widget": "QTabWidget", "text" : "Measurement: ", "value" : 0, "link" : "QTabViking", "color" : ["#0080aa", "#0000ff"]}} - - }, - "Expert":{ - "debug": {"flag" : 1, "data":{ "widget": "None", "text" : "Debug", "value" : 0}}, - "simulation": {"flag" : 1, "data":{ "widget": "None", "text" : "Simulation", "value" : 1}} - }, - "GUI": { - "resultsTabTitle" : "Results", - "subResultsTabTitle" : ["Plots", "Plot-2"], - "resultsSeq" : [10, 1] - } -} diff --git a/hush.json~ b/hush.json~ deleted file mode 100755 index c845405..0000000 --- a/hush.json~ +++ /dev/null @@ -1,67 +0,0 @@ -{ - "menuFlags":{ - "hasFile": 0, - "loadInitFile": 0, - "hasDaq": 0, - "hasH5": 0, - "hasEpics": 0 - }, - "hdf": { - "destination" : "./" - }, - "IP2":{ - "standby": [-10.0025, 10.0025, 10.0025, 0.05, 0.05, 40.000, 0.05, 0.005, - 10.0025, -10.0025, 10.0025, 0.1392, -25.006, 0.05, 0.05, 2.175, - 0.05, 10.0025, -10.0025, 0.05, 0.05, 0.05, 0.05, -10.0025, - -10.0025] - }, - "IW2":{ - "standby": [-5.001, 5.001, 0.05, -5.001, 5.001, 5.001, -5.001, 0.05, - 0.05, 0.05, 5.001, -5.001, -5.001, 5.001, 0.05, 0.05, - 0.05, -5.001, 10.0025, 27.605, -10.0025, 21.899, 0.05, -6, - 6, 6, 0.05, 0.05, 34.152, 0.5, -0.5, 0.05, - 40.591, 62.5], - "ref" : [-79.00, 87.58, 496, -89.3, 80.5, 82.9, -83.77, -1.81, - 0.40, 1.39, 77.80, -41.43, -62.33, 63.97, -0.33, -0.25, - 0.25, -52.27, 83.98, 520.41, -105.96, 433.61, 0.23, -54.25, - 50.51, 23.46, -40.14, -4.66, 622.91, 2.00, -7.17, -0.73, - 806.99, 1147.69] - }, - "PK1":{ - "standby": [56.791, 0.05, -2.0005, 2.0005, 0.05, 0.05, 44.9525, -2.0005, - -2.0005, 0.05, 25.006, -25.006, 0.05, 0.05, 64.066] - }, - - "PK2":{ - "standby": [0.05, -25.006, 25.006, 17.4, 10.0025, -2.0005, 0.05, 0.05, - 25.85, -10.0025, 10.0025, 0.05, 0.05, -25.006, 25.006, -25.006, - 0.05, 0.05, 0.05, 0.05, 25.006, -25.006, 25.006, -25.006, - 0.05, 25.006, 25.1877, 0.05] - }, - - "SINQ":{ - "standby": [-25.006, 0.05, 25.006, 10.0025, -12.608, 0.05, 10.98, - 15.6045, -18.3075, 0.05, 20.462, 0.05, 21.9925, -19.005, - 46.5345, 18.01, -21.3675] - }, - "UCN":{ - "standby": [9.404, 25.006, -25.006, 0.05, 0.05, 0.05, 0.05, 25.006, - -25.006, 20.625, 10.0025, -10.0025, 0.05, 20.625, 25.006 - ] - }, - - "Parameters":{ - - "drawLine" : {"flag" : 0, "data":{ "widget": "QHLine", "text" : "None", "value" : "None"}} - - }, - "Expert":{ - "debug": {"flag" : 1, "data":{ "widget": "None", "text" : "Debug", "value" : 0}}, - "simulation": {"flag" : 1, "data":{ "widget": "None", "text" : "Dry run", "value" : 1}} - }, - "GUI": { - "resultsTabTitle" : "Results", - "subResultsTabTitle" : [], - "resultsSeq" : [] - } -} diff --git a/hush.py~ b/hush.py~ deleted file mode 100644 index 87887a2..0000000 --- a/hush.py~ +++ /dev/null @@ -1,213 +0,0 @@ -import inspect -import logging -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, QGridLayout, QGroupBox, QHBoxLayout, QLabel, - QMainWindow, QMessageBox, QProgressBar, QPushButton, QSizePolicy, - QSpacerItem, QTabWidget, QTableWidget, QTableWidgetItem, QVBoxLayout, - QWidget) - -from apps4ops.bdbase.base import BaseWindow -from apps4ops.bdbase.enumkind import MsgSeverity, UserMode, Facility -from apps4ops.bdbase.helpbrowser import HelpBrowser -from apps4ops.hipa.sendeloghipa import QSendToELOG - -from apps4ops.hipa.enumkind import ElogHIPA - -from src.gui import AppGui -from pyrcc5 import hush_resources - -_pymodule = os.path.basename(__file__) -_appname, _appext = _pymodule.split(".") -_appversion = "1.0.0" -_title = """HIPA Power Usage and Saving Hierarchy, HUSH!""" - - - -def _line(): - """Macro to return the current line number. - - 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 StartMain(BaseWindow): - trigger_log_message = Signal(str, str, int, str, dict) - - def __init__(self, parent=None): - super(StartMain, self).__init__( - parent=parent, pymodule=_pymodule, appversion=_appversion, - title=_title, user_mode=UserMode.OPERATION, facility=Facility.HIPA, - has_optics=False, has_procedure=False) - - self.appname = _appname - self.gui = AppGui(self) - - - - @Slot() - def send_to_elog(self): - - @Slot() - def save_fig_thread_finished(): - - time.sleep(0.2) - - if self.all_data: - QSendToELOG(self, logbook=self.logbook, - projektIdx=self.projekt_idx, - eintragIdx=self.eintrag_idx, - systemIdx=self.system_idx, - statusIdx=self.status_idx, - autoIdx=self.auto_idx, - title=self.title, - message=self.message, - attachFile=self.attach_files) - - time.sleep(1.0) - return - - if not self.verify_send_to_elog(): - return - - - elog = ElogHIPA() - self.projekt_idx = elog.projekt.OPTICS - self.system_idx = elog.system.BEAMDYNAMICS - self.eintrag_idx = elog.eintrag.INFO - self.auto_idx = elog.auto.NO - self.status_idx = elog.status.NONE - - - self.attach_files = [] - - _simulation = self.input_parameters['simulation'] - - if self.all_data: - if self.all_data['Input data'] is not None: - try: - _simulation = self.all_data['Input data']['simulation'] - except KeyError: - _simulation = self.input_parameters['simulation'] - pass - - - self.logbook = "Sandkasten" if _simulation else None - self.title = _title - - if not self.all_data: - QSendToELOG(self, logbook=self.logbook, - projektIdx=self.projekt_idx, - eintragIdx=self.eintrag_idx, - systemIdx=self.system_idx, - statusIdx=self.status_idx, - autoIdx=self.auto_idx, - title=self.title, - attachFile=self.attach_files) - - - return - - - message = "" - - _folder_name = self.elog_dest - if not os.path.exists(_folder_name): - os.makedirs(_folder_name) - - time_in_seconds = self.all_data['Ambient data']['Time in seconds'] - if self.all_data['Processed data']['Reanalysis time']: - reanalysis_time = self.all_data['Processed data'][ - 'Reanalysis time in seconds'] - else: - reanalysis_time = None - - self.message = message - - print(message, flush=True) - - self.folder_name = _folder_name - - save_fig_thread = self.SaveFigureThread( - self, self.folder_name, time_in_seconds, reanalysis_time) - save_fig_thread.finished.connect(save_fig_thread_finished) - - save_fig_thread.start() - time.sleep(0.05) - - - - - @Slot() - def closeEvent(self, event): - - if not self.verify_close_event(): - event.ignore() - return - - BaseWindow.closeEvent(self, event) - - @Slot() - def show_about(self): - """ To overide by application - """ - QApplication.processEvents() - QMessageBox.about( - self, "About", - """{0} v {1} -

Copyright © Paul Scherrer Institut (PSI). - All rights reserved.

-

Author: J. Chrin, Spring 2023

-

(EPICS db adapted from A. Kovach, 2016)

-

IOC Administrator: H. Lutz

-

1st Responsible: A. Barchetti, Tel. 4779 - or 3301 (Control Room)

- -

Initiates energy saving procedures and records power saved

-

Python {2} - Qt {3} - PyQt {4}
- cafe {5} - epics {6} on {7}""".format( - _pymodule, _appversion, platform.python_version(), - QT_VERSION_STR, PYQT_VERSION_STR, - self.cafe.CAFE_version(), self.cafe.EPICS_version(), - platform.system())) - QApplication.processEvents() - - @Slot() - def show_help(self): - """ Invoke help pages from hush_resources - """ - index_html ="index.html" #self.appname + "/index.html" - help_base = ":" # + self.appname - help_page = HelpBrowser(help_base, index_html, self) - help_page.show() - -######################################################################### -if __name__ == "__main__": - - app = QApplication(sys.argv) - splash = BaseWindow.initialize_application( - app, appname=_appname, delay=20, facility=Facility.HIPA) - - myapp = StartMain() - - myapp.show() - - if splash is not None: - splash.finish(myapp) - - app.exec_() - diff --git a/hush.sh~ b/hush.sh~ deleted file mode 100755 index a980a90..0000000 --- a/hush.sh~ +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -cd /afs/psi.ch/project/pyqtacc/apps4ops/examples/hush/1.0.0 - -# For use if script is sourced rather than executed -appNameDefault="hush.sh" - -module unload gcc -module load gcc/7.3.0 - -if [ -z "$PS1" ] # no prompt? -### if [ -v PS1 ] # On Bash 4.2+ ... -then - # non-interactive - echo "Non-interactive script" -else - # interactive - echo "Interactive/sourced script" -fi - -# Select Python Version here. Currently one of 3.5, 3.7 -PYTHON_VERSION=3.7 - -if [ "$1" ]; then - - if [ "$1" == "3.5" -o "$1" == "35" ]; then - echo "Using default version $PYTHON_VERSION" - elif [ "$1" == "3.7" -o "$1" == "37" ]; then - PYTHON_VERSION=3.7 - else - echo "Requested Python version is not supported" - echo "Using default version $PYTHON_VERSION" - fi - -fi - -echo "PYTHON_VERSION $PYTHON_VERSION" - - -_EPICS_HOST_ARCH=${EPICS_HOST_ARCH} -. /opt/gfa/python $PYTHON_VERSION - -#/sf/bd/applications/OnlineModel/current/PythonModule:/sf/bd/applications/OnlineModel/current -#/sf/bd/applications/OnlineModel/default/scripts/VA: - -#C_EXT version for Py 3.7: -export PYTHONPATH=.:/opt/gfa/cafe/python/pycafe/cafe-1.18.0/lib/${_EPICS_HOST_ARCH}:/afs/psi.ch/project/pyqtacc:/afs/psi.ch/intranet/SLS/Controls/BD/pyqtacc/v1.5.2 - -echo $PYTHONPATH - -STDOUT_DIR="/tmp" -#Set to 0 if you do not wish std::out to write to logger -STDOUT_FLAG=1 - -if [ "$#" -gt "0" ]; then - appName=$0 - if [ "$appName" == "-bash" ]; then - appName=$appNameDefault - fi -else -appName=$appNameDefault -fi - -#echo "$appName $@ $#" -baseName="${appName##*/}" -name=$(echo "$baseName" | cut -f 1 -d '.') -nameLog=${name}-$USER -echo "Application: $name" -echo "nameLog: $nameLog" - -#Configuration files can be overwritten -#python ${name}.py -s="/sf/bd/deps/pyqtacc/common/config/style.json" -f="/sf/bd/deps/pyqtacc/v1.0.0/pyqtacc/qrc_resources/facility/sf/config/base.json" -q="/sf/bd/deps/pyqtacc/common/config/acc.qss" & - -if [ "${STDOUT_FLAG}" -gt "0" ] ; then -#if changing the std::out destination, remember to also change it in your json config file (for reading) - if test -f "$STDOUT_DIR/${nameLog}.log---"; then - rm -f $STDOUT_DIR/${nameLog}.log--- - fi - if test -f "$STDOUT_DIR/${nameLog}.log--"; then - cp $STDOUT_DIR/${nameLog}.log-- $STDOUT_DIR/${nameLog}.log--- - rm -f $STDOUT_DIR/${nameLog}.log-- - fi - if test -f "$STDOUT_DIR/${nameLog}.log-"; then - cp $STDOUT_DIR/${nameLog}.log- $STDOUT_DIR/${nameLog}.log-- - rm -f $STDOUT_DIR/${nameLog}.log- - fi - if test -f "$STDOUT_DIR/${nameLog}.log"; then - cp $STDOUT_DIR/${nameLog}.log $STDOUT_DIR/${nameLog}.log- - rm -f $STDOUT_DIR/${nameLog}.log - fi - - python ${name}.py -u ${name}.json >> $STDOUT_DIR/${nameLog}.log 2>&1 & - chmod 777 $STDOUT_DIR/${nameLog}.log -else -#Run instead without std::out - python ${name}.py -u ${name}.json & -fi - - diff --git a/src/gui.py- b/src/gui.py- deleted file mode 100644 index e57fa8f..0000000 --- a/src/gui.py- +++ /dev/null @@ -1,542 +0,0 @@ -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 diff --git a/src/gui.py~ b/src/gui.py~ deleted file mode 100644 index 153ead6..0000000 --- a/src/gui.py~ +++ /dev/null @@ -1,596 +0,0 @@ -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