Skip to content

Commit

Permalink
Refactor Implementation of experimentSetupFormWidget
Browse files Browse the repository at this point in the history
Refactor implementation of experimentSetupFormWidget in the view and presenter to update method names, behaviour and handle value changed signal within one method
  • Loading branch information
JackEAllen committed Dec 4, 2024
1 parent d97bdb6 commit 4ed46e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
14 changes: 5 additions & 9 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
21 changes: 7 additions & 14 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit 4ed46e7

Please sign in to comment.