sendelogsls.py uses bdbase.sendelogframe.py
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*.*~
|
||||
*.*-*
|
||||
*.*+*
|
||||
__pycache__
|
||||
@@ -0,0 +1,2 @@
|
||||
sendelogsls.py inherits from bdbase.sendelogframe
|
||||
enumkind.py has ELogSLS enum options defined
|
||||
90
enumkind.py
90
enumkind.py
@@ -3,38 +3,72 @@ from enum import IntEnum
|
||||
|
||||
class ElogSLS:
|
||||
def __init__(self):
|
||||
self.category = self.Category(0)
|
||||
self.domain = self.Domain(0)
|
||||
self.eintrag = self.Eintrag(0)
|
||||
self.projekt = self.Projekt(0)
|
||||
self.system = self.System(0)
|
||||
|
||||
class Category(IntEnum):
|
||||
INFO = 0
|
||||
MEASUREMENT = 1
|
||||
class Eintrag(IntEnum):
|
||||
PROBLEM = 0
|
||||
INFO = 1
|
||||
TUNING = 2
|
||||
OPERATION_CHANGE = 3
|
||||
BRIDGE = 4
|
||||
PIKETT = 5
|
||||
STATUS = 6
|
||||
AK3 = 7
|
||||
TIPS = 8
|
||||
SHIFT_CHANGE = 9
|
||||
SHIFT_REPORT = 10
|
||||
|
||||
class Domain(IntEnum):
|
||||
NONE = 0
|
||||
INJECTOR = 1
|
||||
LINAC1 = 2
|
||||
LINAC2 = 3
|
||||
LINAC3 = 4
|
||||
ARAMIS = 5
|
||||
ARAMIS_BEAMLINES = 6
|
||||
ATHOS = 7
|
||||
ATHOS_BEAMLINES = 8
|
||||
class Projekt(IntEnum):
|
||||
BBA = 0
|
||||
BOOSTER = 1
|
||||
COUPLING = 2
|
||||
EMITTANCE = 3
|
||||
FILLING_PATTERNS = 4
|
||||
IDS = 5
|
||||
MBFM = 6
|
||||
OPTICS = 7
|
||||
LOW_BEAM_ENERGY = 8
|
||||
LOW_ALPHA = 9
|
||||
LIFETIME = 10
|
||||
RGM = 11
|
||||
PHOTON_MONITORS = 12
|
||||
STABILITY = 13
|
||||
BEAM_TRANSMISSIONS = 14
|
||||
LOSS_FACTOR_MEAS = 15
|
||||
BEAM_SIZE_MONITOR = 16
|
||||
ID_ALIGNMENT = 17
|
||||
BEAM_LOSS_MONITORS = 18
|
||||
SINGLE_TURN_BPM = 19
|
||||
INJECTION = 20
|
||||
CHARGE_MONITORING = 21
|
||||
ORBIT_CORRECTION = 22
|
||||
BUNCH_LENGTH_MEASUREMENT = 23
|
||||
LOSS_MEASUREMENT = 24
|
||||
TRIBS = 25
|
||||
ROBINSON_STABILITY = 26
|
||||
INJECTION_TRANSIENT = 27
|
||||
TBT_BPM_MEASUREMENT = 28
|
||||
LINAC_OPTMIZER = 29
|
||||
|
||||
|
||||
class System(IntEnum):
|
||||
NONE = 0
|
||||
BEAMDYNAMICS = 1
|
||||
CONTROLS = 2
|
||||
DIAGNOSTICS = 3
|
||||
ELECTRICSUPPLY = 4
|
||||
INSERTIONDEVICES = 5
|
||||
LASER = 6
|
||||
MAGNETPOWERSUPPLIES = 7
|
||||
OPERATION = 8
|
||||
RF = 9
|
||||
SAFETY = 10
|
||||
VACUUM = 11
|
||||
WATERCOOLING = 11
|
||||
OTHER = 12
|
||||
UNKNOWN = 13
|
||||
FEEDBACKS = 2
|
||||
CONTROLS = 3
|
||||
DIAGNOSTICS = 4
|
||||
ELECTRIC_SUPPLY = 5
|
||||
FRONTENDS = 6
|
||||
INSERTION_DEVICES = 7
|
||||
HF = 8
|
||||
TIMING = 9
|
||||
MAGNET_POWER_SUPPLIES = 10
|
||||
OPERATION = 11
|
||||
SU = 12
|
||||
PSYS = 13
|
||||
VACUUM = 14
|
||||
WATER_COOLING = 15
|
||||
OTHER = 16
|
||||
UNKNOWN = 17
|
||||
|
||||
365
sendelog.py
Normal file
365
sendelog.py
Normal file
@@ -0,0 +1,365 @@
|
||||
import getpass
|
||||
import inspect
|
||||
import os
|
||||
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
|
||||
|
||||
_version = "1.0.0"
|
||||
_pymodule = os.path.basename(__file__)
|
||||
_appname, _appext = _pymodule.split(".")
|
||||
|
||||
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(QDialog):
|
||||
""" Graphical interface to elog
|
||||
"""
|
||||
def __init__(self, parent, logbook=None, categoryIdx=0, domainIdx=0,
|
||||
systemIdx=0, sectionIdx=0, title=None, message=None,
|
||||
attachFile=None, destination_folder=None):
|
||||
#super(QSendToELOG, self).__init__(parent)
|
||||
super().__init__()
|
||||
|
||||
self.files_text = ''
|
||||
self.fflag = False
|
||||
self.parent = parent
|
||||
if destination_folder is None:
|
||||
self.destination = self.parent.elog_dest + " / " + self.parent.appname
|
||||
else:
|
||||
self.destination = destination_folder
|
||||
self.window_title = self.parent.appname + ": " + _appname
|
||||
self.pymodule = _pymodule
|
||||
|
||||
self.setWindowTitle(self.window_title)
|
||||
|
||||
elog_books = list(self.parent.settings.data["ElogBooks"])
|
||||
self.elog_items = QComboBox()
|
||||
self.elog_items.addItems(elog_books)
|
||||
self.elog_items.currentIndexChanged.connect(self.on_elog_change)
|
||||
idx = 0
|
||||
|
||||
if logbook is not None:
|
||||
try:
|
||||
idx = elog_books.index(logbook)
|
||||
except Exception:
|
||||
mess = "Index not found for logbook {0}".format(logbook)
|
||||
self.parent.show_log_message(MsgSeverity.WARN, self.pymodule,
|
||||
_line(), mess)
|
||||
else:
|
||||
try:
|
||||
idx = elog_books.index(self.parent.settings.data["Elog"][
|
||||
"book"])
|
||||
except Exception:
|
||||
logbook = self.parent.settings.data["Elog"]["book"]
|
||||
mess = "Index not found for logbook {0}".format(logbook)
|
||||
self.parent.show_log_message(MsgSeverity.WARN, self.pymodule,
|
||||
_line(), mess)
|
||||
|
||||
print("logbook", logbook)
|
||||
|
||||
self.elog_items.setCurrentIndex(idx)
|
||||
self.elog_items.currentIndexChanged.emit(idx)
|
||||
self.elog_items.setObjectName("Elog")
|
||||
|
||||
print(self.parent.settings.data["Elog"])
|
||||
category_str = list(self.parent.settings.data["Elog"]['Projekt'])
|
||||
print("logbook2", logbook)
|
||||
self.category = QHBoxLayout()
|
||||
self.category.addWidget(QLabel('Projekt: '))
|
||||
self.category_items = QComboBox()
|
||||
self.category_items.setObjectName("Elog")
|
||||
self.category_items.addItems(category_str)
|
||||
self.category.addWidget(self.category_items)
|
||||
self.category_items.setCurrentIndex(categoryIdx)
|
||||
|
||||
domain_str = list(self.parent.settings.data["Elog"]['Eintrag'])
|
||||
self.domain = QHBoxLayout()
|
||||
self.domain.addWidget(QLabel('Eintrag: '))
|
||||
self.domain_items = QComboBox()
|
||||
self.domain_items.setObjectName("Elog")
|
||||
self.domain_items.addItems(domain_str)
|
||||
self.domain.addWidget(self.domain_items)
|
||||
self.domain_items.setCurrentIndex(domainIdx)
|
||||
self.domain_items.currentIndexChanged.connect(self.on_domain_change)
|
||||
print("logbook2", logbook)
|
||||
|
||||
#self.elog_section = list(self.parent.settings.data["Elog"]['Effekt'])
|
||||
self.section = QHBoxLayout()
|
||||
self.section.addWidget(QLabel('Effekt: '))
|
||||
#self.section_items = QComboBox()
|
||||
#self.section_items.setObjectName("Elog")
|
||||
#self.section_items.addItems(self.elog_section[domainIdx])
|
||||
#self.section.addWidget(self.section_items)
|
||||
#self.section_items.setCurrentIndex(sectionIdx)
|
||||
self.effekt = QLineEdit()
|
||||
self.effekt.setObjectName('Elog')
|
||||
self.effekt.setText(str(""))
|
||||
self.effekt.setFixedWidth(300)
|
||||
self.effekt.setAlignment(Qt.AlignCenter)
|
||||
self.section.addWidget(self.effekt)
|
||||
|
||||
|
||||
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']))
|
||||
|
||||
self.system.addWidget(self.system_items)
|
||||
self.system_items.setCurrentIndex(systemIdx)
|
||||
print("logbook3", logbook)
|
||||
self.title_items = QHBoxLayout()
|
||||
self.title_items.addWidget(QLabel('Title: '))
|
||||
self.titleline = QLineEdit()
|
||||
self.titleline.setObjectName('Elog')
|
||||
self.titleline.setStatusTip('elog')
|
||||
if title is None:
|
||||
title = self.parent.appname
|
||||
self.titleline.setText(str(title))
|
||||
self.titleline.setFixedWidth(300)
|
||||
self.titleline.setAlignment(Qt.AlignCenter)
|
||||
self.title_items.addWidget(self.titleline)
|
||||
|
||||
self.applicationbox = QHBoxLayout()
|
||||
self.applicationbox.addWidget(QLabel('Application:'))
|
||||
self.applicationlabel = QLabel(self.parent.pymodule)
|
||||
self.applicationlabel.setObjectName("Elog")
|
||||
# self.applicationbox.addStretch()
|
||||
self.applicationbox.addWidget(self.applicationlabel)
|
||||
|
||||
logbook = QHBoxLayout()
|
||||
logbook.addWidget(QLabel('Logbook: '))
|
||||
logbook.addWidget(self.elog_items)
|
||||
|
||||
authorbox = QHBoxLayout()
|
||||
authorbox.addWidget(QLabel('Author: '))
|
||||
self.author = QLineEdit()
|
||||
self.author.setObjectName('Elog')
|
||||
self.author.setFixedWidth(195)
|
||||
self.author.setStatusTip('elog')
|
||||
self.author.setText(getpass.getuser())
|
||||
authorbox.addWidget(self.author)
|
||||
|
||||
self.files = []
|
||||
self.attributes = {}
|
||||
|
||||
self.layout = QVBoxLayout(self)
|
||||
self.layout.addLayout(logbook)
|
||||
self.layout.addLayout(self.applicationbox)
|
||||
self.layout.addLayout(self.category)
|
||||
self.layout.addLayout(self.domain)
|
||||
self.layout.addLayout(self.section)
|
||||
self.layout.addLayout(self.system)
|
||||
self.layout.addLayout(authorbox)
|
||||
self.layout.addLayout(self.title_items)
|
||||
print("here4", flush=True)
|
||||
report = QLabel('Report: ')
|
||||
self.layout.addWidget(report)
|
||||
self.message = QTextEdit(message)
|
||||
self.layout.addWidget(self.message)
|
||||
|
||||
filebox = QHBoxLayout()
|
||||
qlfile = QLabel('Attach:')
|
||||
qlfile.setAlignment(Qt.AlignTop)
|
||||
filebox.addWidget(qlfile)
|
||||
|
||||
self.filesE = QTextEdit()
|
||||
self.filesE.setAlignment(Qt.AlignTop)
|
||||
self.filesE.setFixedHeight(80)
|
||||
self.filesE.setReadOnly(True)
|
||||
|
||||
self.attachFile = attachFile
|
||||
|
||||
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
|
||||
|
||||
filebox.addWidget(self.filesE)
|
||||
|
||||
openCloseVBox = QVBoxLayout()
|
||||
self.openBtn = QPushButton('Add')
|
||||
self.openBtn.setAutoDefault(False)
|
||||
self.openBtn.clicked.connect(self.openFiles)
|
||||
openCloseVBox.addWidget(self.openBtn)
|
||||
|
||||
closeBtn = QPushButton('Clear')
|
||||
closeBtn.setAutoDefault(False)
|
||||
closeBtn.clicked.connect(self.clearFiles)
|
||||
openCloseVBox.addWidget(closeBtn)
|
||||
|
||||
filebox.addLayout(openCloseVBox)
|
||||
self.layout.addLayout(filebox)
|
||||
|
||||
btnLayout = QHBoxLayout()
|
||||
self.okBtn = QPushButton('Send')
|
||||
self.okBtn.setAutoDefault(False)
|
||||
self.okBtn.clicked.connect(self.ok)
|
||||
|
||||
self.cancelBtn = QPushButton('Cancel')
|
||||
self.cancelBtn.setAutoDefault(False)
|
||||
self.cancelBtn.clicked.connect(self.close)
|
||||
btnLayout.addWidget(self.okBtn)
|
||||
btnLayout.addWidget(self.cancelBtn)
|
||||
self.messagelbl = QLabel('')
|
||||
self.messagelbl.setStyleSheet("QLabel { color : red; }")
|
||||
self.layout.addWidget(self.messagelbl)
|
||||
self.layout.addLayout(btnLayout)
|
||||
print("logbook5", logbook)
|
||||
self.setMinimumWidth(440)
|
||||
self.exec()
|
||||
|
||||
def on_elog_change(self, elog_change_val):
|
||||
if "test" in self.elog_items.currentText():
|
||||
_bgcolor = "QComboBox {background: plum; color : black;}"
|
||||
else:
|
||||
_bgcolor = "QComboBox {background: lightblue; color : black;}"
|
||||
self.elog_items.setStyleSheet(_bgcolor)
|
||||
|
||||
def on_domain_change(self, i):
|
||||
self.section_items.clear()
|
||||
self.section_items.addItems(self.elog_section[i])
|
||||
|
||||
def ok(self):
|
||||
message = self.message.document().toPlainText()
|
||||
if not message:
|
||||
self.messagelbl.setText('Please enter a brief Report')
|
||||
return
|
||||
title = self.titleline.text()
|
||||
if not title:
|
||||
self.messagelbl.setText('Titel attribute is required')
|
||||
return
|
||||
cat = self.category_items.currentText()
|
||||
if not cat:
|
||||
self.messagelbl.setText('Projekt attribute is required')
|
||||
return
|
||||
|
||||
el = self.elog_items.currentText()
|
||||
|
||||
author = self.author.text()
|
||||
application = self.applicationlabel.text()
|
||||
self.attributes['Autor'] = author
|
||||
self.attributes['Author'] = author
|
||||
self.attributes['Application'] = application
|
||||
# if title is not None: #!= '':
|
||||
self.attributes['Titel'] = title
|
||||
self.attributes['Title'] = title
|
||||
self.attributes['Projekt'] = cat
|
||||
if el == 'SLS':
|
||||
self.attributes['Eintrag'] = self.domain_items.currentText()
|
||||
self.attributes['Effekt'] = self.effekt.text()
|
||||
self.attributes['System'] = self.system_items.currentText()
|
||||
self.attributes['When'] = str(time.time())
|
||||
self.attributes['Wann'] = str(time.time())
|
||||
|
||||
|
||||
|
||||
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 in range(0, len(_attachFile)):
|
||||
if "/tmp" in _attachFile[i]:
|
||||
self.files.append(str(_attachFile[i]))
|
||||
elif "/afs/psi.ch" in _attachFile[i]:
|
||||
self.files.append(str(_attachFile[i]))
|
||||
elif "/sls/bd/data/" in _attachFile[i]:
|
||||
self.files.append(str(_attachFile[i]))
|
||||
else:
|
||||
self.files.append(self.destination + str(_attachFile[i]))
|
||||
|
||||
url = self.parent.settings.data["ElogBooks"][el]["url"]
|
||||
|
||||
self.logbook = elog.open(url, user='robot', password='robot')
|
||||
|
||||
print("sendelog.py: ", url, flush=True)
|
||||
print(message, flush=True)
|
||||
try:
|
||||
if self.files:
|
||||
self.logbook.post(message, attributes=self.attributes,
|
||||
attachments=self.files)
|
||||
else:
|
||||
self.logbook.post(message, attributes=self.attributes)
|
||||
|
||||
#self.trigger_elog_entry.emit(True, url, "OK")
|
||||
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)
|
||||
|
||||
self.close()
|
||||
|
||||
|
||||
def clearFiles(self):
|
||||
self.attachFile = []
|
||||
self.filesE.clear()
|
||||
self.files = []
|
||||
self.files_text = ''
|
||||
self.fflag = False
|
||||
|
||||
def openFiles(self):
|
||||
# Notethat openFiles also gets called when qDialog cacnel is clicked!
|
||||
qFileDialog = QFileDialog()
|
||||
extensions = ("Images (*.bmp *.eps *.gif *.jpeg *.jpg *.pdf *.png " +
|
||||
"*.ps *.tiff *.xpm);;Text files (*.txt *.text);;" +
|
||||
"JSON/XML files (*.json *.xml)")
|
||||
|
||||
flocal = qFileDialog.getOpenFileNames(
|
||||
self, 'Open File', self.destination, extensions)[0]
|
||||
|
||||
if not flocal:
|
||||
return
|
||||
self.files.append(flocal[0])
|
||||
if self.fflag:
|
||||
self.files_text += '\n'
|
||||
self.files_text += str(flocal[0].split('/')[-1])
|
||||
self.fflag = True
|
||||
self.filesE.setText(self.files_text)
|
||||
|
||||
|
||||
def receive_elog_notification(self, is_accepted, logbook_url, elog_message):
|
||||
'''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)
|
||||
|
||||
if is_accepted:
|
||||
self.parent.show_log_message(MsgSeverity.INFO, self.pymodule,
|
||||
_line(), mess)
|
||||
else:
|
||||
mess += ".\n" + elog_message
|
||||
self.parent.show_log_message(MsgSeverity.WARN, self.pymodule,
|
||||
_line(), mess)
|
||||
self.parent.statusbar.showMessage(mess)
|
||||
203
sendelogsls.py
Normal file
203
sendelogsls.py
Normal file
@@ -0,0 +1,203 @@
|
||||
import getpass
|
||||
import inspect
|
||||
import os
|
||||
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(".")
|
||||
|
||||
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, projektIdx=0, eintragIdx=0,
|
||||
systemIdx=0, effektIdx=0, title=None, message=None,
|
||||
attachFile=None, destination_folder=None):
|
||||
|
||||
#super(QSendToELOGFrame, self).__init__(
|
||||
# parent, logbook=logbook, title=title, message=message,
|
||||
# attachFile=attachFile,
|
||||
# destination_folder=destination_folder)
|
||||
|
||||
super().__init__(parent, logbook=logbook, title=title)
|
||||
|
||||
#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
|
||||
|
||||
layout_items.extend(layout_items_optional)
|
||||
|
||||
print("LAYOUIT ITEMS: ", layout_items)
|
||||
|
||||
#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)
|
||||
|
||||
#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.exec()
|
||||
|
||||
#have to remove widgets within layout too!
|
||||
#https://riverbankcomputing.com/pipermail/pyqt/2009-November/025214.html
|
||||
def on_elog_change(self, elog_change_val):
|
||||
|
||||
sim_list = ["Sand"]
|
||||
if any(substring.upper() in self.elog_items.currentText().upper() for substring in 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)
|
||||
|
||||
|
||||
def ok(self):
|
||||
|
||||
#proj = self.projekt_items.currentText()
|
||||
#if not proj:
|
||||
# self.messagelbl.setText('Projekt attribute is required')
|
||||
# return
|
||||
#self.attributes['Projekt'] = proj
|
||||
el = self.elog_items.currentText()
|
||||
|
||||
if el == 'SLS':
|
||||
self.attributes['Eintrag'] = self.eintrag_items.currentText()
|
||||
self.attributes['Effekt'] = self.effekt.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()
|
||||
self.files = []
|
||||
self.files_text = ''
|
||||
self.fflag = False
|
||||
|
||||
def openFiles(self):
|
||||
# Notethat openFiles also gets called when qDialog cacnel is clicked!
|
||||
qFileDialog = QFileDialog()
|
||||
extensions = ("Images (*.bmp *.eps *.gif *.jpeg *.jpg *.pdf *.png " +
|
||||
"*.ps *.tiff *.xpm);;Text files (*.txt *.text);;" +
|
||||
"JSON/XML files (*.json *.xml)")
|
||||
|
||||
flocal = qFileDialog.getOpenFileNames(
|
||||
self, 'Open File', self.destination, extensions)[0]
|
||||
|
||||
if not flocal:
|
||||
return
|
||||
self.files.append(flocal[0])
|
||||
if self.fflag:
|
||||
self.files_text += '\n'
|
||||
self.files_text += str(flocal[0].split('/')[-1])
|
||||
self.fflag = True
|
||||
self.filesE.setText(self.files_text)
|
||||
|
||||
|
||||
def receive_elog_notification(self, is_accepted, logbook_url, elog_message):
|
||||
'''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)
|
||||
|
||||
if is_accepted:
|
||||
self.parent.show_log_message(MsgSeverity.INFO, self.pymodule,
|
||||
_line(), mess)
|
||||
else:
|
||||
mess += ".\n" + elog_message
|
||||
self.parent.show_log_message(MsgSeverity.WARN, self.pymodule,
|
||||
_line(), mess)
|
||||
self.parent.statusbar.showMessage(mess)
|
||||
Reference in New Issue
Block a user