Skip to content

Commit

Permalink
fixing mypy errors and making do_add_roi
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeigh committed Dec 2, 2024
1 parent 6bcab34 commit aa8caf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,19 @@ def get_roi_names(self) -> list[str]:
return list(self.view.spectrum_widget.roi_dict.keys())

def do_add_roi(self) -> None:
"""
Add a new ROI to the spectrum
"""
roi_name = self.model.roi_name_generator()
if roi_name in self.view.spectrum_widget.roi_dict:
raise ValueError(f"ROI name already exists: {roi_name}")
self.model.set_new_roi(roi_name)

if self.view.spectrum_widget.roi_dict:
last_roi = self.view.spectrum_widget.get_roi(list(self.view.spectrum_widget.roi_dict)[-1])
roi = SensibleROI(SensibleROI(last_roi.left, last_roi.top, last_roi.right, last_roi.bottom))
self.view.spectrum_widget.add_roi(roi, roi_name)
self.view.set_spectrum(
roi_name, self.model.get_spectrum(roi, self.spectrum_mode, self.view.shuttercount_norm_enabled()))
self.view.auto_range_image()
self.do_add_roi_to_table(roi_name)
roi = self.model._roi_ranges.get(roi_name)
self.view.spectrum_widget.add_roi(roi, roi_name)
spectrum = self.model.get_spectrum(roi, self.spectrum_mode, self.view.shuttercount_norm_enabled())
self.view.set_spectrum(roi_name, spectrum)
self.view.auto_range_image()
self.do_add_roi_to_table(roi_name)

def change_roi_colour(self, roi_name: str, new_colour: tuple[int, int, int]) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PyQt5.QtWidgets import QPushButton, QActionGroup, QGroupBox, QAction, QCheckBox, QTabWidget
from parameterized import parameterized

from mantidimaging.core.data.dataset import StrictDataset, Dataset
from mantidimaging.core.data.dataset import Dataset
from mantidimaging.core.utility.sensible_roi import SensibleROI
from mantidimaging.gui.windows.main import MainWindowView
from mantidimaging.gui.windows.spectrum_viewer import SpectrumViewerWindowView, SpectrumViewerWindowPresenter
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_get_dataset_id_for_stack(self):

def test_handle_sample_change_has_flat_before(self):
self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4())
new_dataset = StrictDataset(sample=generate_images([10, 11, 12]), flat_before=generate_images())
new_dataset = Dataset(sample=generate_images([10, 11, 12]), flat_before=generate_images())
new_dataset.flat_before.name = 'Flat_before'
self.presenter.main_window.get_dataset = mock.Mock(return_value=new_dataset)
self.presenter.main_window.get_stack = mock.Mock(return_value=generate_images())
Expand All @@ -68,7 +68,7 @@ def test_handle_sample_change_has_flat_before(self):

def test_handle_sample_change_has_flat_after(self):
self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4())
new_dataset = StrictDataset(sample=generate_images(), flat_after=generate_images())
new_dataset = Dataset(sample=generate_images(), flat_after=generate_images())
new_dataset.flat_after.name = 'Flat_after'
self.presenter.main_window.get_dataset = mock.Mock(return_value=new_dataset)
self.presenter.main_window.get_stack = mock.Mock(return_value=generate_images())
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_handle_sample_change_to_dataset_no_sample(self):

def test_handle_sample_change_no_flat(self):
self.presenter.get_dataset_id_for_stack = mock.Mock(return_value=uuid.uuid4())
new_dataset = StrictDataset(sample=generate_images())
new_dataset = Dataset(sample=generate_images())
self.presenter.main_window.get_dataset = mock.Mock(return_value=new_dataset)
self.presenter.main_window.get_stack = mock.Mock(return_value=generate_images())
self.presenter.show_new_sample = mock.Mock()
Expand Down

0 comments on commit aa8caf8

Please sign in to comment.