wip: digital twin
This commit is contained in:
@@ -3,7 +3,7 @@ import numpy as np
|
||||
from bec_lib import bec_logger
|
||||
|
||||
os.environ["USE_XRT"] = "False"
|
||||
import debye_bec.bec_ipython_client.plugins.digital_twin.x01da_parameters as bl
|
||||
import debye_bec.bec_widgets.widgets.digital_twin.x01da_parameters as bl
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ import pyqtgraph as pg
|
||||
from bec_widgets.utils.bec_widget import BECWidget
|
||||
from bec_widgets.utils.error_popups import SafeSlot
|
||||
|
||||
from debye_bec.bec_widgets.widgets.qt_widgets import InputNumberField, ComboBox, Group
|
||||
from debye_bec.bec_widgets.widgets.qt_widgets import InputNumberField, ComboBox, Group, NumberIndicator
|
||||
|
||||
from debye_bec.bec_widgets.widgets.digital_twin.calculate_positions import calculate_positions
|
||||
|
||||
logger = bec_logger.logger
|
||||
|
||||
@@ -42,15 +44,63 @@ class DigitalTwin(BECWidget, QWidget):
|
||||
self.root_layout = QHBoxLayout(central)
|
||||
|
||||
self.plot_widget = PlotWidget(title='Plot title', chart_data = [])
|
||||
self.control_panel = InputPanel()
|
||||
self.input = InputPanel()
|
||||
self.positions_panel = PositionsPanel()
|
||||
|
||||
self.root_layout.addWidget(self.plot_widget, stretch=3)
|
||||
self.root_layout.addWidget(self.control_panel, stretch=1, alignment=Qt.AlignTop)
|
||||
self.root_layout.addWidget(self.input, stretch=1, alignment=Qt.AlignTop)
|
||||
self.root_layout.addWidget(self.positions_panel, stretch=1, alignment=Qt.AlignTop)
|
||||
|
||||
self.setLayout(self.root_layout)
|
||||
self.setWindowTitle("Digital Twin")
|
||||
self.resize(600, 500)
|
||||
|
||||
self.input.energy.value_changed_connect(self.calculate_positions)
|
||||
self.input.sldi_hacc.value_changed_connect(self.calculate_positions)
|
||||
self.input.sldi_vacc.value_changed_connect(self.calculate_positions)
|
||||
self.input.cm_stripe.activated_connect(self.calculate_positions)
|
||||
self.input.cm_pitch.value_changed_connect(self.calculate_positions)
|
||||
self.input.mo1_mode.activated_connect(self.calculate_positions)
|
||||
self.input.mo1_xtal.activated_connect(self.calculate_positions)
|
||||
self.input.fm_stripe.activated_connect(self.calculate_positions)
|
||||
self.input.fm_pitch.value_changed_connect(self.calculate_positions)
|
||||
self.input.smpl.value_changed_connect(self.calculate_positions)
|
||||
|
||||
self.input.mo1_mode.activated_connect(self.update_mono_mode)
|
||||
|
||||
@SafeSlot()
|
||||
def calculate_positions(self, field, qt_obj, number, *args):
|
||||
logger.info(f'Got field {field} and number {qt_obj} and number {number} and args {args}')
|
||||
|
||||
config = { # Config in SI units!
|
||||
'energy' : self.input.energy.value(),
|
||||
'h_acc' : self.input.sldi_hacc.value() * 1e-3,
|
||||
'v_acc' : self.input.sldi_vacc.value() * 1e-3,
|
||||
'cm_pitch' : -self.input.cm_pitch.value() * 1e-3,
|
||||
'cm_stripe' : self.input.cm_stripe.currentText(),
|
||||
'mo_mode' : self.input.mo1_mode.currentText(),
|
||||
'mo_xtal' : self.input.mo1_xtal.currentText(),
|
||||
'mo_bragg' : [12.725, 12.725],
|
||||
'fm_pitch' : -self.input.fm_pitch.value() * 1e-3,
|
||||
'fm_stripe' : self.input.fm_stripe.currentText(),
|
||||
'fm_gain_height' : 1,
|
||||
'smpl' : self.input.smpl.value(),
|
||||
}
|
||||
|
||||
logger.info(f'Config created: {config}')
|
||||
|
||||
positions = calculate_positions(config)
|
||||
|
||||
logger.info(f'Got positions: {positions}')
|
||||
|
||||
@SafeSlot()
|
||||
def update_mono_mode(self, *args):
|
||||
logger.info(f'Got args {args}')
|
||||
if self.input.mo1_mode.currentText() in 'Monochromatic':
|
||||
self.input.mo1_xtal.setDisabled(False)
|
||||
else:
|
||||
self.input.mo1_xtal.setDisabled(True)
|
||||
|
||||
# self.init_ui()
|
||||
# self._recalculate() # populate outputs on startup
|
||||
|
||||
@@ -195,11 +245,13 @@ class InputPanel(QWidget):
|
||||
self._layout = QVBoxLayout(self)
|
||||
self._layout.setSizeConstraint(QLayout.SetFixedSize)
|
||||
|
||||
self.energy = InputNumberField('Energy [keV]')
|
||||
# Energy
|
||||
self.energy = InputNumberField('Energy [keV]', init=8979, decimals=0, single_step=100, ll=4000, hl=65000)
|
||||
|
||||
self.sldi_hacc = InputNumberField('Horizontal [± mrad]')
|
||||
self.sldi_vacc = InputNumberField('Vertical [± mrad]')
|
||||
self.fe_slits_group = Group(
|
||||
# FE Slits Acceptance
|
||||
self.sldi_hacc = InputNumberField('Horizontal [± mrad]', init=0.25, decimals=2, single_step=0.01, ll=-0.1, hl=0.9)
|
||||
self.sldi_vacc = InputNumberField('Vertical [± mrad]', init=0.1, decimals=2, single_step=0.01, ll=-0.1, hl=0.5)
|
||||
self.sldi_ass_group = Group(
|
||||
'FE Slits Acceptance',
|
||||
[
|
||||
self.sldi_hacc,
|
||||
@@ -207,15 +259,190 @@ class InputPanel(QWidget):
|
||||
]
|
||||
)
|
||||
|
||||
self.assistant_group = Group(
|
||||
'Assistant',
|
||||
# Collimating mirror
|
||||
self.cm_stripe = ComboBox('Stripe', ['Si', 'Rh', 'Pt'])
|
||||
self.cm_pitch_critical = NumberIndicator('Critical Pitch', 'mrad', decimals=3)
|
||||
self.cm_pitch = InputNumberField('Pitch [mrad]', init=-3, decimals=3, single_step=0.01, ll=-4.6, hl=-1.2)
|
||||
self.cm_ass_group = Group(
|
||||
'Collimating Mirror',
|
||||
[
|
||||
self.energy,
|
||||
self.fe_slits_group,
|
||||
self.cm_stripe,
|
||||
self.cm_pitch_critical,
|
||||
self.cm_pitch,
|
||||
]
|
||||
)
|
||||
|
||||
self._layout .addWidget(self.assistant_group)
|
||||
# Monochromator
|
||||
self.mo1_mode = ComboBox('Mode', ['Monochromatic', 'Pinkbeam'])
|
||||
self.mo1_xtal = ComboBox('Crystal', ['Si(111)', 'Si(311)'])
|
||||
self.mo1_ass_group = Group(
|
||||
'Monochromator',
|
||||
[
|
||||
self.mo1_mode,
|
||||
self.mo1_xtal,
|
||||
]
|
||||
)
|
||||
|
||||
# Focusing Mirror
|
||||
self.fm_stripe = ComboBox('Stripe', ['Rh (toroid)', 'Rh (flat)', 'Pt (toroid)', 'Pt (flat)'])
|
||||
self.fm_pitch_ideal = NumberIndicator('Ideal Pitch', 'mrad', decimals=3)
|
||||
self.fm_pitch = InputNumberField('Pitch [mrad]', init=-3, decimals=3, single_step=0.01, ll=-10, hl=2)
|
||||
self.fm_ass_group = Group(
|
||||
'Focusing Mirror',
|
||||
[
|
||||
self.fm_stripe,
|
||||
self.fm_pitch_ideal,
|
||||
self.fm_pitch,
|
||||
]
|
||||
)
|
||||
|
||||
# Sample
|
||||
self.smpl = InputNumberField('Sample Position [mm]')
|
||||
|
||||
# Assemble complete assitant group
|
||||
self.input_group = Group(
|
||||
'User Input',
|
||||
[
|
||||
self.energy,
|
||||
self.sldi_ass_group,
|
||||
self.cm_ass_group,
|
||||
self.mo1_ass_group,
|
||||
self.fm_ass_group,
|
||||
self.smpl,
|
||||
]
|
||||
)
|
||||
|
||||
self._layout .addWidget(self.input_group)
|
||||
self._layout .addStretch()
|
||||
|
||||
class PositionsPanel(QWidget):
|
||||
"""Right-side control panel: input field, indicator, send, recording."""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self._layout = QVBoxLayout(self)
|
||||
self._layout.setSizeConstraint(QLayout.SetFixedSize)
|
||||
|
||||
# FE Slits
|
||||
self.sldi_gapx = NumberIndicator('GAPX', 'mm', decimals=3)
|
||||
self.sldi_gapy = NumberIndicator('GAPY', 'mm', decimals=3)
|
||||
self.sldi_pos_group = Group(
|
||||
'FE Slits',
|
||||
[
|
||||
self.sldi_gapx,
|
||||
self.sldi_gapy,
|
||||
]
|
||||
)
|
||||
|
||||
# Collimating mirror
|
||||
self.cm_trx = NumberIndicator('TRX', 'mm', decimals=1)
|
||||
self.cm_try = NumberIndicator('TRY', 'mm', decimals=3)
|
||||
self.cm_bnd = NumberIndicator('BENDER', 'mm', decimals=2)
|
||||
self.cm_rotx = NumberIndicator('PITCH', 'mm', decimals=3)
|
||||
self.cm_pos_group = Group(
|
||||
'Collimating Mirror',
|
||||
[
|
||||
self.cm_trx,
|
||||
self.cm_try,
|
||||
self.cm_bnd,
|
||||
self.cm_rotx,
|
||||
]
|
||||
)
|
||||
|
||||
# Monochromator
|
||||
self.mo1_bragg_angle = NumberIndicator('Bragg Angle', 'mm', decimals=3)
|
||||
self.mo1_trx = NumberIndicator('TRX', 'mm', decimals=1)
|
||||
self.mo1_try = NumberIndicator('TRY', 'mm', decimals=3)
|
||||
self.mo1_pos_group = Group(
|
||||
'Monochromator',
|
||||
[
|
||||
self.mo1_bragg_angle,
|
||||
self.mo1_trx,
|
||||
self.mo1_try,
|
||||
]
|
||||
)
|
||||
|
||||
# OP Slits 1
|
||||
self.sl1_centery = NumberIndicator('CENTERY', 'mm', decimals=1)
|
||||
self.sl1_pos_group = Group(
|
||||
'OP Slits 1',
|
||||
[
|
||||
self.sl1_centery,
|
||||
]
|
||||
)
|
||||
|
||||
# OP Beam Monitor 1
|
||||
self.bm1_try = NumberIndicator('TRY', 'mm', decimals=1)
|
||||
self.bm1_pos_group = Group(
|
||||
'OP Beam Monitor 1',
|
||||
[
|
||||
self.bm1_try,
|
||||
]
|
||||
)
|
||||
|
||||
# Focusing Mirror
|
||||
self.fm_trx = NumberIndicator('TRX', 'mm', decimals=1)
|
||||
self.fm_try = NumberIndicator('TRY', 'mm', decimals=3)
|
||||
self.fm_bnd = NumberIndicator('BENDER', 'mm', decimals=2)
|
||||
self.fm_rotx = NumberIndicator('PITCH', 'mm', decimals=3)
|
||||
self.fm_pos_group = Group(
|
||||
'Focusing Mirror',
|
||||
[
|
||||
self.fm_trx,
|
||||
self.fm_try,
|
||||
self.fm_bnd,
|
||||
self.fm_rotx,
|
||||
]
|
||||
)
|
||||
|
||||
# OP Slits 2
|
||||
self.sl2_centery = NumberIndicator('CENTERY', 'mm', decimals=1)
|
||||
self.sl2_pos_group = Group(
|
||||
'OP Slits 2',
|
||||
[
|
||||
self.sl2_centery,
|
||||
]
|
||||
)
|
||||
|
||||
# OP Beam Monitor 2
|
||||
self.bm2_try = NumberIndicator('TRY', 'mm', decimals=1)
|
||||
self.bm2_pos_group = Group(
|
||||
'OP Beam Monitor 2',
|
||||
[
|
||||
self.bm2_try,
|
||||
]
|
||||
)
|
||||
|
||||
# Optical Table
|
||||
self.es_try = NumberIndicator('TRY', 'mm', decimals=3)
|
||||
self.es_rotx = NumberIndicator('ROTX', 'mm', decimals=3)
|
||||
self.es1_trz = NumberIndicator('ES1 TRZ', 'mm', decimals=0)
|
||||
self.es_pos_group = Group(
|
||||
'Optical Table',
|
||||
[
|
||||
self.es_try,
|
||||
self.es_rotx,
|
||||
self.es1_trz,
|
||||
]
|
||||
)
|
||||
|
||||
# Assemble complete assitant group
|
||||
self.position_group = Group(
|
||||
'Axes Positions Calculator',
|
||||
[
|
||||
self.sldi_pos_group,
|
||||
self.cm_pos_group,
|
||||
self.mo1_pos_group,
|
||||
self.sl1_pos_group,
|
||||
self.bm1_pos_group,
|
||||
self.fm_pos_group,
|
||||
self.sl2_pos_group,
|
||||
self.bm2_pos_group,
|
||||
self.es_pos_group,
|
||||
]
|
||||
)
|
||||
|
||||
self._layout .addWidget(self.position_group)
|
||||
self._layout .addStretch()
|
||||
|
||||
class PlotWidget(QWidget):
|
||||
@@ -352,7 +579,7 @@ class TimeAxis(pg.AxisItem):
|
||||
|
||||
if __name__ == "__main__":
|
||||
from qtpy.QtWidgets import QApplication
|
||||
from bec_widgets.utils import BECDispatcher
|
||||
from bec_widgets.utils.bec_dispatcher import BECDispatcher
|
||||
from bec_widgets.utils.colors import apply_theme
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
@@ -14,8 +14,34 @@ class Group(QGroupBox):
|
||||
for widget in widgets:
|
||||
self.layout.addWidget(widget)
|
||||
|
||||
class Indicator(QWidget):
|
||||
def __init__(self, label, unit=None, highlight=False):
|
||||
# class TextIndicator(QWidget):
|
||||
# def __init__(self, label, unit=None, highlight=False):
|
||||
# super().__init__()
|
||||
# layout = QHBoxLayout(self)
|
||||
# layout.setContentsMargins(10, 0, 0, 0)
|
||||
# layout.setSpacing(0)
|
||||
# self.label = QLabel(label)
|
||||
# self.label.setFixedWidth(150)
|
||||
# layout.addWidget(self.label)
|
||||
# self.value = QLabel('-')
|
||||
# self.value.setFixedWidth(160)
|
||||
# layout.addWidget(self.value)
|
||||
# self.unit = unit
|
||||
# self.highlight = highlight
|
||||
# if highlight:
|
||||
# font = QFont()
|
||||
# font.setBold(True)
|
||||
# font.setPointSize(14)
|
||||
# self.label.setFont(font)
|
||||
# self.value.setFont(font)
|
||||
|
||||
# def set_text(self, text):
|
||||
# if self.unit is not None:
|
||||
# text = text + ' ' + self.unit
|
||||
# self.value.setText(text)
|
||||
|
||||
class NumberIndicator(QWidget):
|
||||
def __init__(self, label, unit=None, highlight=False, decimals=3):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(10, 0, 0, 0)
|
||||
@@ -23,22 +49,29 @@ class Indicator(QWidget):
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.value = QLabel('-')
|
||||
self.value.setFixedWidth(160)
|
||||
layout.addWidget(self.value)
|
||||
self.val = QLabel('-')
|
||||
self.val.setFixedWidth(160)
|
||||
layout.addWidget(self.val)
|
||||
self.unit = unit
|
||||
self.highlight = highlight
|
||||
self.decimals = decimals
|
||||
self.number = 0
|
||||
if highlight:
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
font.setPointSize(14)
|
||||
self.label.setFont(font)
|
||||
self.value.setFont(font)
|
||||
self.val.setFont(font)
|
||||
|
||||
def set_text(self, text):
|
||||
def value(self) -> float:
|
||||
return self.number
|
||||
|
||||
def setValue(self, number):
|
||||
self.number = number
|
||||
text = f'{number:.{self.decimals}f}'
|
||||
if self.unit is not None:
|
||||
text = text + ' ' + self.unit
|
||||
self.value.setText(text)
|
||||
self.val.setText(text)
|
||||
|
||||
class InputTextField(QWidget):
|
||||
def __init__(self, topic, label):
|
||||
@@ -50,21 +83,24 @@ class InputTextField(QWidget):
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.value = QLineEdit()
|
||||
self.value.setPlaceholderText('0')
|
||||
self.value.setFixedWidth(160)
|
||||
layout.addWidget(self.value)
|
||||
self.val = QLineEdit()
|
||||
self.val.setPlaceholderText('0')
|
||||
self.val.setFixedWidth(160)
|
||||
layout.addWidget(self.val)
|
||||
|
||||
def set_text(self, text):
|
||||
self.value.setText(text)
|
||||
self.val.setText(text)
|
||||
|
||||
def has_focus(self) -> bool:
|
||||
return self.value.hasFocus()
|
||||
return self.val.hasFocus()
|
||||
|
||||
def value(self) -> float:
|
||||
return self.val.val()
|
||||
|
||||
def set_on_return(self, func):
|
||||
"""Connect a function to the Enter/Return key press."""
|
||||
self.value.returnPressed.connect(
|
||||
partial(func, self.value, self.topic, lambda: self.value.text())
|
||||
self.val.returnPressed.connect(
|
||||
partial(func, self.val, self.topic, lambda: self.val.text())
|
||||
)
|
||||
|
||||
class InputNumberField(QWidget):
|
||||
@@ -76,87 +112,90 @@ class InputNumberField(QWidget):
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.value = QDoubleSpinBox()
|
||||
self.value.setValue(init)
|
||||
self.value.setRange(ll, hl)
|
||||
self.value.setDecimals(decimals)
|
||||
self.value.setSingleStep(single_step)
|
||||
self.value.setFixedWidth(160)
|
||||
layout.addWidget(self.value)
|
||||
self.val = QDoubleSpinBox()
|
||||
self.val.setValue(init)
|
||||
self.val.setRange(ll, hl)
|
||||
self.val.setDecimals(decimals)
|
||||
self.val.setSingleStep(single_step)
|
||||
self.val.setFixedWidth(160)
|
||||
layout.addWidget(self.val)
|
||||
|
||||
def set_number(self, number):
|
||||
self.value.setValue(number)
|
||||
self.val.setValue(number)
|
||||
|
||||
def has_focus(self) -> bool:
|
||||
return self.value.hasFocus()
|
||||
return self.val.hasFocus()
|
||||
|
||||
def value(self) -> float:
|
||||
return self.val.value()
|
||||
|
||||
def set_on_return(self, func):
|
||||
def value_changed_connect(self, func):
|
||||
"""Connect a function to the Enter/Return key press."""
|
||||
self.value.editingFinished.connect(
|
||||
partial(func, self.value, lambda: self.value.text())
|
||||
self.val.valueChanged.connect(
|
||||
partial(func, self.val, lambda: self.val.value())
|
||||
)
|
||||
|
||||
class IPAdressInputField(QWidget):
|
||||
def __init__(self, topic, label):
|
||||
super().__init__()
|
||||
self.topic = topic
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(10, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.oct0 = QLineEdit()
|
||||
self.oct0.setPlaceholderText('0')
|
||||
self.oct0.setFixedWidth(30)
|
||||
layout.addWidget(self.oct0)
|
||||
separator1 = QLabel('.')
|
||||
layout.addWidget(separator1)
|
||||
self.oct1 = QLineEdit()
|
||||
self.oct1.setPlaceholderText('0')
|
||||
self.oct1.setFixedWidth(30)
|
||||
layout.addWidget(self.oct1)
|
||||
separator2 = QLabel('.')
|
||||
layout.addWidget(separator2)
|
||||
self.oct2 = QLineEdit()
|
||||
self.oct2.setPlaceholderText('0')
|
||||
self.oct2.setFixedWidth(30)
|
||||
layout.addWidget(self.oct2)
|
||||
separator3 = QLabel('.')
|
||||
layout.addWidget(separator3)
|
||||
self.oct3 = QLineEdit()
|
||||
self.oct3.setPlaceholderText('0')
|
||||
self.oct3.setFixedWidth(30)
|
||||
layout.addWidget(self.oct3)
|
||||
# class IPAdressInputField(QWidget):
|
||||
# def __init__(self, topic, label):
|
||||
# super().__init__()
|
||||
# self.topic = topic
|
||||
# layout = QHBoxLayout(self)
|
||||
# layout.setContentsMargins(10, 0, 0, 0)
|
||||
# layout.setSpacing(0)
|
||||
# self.label = QLabel(label)
|
||||
# self.label.setFixedWidth(150)
|
||||
# layout.addWidget(self.label)
|
||||
# self.oct0 = QLineEdit()
|
||||
# self.oct0.setPlaceholderText('0')
|
||||
# self.oct0.setFixedWidth(30)
|
||||
# layout.addWidget(self.oct0)
|
||||
# separator1 = QLabel('.')
|
||||
# layout.addWidget(separator1)
|
||||
# self.oct1 = QLineEdit()
|
||||
# self.oct1.setPlaceholderText('0')
|
||||
# self.oct1.setFixedWidth(30)
|
||||
# layout.addWidget(self.oct1)
|
||||
# separator2 = QLabel('.')
|
||||
# layout.addWidget(separator2)
|
||||
# self.oct2 = QLineEdit()
|
||||
# self.oct2.setPlaceholderText('0')
|
||||
# self.oct2.setFixedWidth(30)
|
||||
# layout.addWidget(self.oct2)
|
||||
# separator3 = QLabel('.')
|
||||
# layout.addWidget(separator3)
|
||||
# self.oct3 = QLineEdit()
|
||||
# self.oct3.setPlaceholderText('0')
|
||||
# self.oct3.setFixedWidth(30)
|
||||
# layout.addWidget(self.oct3)
|
||||
|
||||
self.oct0.editingFinished.connect(partial(self.check_octet, self.oct0))
|
||||
self.oct1.editingFinished.connect(partial(self.check_octet, self.oct1))
|
||||
self.oct2.editingFinished.connect(partial(self.check_octet, self.oct2))
|
||||
self.oct3.editingFinished.connect(partial(self.check_octet, self.oct3))
|
||||
# self.oct0.editingFinished.connect(partial(self.check_octet, self.oct0))
|
||||
# self.oct1.editingFinished.connect(partial(self.check_octet, self.oct1))
|
||||
# self.oct2.editingFinished.connect(partial(self.check_octet, self.oct2))
|
||||
# self.oct3.editingFinished.connect(partial(self.check_octet, self.oct3))
|
||||
|
||||
def check_octet(self, octet):
|
||||
if octet.text().isnumeric():
|
||||
if int(octet.text()) < 0:
|
||||
octet.setText('0')
|
||||
if int(octet.text()) > 254:
|
||||
octet.setText('254')
|
||||
else:
|
||||
octet.setText('')
|
||||
# def check_octet(self, octet):
|
||||
# if octet.text().isnumeric():
|
||||
# if int(octet.text()) < 0:
|
||||
# octet.setText('0')
|
||||
# if int(octet.text()) > 254:
|
||||
# octet.setText('254')
|
||||
# else:
|
||||
# octet.setText('')
|
||||
|
||||
def get_ip(self):
|
||||
return f'{self.oct0.text()}.{self.oct1.text()}.{self.oct2.text()}.{self.oct3.text()}'
|
||||
# def get_ip(self):
|
||||
# return f'{self.oct0.text()}.{self.oct1.text()}.{self.oct2.text()}.{self.oct3.text()}'
|
||||
|
||||
def set_ip(self, ip):
|
||||
octets = ip.split('.')
|
||||
if len(octets) == 4 and all(octet.isnumeric() for octet in octets):
|
||||
if all(int(octet) > 0 and int(octet) < 254 for octet in octets):
|
||||
self.oct0.setText(octets[0])
|
||||
self.oct1.setText(octets[1])
|
||||
self.oct2.setText(octets[2])
|
||||
self.oct3.setText(octets[3])
|
||||
# def set_ip(self, ip):
|
||||
# octets = ip.split('.')
|
||||
# if len(octets) == 4 and all(octet.isnumeric() for octet in octets):
|
||||
# if all(int(octet) > 0 and int(octet) < 254 for octet in octets):
|
||||
# self.oct0.setText(octets[0])
|
||||
# self.oct1.setText(octets[1])
|
||||
# self.oct2.setText(octets[2])
|
||||
# self.oct3.setText(octets[3])
|
||||
|
||||
class ComboBox(QWidget):
|
||||
def __init__(self, enums, label):
|
||||
def __init__(self, label, enums):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(10, 0, 0, 0)
|
||||
@@ -173,101 +212,107 @@ class ComboBox(QWidget):
|
||||
def set_current_text(self, text):
|
||||
self.value.setCurrentText(text)
|
||||
|
||||
def currentText(self) -> str:
|
||||
return self.value.currentText()
|
||||
|
||||
def has_focus(self) -> bool:
|
||||
return QApplication.focusWidget() is self.value.view()
|
||||
|
||||
def set_on_change(self, func, reset_plot=False):
|
||||
def activated_connect(self, func):
|
||||
"""Connect a function to the Enter/Return key press."""
|
||||
self.value.activated.connect(
|
||||
partial(func, self.value, lambda: self.value.currentText(), reset_plot)
|
||||
partial(func, self.value, lambda: self.value.currentText())
|
||||
)
|
||||
|
||||
class LED(QWidget):
|
||||
def __init__(self, states, colors, label):
|
||||
super().__init__()
|
||||
self.states = states
|
||||
self.colors = colors
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(10, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.led = QLabel()
|
||||
self.led.setFixedWidth(160)
|
||||
layout.addWidget(self.led)
|
||||
def setDisabled(self, disable):
|
||||
self.value.setDisabled(disable)
|
||||
|
||||
def apply_color(self, val):
|
||||
color = self.colors[self.states.index(val)]
|
||||
self.led.setStyleSheet(f"background-color: {color}; border: 1px solid black;")
|
||||
# class LED(QWidget):
|
||||
# def __init__(self, states, colors, label):
|
||||
# super().__init__()
|
||||
# self.states = states
|
||||
# self.colors = colors
|
||||
# layout = QHBoxLayout(self)
|
||||
# layout.setContentsMargins(10, 0, 0, 0)
|
||||
# layout.setSpacing(0)
|
||||
# self.label = QLabel(label)
|
||||
# self.label.setFixedWidth(150)
|
||||
# layout.addWidget(self.label)
|
||||
# self.led = QLabel()
|
||||
# self.led.setFixedWidth(160)
|
||||
# layout.addWidget(self.led)
|
||||
|
||||
class StartStop(QWidget):
|
||||
def __init__(self, label, label_buttons=['Start', 'Stop']):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(10, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.start = QPushButton(label_buttons[0])
|
||||
self.start.setStyleSheet("color: black; background-color: green;")
|
||||
self.start.setFixedWidth(80)
|
||||
self.stop = QPushButton(label_buttons[1])
|
||||
self.stop.setStyleSheet("color: black; background-color: firebrick;")
|
||||
self.stop.setFixedWidth(80)
|
||||
layout.addWidget(self.start)
|
||||
layout.addWidget(self.stop)
|
||||
# def apply_color(self, val):
|
||||
# color = self.colors[self.states.index(val)]
|
||||
# self.led.setStyleSheet(f"background-color: {color}; border: 1px solid black;")
|
||||
|
||||
def set_on_start(self, func):
|
||||
"""Connect a function to the start button press."""
|
||||
self.start.clicked.connect(func)
|
||||
# class StartStop(QWidget):
|
||||
# def __init__(self, label, label_buttons=['Start', 'Stop']):
|
||||
# super().__init__()
|
||||
# layout = QHBoxLayout(self)
|
||||
# layout.setContentsMargins(10, 0, 0, 0)
|
||||
# layout.setSpacing(0)
|
||||
# self.label = QLabel(label)
|
||||
# self.label.setFixedWidth(150)
|
||||
# layout.addWidget(self.label)
|
||||
# self.start = QPushButton(label_buttons[0])
|
||||
# self.start.setStyleSheet("color: black; background-color: green;")
|
||||
# self.start.setFixedWidth(80)
|
||||
# self.stop = QPushButton(label_buttons[1])
|
||||
# self.stop.setStyleSheet("color: black; background-color: firebrick;")
|
||||
# self.stop.setFixedWidth(80)
|
||||
# layout.addWidget(self.start)
|
||||
# layout.addWidget(self.stop)
|
||||
|
||||
def set_on_stop(self, func):
|
||||
"""Connect a function to the stop button press."""
|
||||
self.stop.clicked.connect(func)
|
||||
# def set_on_start(self, func):
|
||||
# """Connect a function to the start button press."""
|
||||
# self.start.clicked.connect(func)
|
||||
|
||||
def enable_start(self):
|
||||
self.start.setEnabled(True)
|
||||
self.start.setStyleSheet("color: black; background-color: green;")
|
||||
# def set_on_stop(self, func):
|
||||
# """Connect a function to the stop button press."""
|
||||
# self.stop.clicked.connect(func)
|
||||
|
||||
def enable_stop(self):
|
||||
self.stop.setEnabled(True)
|
||||
self.stop.setStyleSheet("color: black; background-color: firebrick;")
|
||||
# def enable_start(self):
|
||||
# self.start.setEnabled(True)
|
||||
# self.start.setStyleSheet("color: black; background-color: green;")
|
||||
|
||||
def disable_start(self):
|
||||
self.start.setEnabled(False)
|
||||
self.start.setStyleSheet("color: black; background-color: grey;")
|
||||
# def enable_stop(self):
|
||||
# self.stop.setEnabled(True)
|
||||
# self.stop.setStyleSheet("color: black; background-color: firebrick;")
|
||||
|
||||
def disable_stop(self):
|
||||
self.stop.setEnabled(False)
|
||||
self.stop.setStyleSheet("color: black; background-color: grey;")
|
||||
# def disable_start(self):
|
||||
# self.start.setEnabled(False)
|
||||
# self.start.setStyleSheet("color: black; background-color: grey;")
|
||||
|
||||
class Button(QWidget):
|
||||
def __init__(self, label, label_button):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(10, 0, 0, 0)
|
||||
layout.setSpacing(0)
|
||||
self.label = QLabel(label)
|
||||
self.label.setFixedWidth(150)
|
||||
layout.addWidget(self.label)
|
||||
self.button = QPushButton(label_button)
|
||||
self.button.setStyleSheet("color: black; background-color: dodgerblue;")
|
||||
self.button.setFixedWidth(160)
|
||||
layout.addWidget(self.button)
|
||||
# def disable_stop(self):
|
||||
# self.stop.setEnabled(False)
|
||||
# self.stop.setStyleSheet("color: black; background-color: grey;")
|
||||
|
||||
def set_on_press(self, func):
|
||||
"""Connect a function to the button press."""
|
||||
self.button.clicked.connect(func)
|
||||
# class Button(QWidget):
|
||||
# def __init__(self, label, label_button):
|
||||
# super().__init__()
|
||||
# layout = QHBoxLayout(self)
|
||||
# layout.setContentsMargins(10, 0, 0, 0)
|
||||
# layout.setSpacing(0)
|
||||
# self.label = QLabel(label)
|
||||
# self.label.setFixedWidth(150)
|
||||
# layout.addWidget(self.label)
|
||||
# self.button = QPushButton(label_button)
|
||||
# self.button.setStyleSheet("color: black; background-color: dodgerblue;")
|
||||
# self.button.setFixedWidth(160)
|
||||
# layout.addWidget(self.button)
|
||||
|
||||
def enable_button(self):
|
||||
self.button.setEnabled(True)
|
||||
self.button.setStyleSheet("color: black; background-color: dodgerblue;")
|
||||
# def set_on_press(self, func):
|
||||
# """Connect a function to the button press."""
|
||||
# self.button.clicked.connect(func)
|
||||
|
||||
def disable_button(self):
|
||||
self.button.setEnabled(False)
|
||||
self.button.setStyleSheet("color: black; background-color: grey;")
|
||||
# def enable_button(self):
|
||||
# self.button.setEnabled(True)
|
||||
# self.button.setStyleSheet("color: black; background-color: dodgerblue;")
|
||||
|
||||
def set_button_text(self, text):
|
||||
self.button.setText(text)
|
||||
# def disable_button(self):
|
||||
# self.button.setEnabled(False)
|
||||
# self.button.setStyleSheet("color: black; background-color: grey;")
|
||||
|
||||
# def set_button_text(self, text):
|
||||
# self.button.setText(text)
|
||||
|
||||
Reference in New Issue
Block a user