Add config checker
This commit is contained in:
@@ -16,6 +16,11 @@ from qtpy.QtWidgets import (
|
||||
QHBoxLayout,
|
||||
QApplication,
|
||||
QLayout,
|
||||
QMessageBox,
|
||||
QLabel,
|
||||
QDialog,
|
||||
QPushButton,
|
||||
QStyle,
|
||||
)
|
||||
# pylint: disable=E0611
|
||||
from qtpy.QtCore import (
|
||||
@@ -76,6 +81,9 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
super().__init__(parent=parent, theme_update=True, *arg, **kwargs)
|
||||
self.get_bec_shortcuts()
|
||||
|
||||
# Check if devices are all in config
|
||||
self.check_config()
|
||||
|
||||
central = QWidget()
|
||||
self.root_layout = QHBoxLayout(central)
|
||||
|
||||
@@ -142,6 +150,84 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
self.surface_plots.apply_theme(theme)
|
||||
self.mover.apply_theme(theme)
|
||||
|
||||
def check_config(self):
|
||||
devices = [
|
||||
'abs',
|
||||
'sldi_gapx',
|
||||
'sldi_gapy',
|
||||
'cm_trx',
|
||||
'cm_try',
|
||||
'cm_bnd_radius',
|
||||
'cm_rotx',
|
||||
'mo1_bragg',
|
||||
'mo1_trx',
|
||||
'mo1_try',
|
||||
'sl1_centery',
|
||||
'sl1_gapy',
|
||||
'bm1_try',
|
||||
'fm_trx',
|
||||
'fm_try',
|
||||
'fm_bnd_radius',
|
||||
'fm_rotx',
|
||||
'fm_roty',
|
||||
'fm_rotz',
|
||||
'sl2_centery',
|
||||
'sl2_gapy',
|
||||
'bm2_try',
|
||||
'ot_try',
|
||||
'ot_rotx',
|
||||
'es0wi_try',
|
||||
'ot_es1_trz',
|
||||
]
|
||||
while True:
|
||||
missing = [d for d in devices if d not in self.dev]
|
||||
if not missing:
|
||||
break
|
||||
dialog = QDialog()
|
||||
dialog.setWindowTitle("Digital Twin - Config Check")
|
||||
dialog.setFixedWidth(400)
|
||||
layout = QVBoxLayout()
|
||||
|
||||
top = QHBoxLayout()
|
||||
icon = QLabel()
|
||||
icon_pixmap = QApplication.style().standardIcon(
|
||||
QStyle.SP_MessageBoxWarning
|
||||
).pixmap(48, 48)
|
||||
icon.setPixmap(icon_pixmap)
|
||||
icon.setAlignment(Qt.AlignTop)
|
||||
top.addWidget(icon)
|
||||
|
||||
text = QLabel(
|
||||
"The current config does not include all required devices to run Digital Twin." +
|
||||
"Reload the config with the correct devices."
|
||||
)
|
||||
text.setWordWrap(True)
|
||||
text.setAlignment(Qt.AlignTop)
|
||||
top.addWidget(text, stretch=1)
|
||||
layout.addLayout(top)
|
||||
|
||||
info = QLabel("Missing devices:\n" + ", ".join(missing))
|
||||
info.setWordWrap(True)
|
||||
info.setAlignment(Qt.AlignTop)
|
||||
layout.addWidget(info)
|
||||
layout.addStretch()
|
||||
|
||||
buttons = QHBoxLayout()
|
||||
check_again = QPushButton("Check Again")
|
||||
close_app = QPushButton("Close Application")
|
||||
check_again.clicked.connect(dialog.accept)
|
||||
close_app.clicked.connect(dialog.reject)
|
||||
buttons.addWidget(check_again)
|
||||
buttons.addWidget(close_app)
|
||||
layout.addLayout(buttons)
|
||||
|
||||
dialog.setLayout(layout)
|
||||
dialog.show()
|
||||
info.setMinimumHeight(info.heightForWidth(info.width()))
|
||||
if dialog.exec_() == QDialog.Rejected:
|
||||
QApplication.instance().exit(0)
|
||||
sys.exit(0)
|
||||
|
||||
@SafeSlot()
|
||||
def calc_assistant(self, *args, **kwargs):
|
||||
identifier = kwargs['identifier']
|
||||
@@ -226,6 +312,8 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
return config
|
||||
|
||||
def get_reality_config(self):
|
||||
# Assure all devices are in the config
|
||||
self.check_config()
|
||||
mo1_trx = self.dev.mo1_trx.read(cached=True)['mo1_trx']['value']
|
||||
if abs(mo1_trx) > 5:
|
||||
mo1_mode = 'Monochromatic'
|
||||
|
||||
Reference in New Issue
Block a user