mirror of
https://gitlab.psi.ch/pyqtacc/proscan.git
synced 2025-12-30 18:33:30 +01:00
249 lines
8.8 KiB
Python
249 lines
8.8 KiB
Python
import inspect
|
|
import os
|
|
import socket
|
|
import time
|
|
|
|
from qtpy.QtCore import Qt
|
|
from qtpy.QtWidgets import (QComboBox, QDialog, QFileDialog, QHBoxLayout,
|
|
QLabel, QLineEdit, QPushButton, QTextEdit,
|
|
QVBoxLayout)
|
|
|
|
import elog # https://github.com/paulscherrerinstitute/py_elog
|
|
from pyqtacc.bdbase.enumkind import MsgSeverity
|
|
|
|
from pyqtacc.bdbase.sendelogframe import QSendToELOGFrame
|
|
|
|
_version = "1.0.0"
|
|
_pymodule = os.path.basename(__file__)
|
|
_appname, _appext = _pymodule.split(".")
|
|
_hostname = socket.gethostname().split(".")[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 QSendToELOG(QSendToELOGFrame):
|
|
""" Graphical interface to elog
|
|
"""
|
|
def __init__(self, parent, logbook=None, eintragIdx=1,
|
|
systemIdx=0, statusIdx=0, effektIdx=0, title=None,
|
|
message=None, attachFile=None, destination_folder=None):
|
|
|
|
super().__init__(parent, logbook=logbook, title=title, message=message)
|
|
|
|
#First check what is the logbook being requested?
|
|
#find layout items
|
|
self.layout_items = self.get_logbook_specific_items(self.logbook)
|
|
self.layout_to_widget_dict = {}
|
|
|
|
|
|
self.eintrag_idx = eintragIdx
|
|
self.system_idx = systemIdx
|
|
self.effekt_idx = effektIdx
|
|
|
|
self.status_idx = statusIdx
|
|
|
|
|
|
#print("indices", self.eintrag_idx, self.system_idx, flush=True)
|
|
|
|
self.eintrag = None
|
|
self.system = None
|
|
self.effekt = None
|
|
self.estatus = None
|
|
self.konsole = None
|
|
|
|
|
|
|
|
#print("LAYOUT ITEMS: ", self.layout_items)
|
|
|
|
self.sim_list = ["Sand", "test"]
|
|
|
|
self.initialize_layout(self.logbook)
|
|
self.exec()
|
|
|
|
def reset_layout(self):
|
|
def remove_wgt(wgt):
|
|
self.layout.removeItem(wgt)
|
|
while wgt.count():
|
|
item = wgt.takeAt(0)
|
|
widget = item.widget()
|
|
widget.deleteLater()
|
|
|
|
for layout in self.get_logbook_specific_items(self.logbook):
|
|
remove_wgt(self.layout_to_widget_dict[layout])
|
|
|
|
|
|
def create_layout_widgets(self):
|
|
|
|
|
|
if not self.eintrag:
|
|
self.eintrag = QHBoxLayout()
|
|
self.eintrag.addWidget(QLabel('Eintrag: '))
|
|
self.eintrag_items = QComboBox()
|
|
self.eintrag_items.setObjectName("Elog")
|
|
self.eintrag.addWidget(self.eintrag_items)
|
|
self.layout_to_widget_dict['Eintrag'] = self.eintrag
|
|
|
|
if not self.system:
|
|
self.system = QHBoxLayout()
|
|
self.system.addWidget(QLabel('System: '))
|
|
self.system_items = QComboBox()
|
|
self.system_items.setObjectName("Elog")
|
|
self.system.addWidget(self.system_items)
|
|
self.layout_to_widget_dict['System'] = self.system
|
|
|
|
if not self.effekt:
|
|
self.effekt = QHBoxLayout()
|
|
self.effekt.addWidget(QLabel('Effekt: '))
|
|
self.effekt_items = QComboBox()
|
|
self.effekt_items.setObjectName('Elog')
|
|
self.effekt.addWidget(self.effekt_items)
|
|
self.layout_to_widget_dict['Effekt'] = self.effekt
|
|
|
|
if not self.estatus:
|
|
self.estatus = QHBoxLayout()
|
|
self.estatus.addWidget(QLabel('Status: '))
|
|
self.estatus_items = QComboBox()
|
|
self.estatus_items.setObjectName("Elog")
|
|
self.estatus.addWidget(self.estatus_items)
|
|
self.layout_to_widget_dict['Status'] = self.estatus
|
|
|
|
'''
|
|
if not self.konsole:
|
|
self.konsole = QHBoxLayout()
|
|
self.konsole.addWidget(QLabel('Konsole: '))
|
|
self.konsole_le = QLineEdit()
|
|
self.konsole_le.setObjectName('Elog')
|
|
self.konsole_le.setText(_hostname)
|
|
self.konsole_le.setFixedWidth(100)
|
|
self.konsole_le.setAlignment(Qt.AlignCenter)
|
|
self.konsole.addWidget(self.konsole_le)
|
|
self.layout_to_widget_dict['Konsole'] = self.konsole
|
|
'''
|
|
|
|
def initialize_layout(self, logbook):
|
|
|
|
print("initialize_layout", self.layout_items, flush=True)
|
|
|
|
#Decide on layout
|
|
self.create_layout_widgets()
|
|
|
|
item_no = 2 # if "Proscan" in logbook else 2
|
|
|
|
if 'Eintrag' in self.layout_items:
|
|
self.eintrag_items.clear()
|
|
self.eintrag_items.addItems(list(self.parent.settings.data[
|
|
'ElogBooks'][logbook]['Required']['Eintrag']))
|
|
self.eintrag_items.setCurrentIndex(self.eintrag_idx)
|
|
self.layout.insertLayout(item_no, self.eintrag)
|
|
if 'Effekt' in self.layout_items:
|
|
item_no += 1
|
|
self.effekt_items.clear()
|
|
self.effekt_items.addItems(list(self.parent.settings.data[
|
|
'ElogBooks'][logbook]['Optional']['Effekt']))
|
|
self.effekt_items.setCurrentIndex(self.effekt_idx)
|
|
self.layout.insertLayout(item_no, self.effekt)
|
|
if 'System' in self.layout_items:
|
|
item_no += 1
|
|
self.system_items.clear()
|
|
self.system_items.addItems(list(self.parent.settings.data[
|
|
'ElogBooks'][logbook]['Optional']['System']))
|
|
self.system_items.setCurrentIndex(self.system_idx)
|
|
self.layout.insertLayout(item_no, self.system)
|
|
if 'Status' in self.layout_items:
|
|
item_no += 1
|
|
self.estatus_items.clear()
|
|
self.estatus_items.addItems(list(self.parent.settings.data[
|
|
'ElogBooks'][logbook]['Optional']['Status']))
|
|
self.estatus_items.setCurrentIndex(self.status_idx)
|
|
self.layout.insertLayout(item_no, self.estatus)
|
|
|
|
if 'Konsole' in self.layout_items:
|
|
item_no += 1
|
|
self.layout.insertLayout(item_no, self.konsole)
|
|
|
|
print("self.attachFile==>", self.parent.attach_files)
|
|
|
|
self.attachFile = self.parent.attach_files
|
|
self.filesE.clear()
|
|
self.files_text = ''
|
|
|
|
if self.attachFile is not None:
|
|
_attachFile = []
|
|
if isinstance(self.attachFile, str):
|
|
_attachFile.append(self.attachFile)
|
|
elif isinstance(self.attachFile, list):
|
|
_attachFile = self.attachFile
|
|
for i, file in enumerate(_attachFile):
|
|
_attach_base = os.path.basename(file)
|
|
if i > 0:
|
|
self.files_text += "\n"
|
|
self.files_text += str(_attach_base)
|
|
self.filesE.setText(self.files_text)
|
|
self.fflag = True
|
|
|
|
if any(substring.upper() in logbook.upper() \
|
|
for substring in self.sim_list):
|
|
_bgcolor = "QComboBox {background: plum; color : black;}"
|
|
else:
|
|
_bgcolor = "QComboBox {background: lightblue; color : black;}"
|
|
self.elog_items.setStyleSheet(_bgcolor)
|
|
|
|
#have to remove widgets within layout too!
|
|
#https://riverbankcomputing.com/pipermail/pyqt/2009-November/025214.html
|
|
def on_elog_change(self, idx):
|
|
|
|
#print(self.elog_items.currentText(), "new=", idx)
|
|
#print(self.elog_items.itemText(idx))
|
|
#print(self.logbook)
|
|
|
|
new_logbook = self.elog_items.itemText(idx)
|
|
|
|
#Meet the new logbook. Same as the old logbook
|
|
if new_logbook == self.logbook:
|
|
return
|
|
|
|
self.layout_items = self.get_logbook_specific_items(new_logbook)
|
|
print("self.layout_items", self.layout_items)
|
|
|
|
|
|
if any(substring.upper() in new_logbook.upper() \
|
|
for substring in self.sim_list):
|
|
_bgcolor = "QComboBox {background: plum; color : black;}"
|
|
else:
|
|
_bgcolor = "QComboBox {background: lightblue; color : black;}"
|
|
|
|
self.reset_layout()
|
|
self.initialize_layout(new_logbook)
|
|
|
|
self.elog_items.setStyleSheet(_bgcolor)
|
|
self.logbook = new_logbook
|
|
|
|
def ok(self):
|
|
|
|
el = self.elog_items.currentText()
|
|
|
|
|
|
if 'Eintrag' in self.layout_items:
|
|
self.attributes['Eintrag'] = self.eintrag_items.currentText()
|
|
if 'Effekt' in self.layout_items:
|
|
self.attributes['Effekt'] = self.effekt_items.currentText()
|
|
if 'System' in self.layout_items:
|
|
self.attributes['System'] = self.system_items.currentText()
|
|
|
|
if 'Status' in self.layout_items:
|
|
self.attributes['Status'] = self.estatus_items.currentText()
|
|
if 'Konsole' in self.layout_items:
|
|
self.attributes['Konsole'] = self.konsole_le.text()
|
|
|
|
QSendToELOGFrame.ok(self)
|
|
|
|
|