Skip to content

Commit

Permalink
Fix adjusting ROI from spin boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc committed Feb 13, 2025
1 parent 24566af commit d72767a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 2 additions & 7 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from mantidimaging.gui.windows.spectrum_viewer.spectrum_widget import SpectrumROI
from mantidimaging.core.data import ImageStack
from uuid import UUID
from PyQt5.QtWidgets import QAction, QSpinBox
from PyQt5.QtWidgets import QAction

LOG = getLogger(__name__)

Expand Down Expand Up @@ -438,7 +438,7 @@ def change_selected_menu_option(self, opt: str) -> None:
self.check_action(action, False)

def do_adjust_roi(self) -> None:
new_roi = self.convert_spinbox_roi_to_SensibleROI(self.view.roiPropertiesSpinBoxes)
new_roi = self.view.roi_properties_widget.as_roi()
self.view.spectrum_widget.adjust_roi(new_roi, self.view.current_roi_name)

def handle_storing_current_roi_name_on_tab_change(self) -> None:
Expand All @@ -458,8 +458,3 @@ def handle_storing_current_roi_name_on_tab_change(self) -> None:
@staticmethod
def check_action(action: QAction, param: bool) -> None:
action.setChecked(param)

def convert_spinbox_roi_to_SensibleROI(self, spinboxes: dict[str, QSpinBox]) -> SensibleROI:
roi_iter_order = ["Left", "Top", "Right", "Bottom"]
new_points = [spinboxes[prop].value() for prop in roi_iter_order]
return SensibleROI.from_list(new_points)
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ def test_WHEN_menu_option_selected_THEN_menu_option_changed(self):
self.presenter.check_action.assert_has_calls(calls)

def test_WHEN_roi_changed_via_spinboxes_THEN_roi_adjusted(self):
self.presenter.view.roiPropertiesSpinBoxes = mock.Mock()
self.presenter.convert_spinbox_roi_to_SensibleROI = mock.Mock(return_value=SensibleROI(10, 10, 20, 30))
self.view.roi_properties_widget.as_roi = mock.Mock(return_value=SensibleROI(10, 10, 20, 30))
self.view.current_roi_name = "roi_1"
self.presenter.do_adjust_roi()
self.view.spectrum_widget.adjust_roi.assert_called_once_with(SensibleROI(10, 10, 20, 30), "roi_1")
Expand Down
6 changes: 6 additions & 0 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from PyQt5.QtCore import QSignalBlocker, Qt, QModelIndex

from mantidimaging.core.utility import finder
from mantidimaging.core.utility.sensible_roi import SensibleROI
from mantidimaging.gui.mvp_base import BaseMainWindowView
from mantidimaging.gui.widgets.dataset_selector import DatasetSelectorWidgetView
from .model import ROI_RITS, allowed_modes
Expand Down Expand Up @@ -118,6 +119,11 @@ def disable_roi_properties(self) -> None:
for _, label in self.roiPropertiesLabels.items():
label.setText("0")

def as_roi(self):
roi_iter_order = ["Left", "Top", "Right", "Bottom"]
new_points = [self.roiPropertiesSpinBoxes[prop].value() for prop in roi_iter_order]
return SensibleROI.from_list(new_points)


class SpectrumViewerWindowView(BaseMainWindowView):
tableView: RemovableRowTableView
Expand Down

0 comments on commit d72767a

Please sign in to comment.