Skip to content

Commit

Permalink
Create Custom ExperimentSetupFormWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
JackEAllen committed Dec 4, 2024
1 parent 0096395 commit d97bdb6
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions mantidimaging/gui/widgets/spectrum_widgets/tof_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later

from PyQt5 import QtCore, QtWidgets


class ExperimentSetupFormWidget(QtWidgets.QGroupBox):
"""
A custom Qt widget for setting up experiment properties related to Time of Flight (ToF).
This widget contains input fields for flight path and time delay.
Attributes:
timeDelayLabel: Label for the time delay input field.
flightPathSpinBox: Spin box for inputting the flight path value.
flightPathLabel: Label for the flight path input field.
timeDelaySpinBox: Spin box for inputting the time delay value.
"""

def __init__(self, parent: QtWidgets.QWidget = None):
super().__init__(parent)
self.setupUi()

def setupUi(self):
self.setObjectName("experimentSetupGroupBox")

self.flightPathLabel = QtWidgets.QLabel(self)
self.flightPathLabel.setGeometry(QtCore.QRect(3, 30, 78, 26))
self.flightPathLabel.setObjectName("flightPathLabel")
self.flightPathLabel.setText("Flight path:")

self.flightPathSpinBox = QtWidgets.QDoubleSpinBox(self)
self.flightPathSpinBox.setGeometry(QtCore.QRect(90, 30, 191, 26))
self.flightPathSpinBox.setSuffix(" m")
self.flightPathSpinBox.setMinimum(0)
self.flightPathSpinBox.setMaximum(1e10)
self.flightPathSpinBox.setObjectName("flightPathSpinBox")

self.timeDelayLabel = QtWidgets.QLabel(self)
self.timeDelayLabel.setGeometry(QtCore.QRect(3, 62, 81, 26))
self.timeDelayLabel.setObjectName("timeDelayLabel")
self.timeDelayLabel.setText("Time delay: ")

self.timeDelaySpinBox = QtWidgets.QDoubleSpinBox(self)
self.timeDelaySpinBox.setGeometry(QtCore.QRect(90, 62, 191, 26))
self.timeDelaySpinBox.setSuffix(" \u03BCs")
self.timeDelaySpinBox.setMaximum(1e10)
self.timeDelaySpinBox.setObjectName("timeDelaySpinBox")

self.setWindowTitle("Time of Flight Properties")
self.setTitle("Time of Flight Properties")

QtCore.QMetaObject.connectSlotsByName(self)

sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())

target = self.parent() if self.parent() else self
target.setSizePolicy(sizePolicy)
target.setMinimumSize(QtCore.QSize(300, 84))
target.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)

@property
def flight_path(self) -> float:
return self.flightPathSpinBox.value()

@flight_path.setter
def flight_path(self, value: float):
self.flightPathSpinBox.setValue(value)

@property
def time_delay(self) -> float:
return self.timeDelaySpinBox.value()

@time_delay.setter
def time_delay(self, value: float):
self.timeDelaySpinBox.setValue(value)

def connect_value_changed(self, handler: QtCore.pyqtSlot):
self.flightPathSpinBox.valueChanged.connect(handler)
self.timeDelaySpinBox.valueChanged.connect(handler)

0 comments on commit d97bdb6

Please sign in to comment.