Skip to content

Commit

Permalink
cleanups for set_roi_alpha (#1959)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc authored Oct 27, 2023
2 parents 09a4422 + 35ad142 commit 28db74e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
9 changes: 0 additions & 9 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ def redraw_all_rois(self) -> None:
self.model.set_roi(name, self.view.spectrum.get_roi(name))
self.view.set_spectrum(name, self.model.get_spectrum(name, self.spectrum_mode))

def do_set_roi_alpha(self, name: str, alpha: float) -> None:
"""
Set the alpha value of the ROI with the given name
:param name: The name of the ROI
:param alpha: The new alpha value (0-255)
"""
self.view.spectrum.set_roi_alpha(name, alpha)

def handle_button_enabled(self) -> None:
"""
Enable the export button if the current stack is not None and normalisation is valid
Expand Down
17 changes: 8 additions & 9 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ def on_visibility_change(self) -> None:
if self.presenter.export_mode == ExportMode.ROI_MODE:
roi_name, _, roi_visible = self.roi_table_model.row_data(roi_item)
if roi_visible is False:
self.set_roi_alpha(0, roi_item)
self.set_roi_alpha(0, roi_name)
else:
self.set_roi_alpha(255, roi_item)
self.set_roi_alpha(255, roi_name)
self.presenter.redraw_spectrum(roi_name)
else:
self.set_roi_alpha(0, roi_item)
roi_name, _, _ = self.roi_table_model.row_data(roi_item)
self.set_roi_alpha(0, roi_name)

return

Expand Down Expand Up @@ -242,20 +243,18 @@ def set_new_roi(self) -> None:
"""
self.presenter.do_add_roi()

def set_roi_alpha(self, alpha: float, roi) -> None:
def set_roi_alpha(self, alpha: float, roi_name: str) -> None:
"""
Set the alpha value for the selected ROI and update the spectrum to reflect the change.
A check is made on the spectrum to see if it exists as it may not have been created yet.
@param alpha: The alpha value
"""
self.presenter.do_set_roi_alpha(self.roi_table_model.row_data(roi)[0], alpha)
self.spectrum.set_roi_alpha(roi_name, alpha)
if alpha == 0:
self.spectrum.spectrum_data_dict[self.roi_table_model.row_data(roi)[0]] = np.zeros(
self.spectrum.spectrum_data_dict[self.roi_table_model.row_data(roi)[0]].shape)
self.spectrum.spectrum_data_dict[roi_name] = np.zeros(self.spectrum.spectrum_data_dict[roi_name].shape)
else:
self.spectrum.spectrum_data_dict[self.roi_table_model.row_data(roi)[0]] = self.spectrum.spectrum_data_dict[
self.roi_table_model.row_data(roi)[0]]
self.spectrum.spectrum_data_dict[roi_name] = self.spectrum.spectrum_data_dict[roi_name]

self.spectrum.spectrum.clearPlots()
self.spectrum.spectrum.update()
Expand Down

0 comments on commit 28db74e

Please sign in to comment.