Skip to content

Commit b2ee792

Browse files
Refactor ROI management to delegate colour, visibility, and alpha to SpectrumROI (#2340)
2 parents 7a87f91 + 36af36d commit b2ee792

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def colour(self) -> tuple[int, int, int, int]:
8989
def colour(self, colour: tuple[int, int, int, int]) -> None:
9090
self._colour = colour
9191
self.setPen(self._colour)
92+
self.hoverPen = mkPen(self._colour, width=3)
93+
94+
def set_visibility(self, visible: bool) -> None:
95+
"""
96+
Set the visibility of the ROI and its handles.
97+
"""
98+
self.setVisible(visible)
99+
for handle in self.getHandles():
100+
handle.setVisible(visible)
92101

93102
@property
94103
def selected_row(self) -> int | None:
@@ -166,12 +175,8 @@ def colour_generator(self) -> tuple[int, int, int, int]:
166175
def change_roi_colour(self, name: str, colour: tuple[int, int, int, int]) -> None:
167176
"""
168177
Change the colour of an existing ROI
169-
170-
@param name: The name of the ROI.
171-
@param colour: The new colour of the ROI.
172178
"""
173179
self.roi_dict[name].colour = colour
174-
self.roi_dict[name].setPen(self.roi_dict[name].colour)
175180

176181
def set_roi_visibility_flags(self, name: str, visible: bool) -> None:
177182
"""
@@ -181,19 +186,14 @@ def set_roi_visibility_flags(self, name: str, visible: bool) -> None:
181186
@param name: The name of the ROI.
182187
@param visible: The new visibility of the ROI.
183188
"""
184-
handles = self.roi_dict[name].getHandles()
185-
for handle in handles:
186-
handle.setVisible(visible)
187-
self.roi_dict[name].setVisible(visible)
189+
self.roi_dict[name].set_visibility(visible)
188190

189191
def set_roi_alpha(self, name: str, alpha: float) -> None:
190192
"""
191193
Change the alpha value of an existing ROI
192-
193194
@param name: The name of the ROI.
194195
@param alpha: The new alpha value of the ROI.
195196
"""
196-
197197
self.roi_dict[name].colour = self.roi_dict[name].colour[:3] + (alpha, )
198198
self.roi_dict[name].setPen(self.roi_dict[name].colour)
199199
self.roi_dict[name].hoverPen = mkPen(self.roi_dict[name].colour, width=3)
@@ -271,7 +271,7 @@ def rename_roi(self, old_name: str, new_name: str) -> None:
271271
class CustomViewBox(ViewBox):
272272

273273
def __init__(self, *args, **kwds) -> None:
274-
#kwds['enableMenu'] = False
274+
# kwds['enableMenu'] = False
275275
ViewBox.__init__(self, *args, **kwds)
276276
self.setMouseMode(self.PanMode)
277277

mantidimaging/gui/windows/spectrum_viewer/test/spectrum_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_WHEN_set_roi_visibility_flags_called_THEN_roi_Visibility_flags_toggled(
9090
self.spectrum_widget.set_roi_visibility_flags(name, alpha)
9191
self.assertEqual(bool(alpha), self.spectrum_widget.roi_dict[name].isVisible())
9292

93-
@parameterized.expand([("Visible", "visible_roi", 1), ("Invisible", "invisible_roi", 0)])
93+
@parameterized.expand([("Visible", "visible_roi", 255), ("Invisible", "invisible_roi", 0)])
9494
def test_WHEN_set_roi_alpha_called_THEN_roi_alpha_updated(self, _, name, alpha):
9595
spectrum_roi = SpectrumROI(name, self.sensible_roi, rotatable=False, scaleSnap=True, translateSnap=True)
9696
self.spectrum_widget.roi_dict[name] = spectrum_roi

0 commit comments

Comments
 (0)