Skip to content

Commit

Permalink
Cherry pick fixes from release branch (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackEAllen committed Mar 1, 2024
2 parents 9c736a4 + f39f4a3 commit e82455a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mantidimaging/gui/ui/image_load_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
</item>
<item>
<property name="text">
<string>Sample Log</string>
<string>Sample / Spectra Log</string>
</property>
<property name="text">
<string/>
Expand Down
7 changes: 5 additions & 2 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def handle_roi_moved(self, force_new_spectrums: bool = False) -> None:
self.view.set_spectrum(name, self.model.get_spectrum(name, self.spectrum_mode))

def handle_roi_clicked(self, roi) -> None:
self.view.current_roi = roi.name
self.view.set_roi_properties()
if not roi.name == ROI_RITS:
self.view.current_roi = roi.name
self.view.last_clicked_roi = roi.name
self.view.set_roi_properties()

def redraw_spectrum(self, name: str) -> None:
"""
Expand Down Expand Up @@ -242,6 +244,7 @@ def change_roi_colour(self, roi_name: str, new_colour: tuple) -> None:
if roi_name in self.view.spectrum_widget.roi_dict:
self.view.spectrum_widget.roi_dict[roi_name].colour = new_colour
self.view.update_roi_color(roi_name, new_colour)
self.view.on_visibility_change()

def add_rits_roi(self) -> None:
roi_name = ROI_RITS
Expand Down
5 changes: 4 additions & 1 deletion mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def adjust_spec_roi(self, roi: SensibleROI) -> None:
self.setPos((roi.left, roi.top))
self.setSize((roi.width, roi.height))

def rename_roi(self, new_name: str) -> None:
self._name = new_name


class SpectrumWidget(QWidget):
"""
Expand Down Expand Up @@ -256,14 +259,14 @@ def rename_roi(self, old_name: str, new_name: str) -> None:
if old_name in self.roi_dict.keys() and new_name not in self.roi_dict.keys():
self.roi_dict[new_name] = self.roi_dict.pop(old_name)
self.spectrum_data_dict[new_name] = self.spectrum_data_dict.pop(old_name)
self.roi_dict[new_name].rename_roi(new_name)


class SpectrumPlotWidget(GraphicsLayoutWidget):

spectrum: PlotItem

range_control: LinearRegionItem
roi_dict: dict[Optional[str], ROI]

range_changed = pyqtSignal(object)

Expand Down
37 changes: 30 additions & 7 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class SpectrumViewerWindowView(BaseMainWindowView):

spectrum_widget: SpectrumWidget

number_roi_properties_procced: int = 0

def __init__(self, main_window: 'MainWindowView'):
super().__init__(None, 'gui/ui/spectrum_viewer.ui')

Expand All @@ -64,6 +66,7 @@ def __init__(self, main_window: 'MainWindowView'):
self.selected_row_data: Optional[list] = None
self.roiPropertiesSpinBoxes: dict[str, QSpinBox] = {}
self.roiPropertiesLabels: dict[str, QLabel] = {}
self.old_table_names: list = []

self.presenter = SpectrumViewerWindowPresenter(self, main_window)

Expand Down Expand Up @@ -179,19 +182,20 @@ def on_data_in_table_change() -> None:
If the visibility of an ROI has changed, update the visibility of the ROI in the spectrum widget.
"""
selected_row_data = self.roi_table_model.row_data(self.selected_row)

if selected_row_data[0].lower() not in ["", " ", "all"] and selected_row_data[0] != self.current_roi:
if selected_row_data[0] in self.presenter.get_roi_names():
selected_row_data[0] = self.current_roi
return
selected_row_data[0] = self.old_table_names[self.selected_row]
self.current_roi = selected_row_data[0]
self.last_clicked_roi = self.current_roi
else:
self.presenter.rename_roi(self.current_roi, selected_row_data[0])
self.current_roi = selected_row_data[0]
return
self.last_clicked_roi = self.current_roi
self.set_roi_properties()
else:
selected_row_data[0] = self.current_roi
selected_row_data[0] = self.old_table_names[self.selected_row]

selected_row_data[0] = self.current_roi
self.set_old_table_names()
self.on_visibility_change()
return

Expand All @@ -215,7 +219,14 @@ def on_visibility_change(self) -> None:
When the visibility of an ROI is changed, update the visibility of the ROI in the spectrum widget
"""
if self.presenter.export_mode == ExportMode.ROI_MODE:
self.current_roi = self.last_clicked_roi
if self.current_roi in self.old_table_names and self.last_clicked_roi in self.old_table_names:
pass
elif self.current_roi == ROI_RITS and self.last_clicked_roi in self.old_table_names:
self.current_roi = self.last_clicked_roi
elif self.current_roi == ROI_RITS and self.last_clicked_roi not in self.old_table_names:
self.current_roi = self.roi_table_model.row_data(self.selected_row)[0]
else:
self.last_clicked_roi = self.current_roi
if self.roi_table_model.rowCount() == 0:
self.disable_roi_properties()
if not self.roi_table_model.rowCount() == 0:
Expand Down Expand Up @@ -403,6 +414,7 @@ def add_roi_table_row(self, name: str, colour: tuple[int, int, int]):
self.tableView.selectRow(self.selected_row)
self.current_roi = name
self.removeBtn.setEnabled(True)
self.set_old_table_names()

def remove_roi(self) -> None:
"""
Expand All @@ -421,6 +433,10 @@ def remove_roi(self) -> None:
if self.roi_table_model.rowCount() == 0:
self.removeBtn.setEnabled(False)
self.disable_roi_properties()
else:
self.set_old_table_names()
self.current_roi = self.roi_table_model.row_data(self.selected_row)[0]
self.set_roi_properties()

def clear_all_rois(self) -> None:
"""
Expand Down Expand Up @@ -500,3 +516,10 @@ def disable_roi_properties(self):

def get_roi_properties_spinboxes(self):
return self.roiPropertiesSpinBoxes

def set_old_table_names(self):
self.old_table_names = self.presenter.get_roi_names()
if 'all' in self.old_table_names:
self.old_table_names.remove('all')
if 'rits_roi' in self.old_table_names:
self.old_table_names.remove('rits_roi')

0 comments on commit e82455a

Please sign in to comment.