This commit is contained in:
2022-06-28 13:56:16 +02:00
parent cedb77d270
commit 6f6f69a303
5 changed files with 48 additions and 18945 deletions

71
base.py
View File

@@ -12,8 +12,6 @@ import os
import sys
import time
#import numpy as np
# Third-party modules
from qtpy.QtCore import (PYQT_VERSION_STR, QEventLoop, QFile, QIODevice,
QSettings, QSize, Qt, QThread, QTimer, Signal, Slot)
@@ -97,10 +95,14 @@ class BaseWindow(QMainWindow):
attach_files = []
folder_name = self.folder_name
print("Running SaveFigureThread, folder_name=", folder_name, flush=True)
date_str = self.parent.add_date_to_path(
time_in_seconds=self.time_in_seconds,
reanalysis_time_in_seconds=self.reanalysis_time)
print("date_str", date_str, flush=True)
for i, (nfig, name) in enumerate(
zip(self.settings.data["GUI"]["resultsSeq"],
self.settings.data["GUI"]["subResultsTabTitle"])):
@@ -114,6 +116,7 @@ class BaseWindow(QMainWindow):
idx) if idx > 0 else name_base
save_dest = (folder_name + date_str + '_' + name +
'.png')
print("idx", i, save_dest, flush=True)
if not os.path.exists(save_dest):
if self.all_data['Figure data'][canvas][
idx] is not None:
@@ -121,13 +124,12 @@ class BaseWindow(QMainWindow):
idx].savefig(save_dest)
attach_files.append(save_dest)
##self.parent.attach_files = attach_files
if attach_files:
self.parent.attach_files = attach_files
print("All files attached")
else:
print("No files to attach", flush=True)
time.sleep(0.2) #
time.sleep(0.2) #avoid race condition
class HDFSave(QThread):
"""Thread for hdf analysis
@@ -173,27 +175,20 @@ class BaseWindow(QMainWindow):
#self.parent.trigger_log_message.emit(MsgSeverity.INFO.name,
# _pymodule, _line(),
# mess, {})
isOK = [True] * 3
try:
with h5py.File(self.parent.hdf_filename, 'w') as dataH5:
isOK[0] = self.parent.add_pvs_to_hdf(
self.parent.add_pvs_to_hdf(
dataH5, pv_list=self.parent.pv_machine_list,
from_hdf=from_hdf)
isOK[1] = self.parent.add_general_to_hdf(dataH5)
isOK[2] = self.parent.add_to_hdf(dataH5, proc=True,
raw=True)
self.parent.add_general_to_hdf(dataH5)
self.parent.add_to_hdf(dataH5, proc=True, raw=True)
self.parent.hdf_save_completed = True
base_mess = "Processed data saved" \
if False not in isOK \
else "Data integrity errors in saving"
show_mess = "{0} to {1}".format(
base_mess, self.parent.hdf_filename)
_mess = "Processed data saved to {}".format(
self.parent.hdf_filename)
self.parent.trigger_log_message.emit(
MsgSeverity.INFO.name, _pymodule, _line(),
show_mess, {})
MsgSeverity.INFO.name, _pymodule, _line(), _mess, {})
except OSError as e:
_mess = "OSError in saving to file {0}: {1}".format(
self.parent.hdf_filename, str(e))
@@ -220,6 +215,7 @@ class BaseWindow(QMainWindow):
def run(self):
"""Run hdf thread
"""
self.all_data = self.analysis_procedure.load_hdf_file(
self.hdf_filename_loaded)
@@ -258,16 +254,13 @@ class BaseWindow(QMainWindow):
MsgSeverity.ERROR.name, _pymodule, _line(), mess, {})
class AnalysisThread(QThread): #QRunnable does not have status methods
#e.g. isRunning()
#nor supports signals and slots
class AnalysisThread(QThread):
"""Analysis thread
"""
trigger_thread_event = Signal(dict)
def __init__(self, parent, analysis_procedure, input_parameters):
#QThread.__init__(self)
super().__init__()
QThread.__init__(self)
self.parent = parent
self.analysis_procedure = analysis_procedure
self.input_parameters = input_parameters
@@ -279,7 +272,7 @@ class BaseWindow(QMainWindow):
def __del__(self):
self.wait()
def run(self):
"""Run thread
"""
@@ -314,7 +307,7 @@ class BaseWindow(QMainWindow):
self.facility = facility
self.user_mode = user_mode
self.appname, self.appext = self.pymodule.split(".")
print("=============================================")
print("Starting {0} at: {1}".format(self.appname, datetime.now()))
print("User: {0} Host: {1}".format(os.getlogin(), os.uname()[1]))
@@ -369,7 +362,7 @@ class BaseWindow(QMainWindow):
self.elog_dest = self.settings.data["Elog"]["destination"]
self.screenshot_dest = self.settings.data["screenshot"]["destination"]
self.stdlog_dest = (self.settings.data["stdlog"]["destination"] +
self.appname + ".log")
self.appname + "-" + os.getlogin() + ".log")
self.date_str = None
self.autopost_elog = True
@@ -1027,7 +1020,6 @@ class BaseWindow(QMainWindow):
isOK = True
if not pv_list:
return
@@ -1038,24 +1030,21 @@ class BaseWindow(QMainWindow):
dt_name_top = key1 + "/"
for key2, value in self.all_data[top_group][key1].items():
dt_name = dt_name_top + key2
#print("dt_name", dt_name, value[()])
#TEST
#value = np.array([1,2,3], dtype=np.dtype('O'))
try:
grp_data.create_dataset(dt_name, data=value[()])
except TypeError as err:
isOK = False
_mess = ("Error in saving to HDF ['{0}']['{1}']. " +
"{2}").format(top_group, dt_name, str(err))
print(_mess, flush=True)
self.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, _line(), _mess,
{})
return isOK
if from_hdf:
return isOK
self.cafe.attachContext(pv_list[0])
for pv in pv_list:
self.cafe.setGetActionWhenMonitorPolicy(
@@ -1068,15 +1057,17 @@ class BaseWindow(QMainWindow):
k = key.split("-", 1)
dt_name = k[0] + "/" + k[1]
try:
#value = np.array([1,2,3], dtype=np.dtype('O'))
grp_data.create_dataset(dt_name, data=value)
except TypeError as err:
isOK = False
_mess = ("Error in saving to HDF ['{0}']['{1}'] " +
"{2}").format(dt_name, top_group, str(err))
print(_mess, flush=True)
self.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, _line(), _mess, {})
return isOK
def add_general_to_hdf(self, dataH5):
isOK = True
@@ -1109,17 +1100,17 @@ class BaseWindow(QMainWindow):
for key in user_dict:
lowkey = key.lower()
try:
##TEST
##user_dict[key] = np.array([1,2,3], dtype=np.dtype('O'))
grp_data.create_dataset(lowkey.replace(' ', '_'),
data=user_dict[key])
except TypeError as err:
isOK = False
_mess = ("Error in saving to HDF ['general']['{0}']. " +
"{1}").format(key, str(err))
"{1}").format(key, str(err))
print(_mess, flush=True)
self.trigger_log_message.emit(
MsgSeverity.WARN.name, _pymodule, _line(), _mess, {})
return isOK
@Slot()
def save_to_hdf_dialog(self):
@@ -1648,17 +1639,15 @@ class BaseWindow(QMainWindow):
self.analysis_thread = self.AnalysisThread(
self, self.analysis_procedure, self.input_parameters)
#pool = QThreadPool.globalInstance()
self.analysis_thread.trigger_thread_event.connect(
self.receive_analysis_results)
self.analysis_thread.started.connect(self.analysis_thread_started)
self.analysis_thread.finished.connect(self.analysis_thread_finished)
#pool.start(self.analysis_thread)
#getMachineDatafor hdf
self.analysis_thread.start()
QApplication.processEvents()

View File

@@ -172,7 +172,6 @@ class GUIFrame(QWidget):
self.measurement_tab_wgt.addTab(self.expert_wgt, "Expert")
self.measurement_layout.addWidget(self.measurement_tab_wgt, 0, 0)
def init_results_tab_wgt(self):
""" Add canvas tabs for plots/results
"""
@@ -879,11 +878,13 @@ class GUIFrame(QWidget):
#print(self.left_arrow_dict[self.sender()])
self.next_figure(self.left_arrow_dict[self.sender()], -1)
def on_toggle_right(self): #(self, is_clicked)
#print(self.sender())
#print(self.right_arrow_dict[self.sender()])
self.next_figure(self.right_arrow_dict[self.sender()], 1)
def next_figure(self, det=0, idx=0):
if det not in self.canvas_fig_dict:
@@ -1130,6 +1131,9 @@ class GUIFrame(QWidget):
read_pv.receive_monitor_update(init_value, pvdata.status,
pvdata.alarmSeverity)
if radiobutton_list[1].isChecked():
radiobutton_list[1].toggled.emit(True)
if read:
qpb = QPushButton(radiobutton_title[1])
qpb.setObjectName("Update")
@@ -1139,9 +1143,14 @@ class GUIFrame(QWidget):
grid.addWidget(qpb, 1, 1)
qpb.pressed.emit()
def update_manual_value(new_text):
if radiobutton_list[2].isChecked():
radiobutton_list[2].toggled.emit(True)
if manual:
manual_wgt = QLineEdit(str(manual_value))
manual_wgt.setObjectName("WriteCenter")
manual_wgt.textChanged.connect(update_manual_value)
manual_wgt.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
manual_wgt.setFixedHeight(self.widget_height)
manual_wgt.setFixedWidth(74)
@@ -1172,7 +1181,7 @@ class GUIFrame(QWidget):
if manual:
radio_buddy_text_dict[radiobutton_list[2]] = manual_wgt
idx = 1 if read else 0
idx = 0 #1 if read else 0
#print("idx", idx)
#print(radio_buddy_text_dict)
radiobutton_list[idx].setChecked(True)
@@ -1582,7 +1591,6 @@ class GUIFrame(QWidget):
self.expert_parameters_group.layout().addWidget(
self.checkbox_autoCycle())
if "keepImages" in self.parent.input_parameters.keys():
self.expert_parameters_group.layout().addWidget(
self.checkbox_keepImages())
@@ -1716,6 +1724,7 @@ class GUIFrame(QWidget):
self.table_tab_wgt.addTab(self.table_wgt[i], tab_text)
color = self.branches[i]['tabTextColor']
self.table_tab_wgt.tabBar().setTabTextColor(i, QColor(color))
self.table_tab_wgt.currentChanged.connect(on_table_tab_changed)
self.table_layout.addWidget(self.table_tab_wgt, 0, 0)

View File

@@ -1,67 +0,0 @@
import inspect
import platform
import os
import time
# Third-party modules
from qtpy.QtCore import (PYQT_VERSION_STR, Signal, Slot, QFile, QFileInfo,
QIODevice, QMutex, QSettings, QSize, Qt, QTimer,
qVersion)
from qtpy.QtCore import __version__ as QT_VERSION_STR, QTemporaryDir
from qtpy.QtGui import (QColor, QKeySequence, QFont, QIcon, QPainter, QPalette,
QPixmap)
from qtpy.QtPrintSupport import QPrinter, QPrintDialog
from qtpy.QtWidgets import (QAbstractItemView, QAction, QActionGroup,
QApplication, QButtonGroup, QComboBox, QDialog,
QDockWidget, QDoubleSpinBox, QFileDialog, QFrame,
QGridLayout, QGroupBox, QHBoxLayout, QLabel,
QLayout, QLineEdit, QListWidget, QMainWindow, QMenu,
QMenuBar, QMessageBox, QPlainTextEdit, QProgressBar,
QPushButton, QScrollArea, QSizePolicy, QSlider,
QSpinBox, QSplashScreen, QStyle, QStyleOptionSlider,
QToolButton, QVBoxLayout, QWidget)
import pyqtacc.bdbase.pyrcc5.qrc_resources
from pyqtacc.bdbase.enumkind import MsgSeverity, UsageMode
from pyqtacc.bdbase.readjson import ReadJSON
import PyCafe
_pymodule = os.path.basename(__file__)
_appname, _appext = _pymodule.split(".")
_appversion = "1.0.0"
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 MenuBar(QMainWindow):
""" MenuBar
"""
def __init__(self, parent=None, pymodule=None, appversion=None, title=""):
super(MenuBar, self).__init__(parent)
pass
def create_action(self, text, slot=None, shortcut=None, icon=None, tip=None,
checkable=False, signal="triggered()"):
action = QAction(text, self)
if icon is not None:
action.setIcon(QIcon(":/{0}.png".format(icon)))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
if slot is not None:
action.triggered.connect(slot)
if checkable:
action.setCheckable(True)
return action

File diff suppressed because it is too large Load Diff

View File

@@ -281,8 +281,8 @@ class QSendToELOG(QDialog):
self.logbook = elog.open(url, user='robot', password='robot')
print("send to elog: ", url)
print(message)
print("sendelog.py: ", url, flush=True)
print(message, flush=True)
try:
if self.files:
self.logbook.post(message, attributes=self.attributes,
@@ -294,11 +294,12 @@ class QSendToELOG(QDialog):
self.receive_elog_notification(True, url, "OK")
except Exception as ex:
#self.trigger_elog_entry.emit(False, url, str(ex))
print("Exception in sendelog.py", str(ex))
self.receive_elog_notification(False, url, str(ex))
for file in self.files:
if os.path.exists(file):
os.remove(file)
#for file in self.files:
# if os.path.exists(file):
# os.remove(file)
self.close()