sendelogsls modified

This commit is contained in:
2023-01-06 14:32:13 +01:00
parent fbc432f475
commit 0bce9ecc89
2 changed files with 229 additions and 82 deletions

View File

@@ -6,6 +6,8 @@ class ElogSLS:
self.eintrag = self.Eintrag(0)
self.projekt = self.Projekt(0)
self.system = self.System(0)
self.auto = self.Auto(0)
self.status = self.Status(0)
class Eintrag(IntEnum):
PROBLEM = 0
@@ -72,3 +74,13 @@ class ElogSLS:
WATER_COOLING = 15
OTHER = 16
UNKNOWN = 17
class Auto(IntEnum):
NONE = 0
YES = 1
NO = 2
class Status(IntEnum):
NONE = 0
OFFEN = 1
GESCHLOSSEN = 2

View File

@@ -32,7 +32,7 @@ class QSendToELOG(QSendToELOGFrame):
""" Graphical interface to elog
"""
def __init__(self, parent, logbook=None, projektIdx=0, eintragIdx=0,
systemIdx=0, effektIdx=0, title=None, message=None,
systemIdx=0, statusIdx=0, autoIdx=2, title=None, message=None,
attachFile=None, destination_folder=None):
#super(QSendToELOGFrame, self).__init__(
@@ -40,101 +40,219 @@ class QSendToELOG(QSendToELOGFrame):
# attachFile=attachFile,
# destination_folder=destination_folder)
super().__init__(parent, logbook=logbook, title=title)
super().__init__(parent, logbook=logbook, title=title, message=message)
#First check what is the logbook being requested?
#find layout items
layout_items = []
layout_items_optional = []
try:
layout_items = list(self.parent.settings.data["ElogBooks"][self.logbook]['Required'].keys())
except KeyError:
pass
try:
layout_items_optional = list(self.parent.settings.data["ElogBooks"][self.logbook]['Optional'].keys())
except KeyError:
pass
self.layout_items = self.get_logbook_specific_items(self.logbook)
self.layout_to_widget_dict = {}
self.projekt_idx = projektIdx
self.eintrag_idx = eintragIdx
self.system_idx = systemIdx
self.status_idx = statusIdx
self.auto_idx = autoIdx
layout_items.extend(layout_items_optional)
print("LAYOUIT ITEMS: ", layout_items)
print("indices", self.projekt_idx, self.eintrag_idx, self.system_idx, self.auto_idx)
self.projekt = None
self.eintrag = None
self.system = None
self.effekt = None
self.estatus = None
self.auto = None
#print(self.parent.settings.data["Elog"])
projekt_str = list(self.parent.settings.data["ElogBooks"]['SLS+Development']['Required']['Projekt'])
self.projekt = QHBoxLayout()
self.projekt.addWidget(QLabel('Projekt: '))
self.projekt_items = QComboBox()
self.projekt_items.setObjectName("Elog")
self.projekt_items.addItems(projekt_str)
self.projekt.addWidget(self.projekt_items)
self.projekt_items.setCurrentIndex(projektIdx)
print("LAYOUT ITEMS: ", self.layout_items)
#eintrag_str = list(self.parent.settings.data["Elog"]['Eintrag'])
eintrag_str = list(self.parent.settings.data['ElogBooks']['Sandkasten']['Required']['Eintrag'])
self.eintrag = QHBoxLayout()
self.eintrag.addWidget(QLabel('Eintrag: '))
self.eintrag_items = QComboBox()
self.eintrag_items.setObjectName("Elog")
self.eintrag_items.addItems(eintrag_str)
self.eintrag.addWidget(self.eintrag_items)
self.eintrag_items.setCurrentIndex(eintragIdx)
self.system = QHBoxLayout()
self.system.addWidget(QLabel('System: '))
self.system_items = QComboBox()
self.system_items.setObjectName("Elog")
self.system_items.addItems(
#list(self.parent.settings.data["Elog"]['System']))
list(self.parent.settings.data['ElogBooks']['SLS']['Optional']['System']))
self.system.addWidget(self.system_items)
self.system_items.setCurrentIndex(systemIdx)
self.effekt_lo = QHBoxLayout()
self.effekt_lo.addWidget(QLabel('Effekt: '))
self.effekt = QLineEdit()
self.effekt.setObjectName('Elog')
self.effekt.setText(str(""))
self.effekt.setFixedWidth(300)
self.effekt.setAlignment(Qt.AlignCenter)
self.effekt_lo.addWidget(self.effekt)
self.estatus = QHBoxLayout()
self.estatus.addWidget(QLabel('Status: '))
self.estatus_items = QComboBox()
self.estatus_items.setObjectName("Elog")
self.estatus_items.addItems(
list(self.parent.settings.data['ElogBooks']['Sandkasten']['Optional']['Status']))
self.estatus.addWidget(self.estatus_items)
self.estatus_items.setCurrentIndex(0)
#Decide on original layout
self.layout.insertLayout(2, self.projekt)
self.layout.insertLayout(3, self.eintrag)
self.layout.insertLayout(4, self.effekt_lo)
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.projekt:
self.projekt = QHBoxLayout()
self.projekt.addWidget(QLabel('Projekt: '))
self.projekt_items = QComboBox()
self.projekt_items.setObjectName("Elog")
self.projekt.addWidget(self.projekt_items)
self.layout_to_widget_dict['Projekt'] = self.projekt
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_le = QLineEdit()
self.effekt_le.setObjectName('Elog')
self.effekt_le.setText(str(""))
self.effekt_le.setFixedWidth(300)
self.effekt_le.setAlignment(Qt.AlignCenter)
self.effekt.addWidget(self.effekt_le)
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.auto:
self.auto = QHBoxLayout()
self.auto.addWidget(QLabel('auto: '))
self.auto_items = QComboBox()
self.auto_items.setObjectName("Elog")
self.auto.addWidget(self.auto_items)
self.layout_to_widget_dict['auto'] = self.auto
def initialize_layout(self, logbook):
#Decide on layout
self.create_layout_widgets()
item_no = 2
if 'Projekt' in self.layout_items:
self.projekt_items.clear()
self.projekt_items.addItems(list(self.parent.settings.data[
"ElogBooks"][logbook]['Required']['Projekt']))
self.projekt_items.setCurrentIndex(self.projekt_idx)
self.layout.insertLayout(item_no, self.projekt)
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.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 'auto' in self.layout_items:
item_no += 1
self.auto_items.clear()
self.auto_items.addItems(list(self.parent.settings.data[
'ElogBooks'][logbook]['Optional']['auto']))
self.auto_items.setCurrentIndex(self.auto_idx)
self.layout.insertLayout(item_no, self.auto)
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, elog_change_val):
def on_elog_change(self, idx):
sim_list = ["Sand"]
if any(substring.upper() in self.elog_items.currentText().upper() for substring in sim_list):
#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)
'''
#Acquire New Layout List
new_items = self.get_logbook_specific_items(new_logbook)
#Acquire Current Layout List
old_items = self.get_logbook_specific_items(self.logbook)
#Compare lists and remove Layouts that do not belong
common_items = list(set(new_items) & set(old_items))
print("common items", common_items)
#remove common_items from old_items
#unwanted_items = [ele for ele in old_items if ele not in common_items]
#print("unwamted items", unwanted_items)
unwanted_items = [ele for ele in old_items if ele not in new_items]
print("unwamted items", unwanted_items)
#Add Layouts that are new
wanted_items = [ele for ele in new_items if ele not in old_items]
print("wanted items", wanted_items)
'''
if any(substring.upper() in new_logbook.upper() \
for substring in self.sim_list):
_bgcolor = "QComboBox {background: plum; color : black;}"
self.layout.removeItem(self.projekt)
while self.projekt.count():
item = self.projekt.takeAt(0)
widget = item.widget()
widget.deleteLater()
else:
_bgcolor = "QComboBox {background: lightblue; color : black;}"
self.elog_items.setStyleSheet(_bgcolor)
self.reset_layout()
self.initialize_layout(new_logbook)
self.elog_items.setStyleSheet(_bgcolor)
self.logbook = new_logbook
def ok(self):
@@ -145,21 +263,37 @@ class QSendToELOG(QSendToELOGFrame):
#self.attributes['Projekt'] = proj
el = self.elog_items.currentText()
if 'Projekt' in self.layout_items:
self.attributes['Projekt'] = self.projekt_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_le.text()
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 'auto' in self.layout_items:
self.attributes['auto'] = self.auto_items.currentText()
'''
if el == 'SLS':
self.attributes['Eintrag'] = self.eintrag_items.currentText()
self.attributes['Effekt'] = self.effekt.text()
self.attributes['Effekt'] = self.effekt_le.text()
self.attributes['System'] = self.system_items.currentText()
elif el == 'Sandkasten':
self.attributes['Eintrag'] = self.eintrag_items.currentText()
self.attributes['Status'] = "Geschlossen"
self.attributes['When'] = str(time.time())
self.attributes['Wann'] = str(time.time())
'''
QSendToELOGFrame.ok(self)
#self.close()
'''
def clearFiles(self):
self.attachFile = []
self.filesE.clear()
@@ -188,7 +322,7 @@ class QSendToELOG(QSendToELOGFrame):
def receive_elog_notification(self, is_accepted, logbook_url, elog_message):
'''Receive notification from ELOG, and report to log window'''
#Receive notification from ELOG, and report to log window
yes_no = "made" if is_accepted else "failed"
mess = "Entry into ELOG: {0} {1}".format(logbook_url, yes_no)
@@ -201,3 +335,4 @@ class QSendToELOG(QSendToELOGFrame):
self.parent.show_log_message(MsgSeverity.WARN, self.pymodule,
_line(), mess)
self.parent.statusbar.showMessage(mess)
'''