From 4ed46e7109a2e1f57aacf9387af9b4a84634edc2 Mon Sep 17 00:00:00 2001 From: JackEAllen Date: Thu, 28 Nov 2024 19:19:36 +0000 Subject: [PATCH] Refactor Implementation of experimentSetupFormWidget Refactor implementation of experimentSetupFormWidget in the view and presenter to update method names, behaviour and handle value changed signal within one method --- .../gui/windows/spectrum_viewer/presenter.py | 14 +++++-------- .../gui/windows/spectrum_viewer/view.py | 21 +++++++------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/mantidimaging/gui/windows/spectrum_viewer/presenter.py b/mantidimaging/gui/windows/spectrum_viewer/presenter.py index cdee740def6..065f3f950b1 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/presenter.py +++ b/mantidimaging/gui/windows/spectrum_viewer/presenter.py @@ -129,13 +129,13 @@ def handle_sample_change(self, uuid: UUID | None) -> None: def reset_units_menu(self) -> None: if self.model.tof_data is None: self.view.tof_mode_select_group.setEnabled(False) - self.view.tofPropertiesGroupBox.setEnabled(False) + self.view.experimentSetupGroupBox.setEnabled(False) self.model.tof_mode = ToFUnitMode.IMAGE_NUMBER self.change_selected_menu_option("Image Index") self.view.tof_mode_select_group.setEnabled(False) else: self.view.tof_mode_select_group.setEnabled(True) - self.view.tofPropertiesGroupBox.setEnabled(True) + self.view.experimentSetupGroupBox.setEnabled(True) def handle_normalise_stack_change(self, normalise_uuid: UUID | None) -> None: if normalise_uuid == self.current_norm_stack_uuid: @@ -417,13 +417,9 @@ def refresh_spectrum_plot(self) -> None: self.view.spectrum_widget.spectrum_plot_widget.set_image_index_range_label(*self.model.tof_range) self.view.auto_range_image() - def handle_flight_path_change(self) -> None: - self.model.units.target_to_camera_dist = self.view.flightPathSpinBox.value() - self.model.set_relevant_tof_units() - self.refresh_spectrum_plot() - - def handle_time_delay_change(self) -> None: - self.model.units.data_offset = self.view.timeDelaySpinBox.value() * 1e-6 + def handle_experiment_setup_properties_change(self) -> None: + self.model.units.target_to_camera_dist = self.view.experimentSetupFormWidget.flight_path + self.model.units.data_offset = self.view.experimentSetupFormWidget.time_delay * 1e-6 self.model.set_relevant_tof_units() self.refresh_spectrum_plot() diff --git a/mantidimaging/gui/windows/spectrum_viewer/view.py b/mantidimaging/gui/windows/spectrum_viewer/view.py index 7f364383d50..25a2e85e38c 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/view.py +++ b/mantidimaging/gui/windows/spectrum_viewer/view.py @@ -7,7 +7,7 @@ from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import QCheckBox, QVBoxLayout, QFileDialog, QPushButton, QLabel, QAbstractItemView, QHeaderView, \ - QTabWidget, QComboBox, QSpinBox, QTableWidget, QTableWidgetItem, QGroupBox, QActionGroup, QAction, QDoubleSpinBox + QTabWidget, QComboBox, QSpinBox, QTableWidget, QTableWidgetItem, QGroupBox, QActionGroup, QAction from PyQt5.QtCore import QSignalBlocker, Qt, QModelIndex from mantidimaging.core.utility import finder @@ -18,7 +18,7 @@ from mantidimaging.gui.widgets import RemovableRowTableView from .spectrum_widget import SpectrumWidget from mantidimaging.gui.windows.spectrum_viewer.roi_table_model import TableModel - +from mantidimaging.gui.widgets.spectrum_widgets.tof_properties import ExperimentSetupFormWidget import numpy as np if TYPE_CHECKING: @@ -55,9 +55,8 @@ class SpectrumViewerWindowView(BaseMainWindowView): number_roi_properties_procced: int = 0 - tofPropertiesGroupBox: QGroupBox - flightPathSpinBox: QDoubleSpinBox - timeDelaySpinBox: QDoubleSpinBox + experimentSetupGroupBox: QGroupBox + experimentSetupFormWidget: ExperimentSetupFormWidget def __init__(self, main_window: MainWindowView): super().__init__(None, 'gui/ui/spectrum_viewer.ui') @@ -174,15 +173,9 @@ def __init__(self, main_window: MainWindowView): self.current_roi_name = self.last_clicked_roi = self.roi_table_model.roi_names()[0] self.set_roi_properties() - self.flightPathSpinBox.setMinimum(0) - self.flightPathSpinBox.setMaximum(1e10) - self.flightPathSpinBox.setValue(56.4) - self.flightPathSpinBox.setSuffix(" m") - self.timeDelaySpinBox.setMaximum(1e10) - self.timeDelaySpinBox.setSuffix(" \u03BCs") - - self.flightPathSpinBox.valueChanged.connect(self.presenter.handle_flight_path_change) - self.timeDelaySpinBox.valueChanged.connect(self.presenter.handle_time_delay_change) + self.experimentSetupFormWidget = ExperimentSetupFormWidget(self.experimentSetupGroupBox) + self.experimentSetupFormWidget.flight_path = 56.4 + self.experimentSetupFormWidget.connect_value_changed(self.presenter.handle_experiment_setup_properties_change) def on_row_change(item: QModelIndex, _: Any) -> None: """