From 028f127f89bb971aead93267ff8abaf779dfb5db Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Thu, 22 Feb 2024 11:28:24 +0000 Subject: [PATCH 1/6] Spectrum Viewer ROI visibility fix --- .../gui/windows/spectrum_viewer/presenter.py | 1 + .../spectrum_viewer/spectrum_widget.py | 5 +++- .../gui/windows/spectrum_viewer/view.py | 29 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mantidimaging/gui/windows/spectrum_viewer/presenter.py b/mantidimaging/gui/windows/spectrum_viewer/presenter.py index a6946db0f92..73df17444d3 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/presenter.py +++ b/mantidimaging/gui/windows/spectrum_viewer/presenter.py @@ -138,6 +138,7 @@ def handle_roi_moved(self, force_new_spectrums: bool = False) -> None: def handle_roi_clicked(self, roi) -> None: 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: diff --git a/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py b/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py index aae1afbdf56..6d901f56449 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py +++ b/mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py @@ -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): """ @@ -256,6 +259,7 @@ 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): @@ -263,7 +267,6 @@ class SpectrumPlotWidget(GraphicsLayoutWidget): spectrum: PlotItem range_control: LinearRegionItem - roi_dict: dict[Optional[str], ROI] range_changed = pyqtSignal(object) diff --git a/mantidimaging/gui/windows/spectrum_viewer/view.py b/mantidimaging/gui/windows/spectrum_viewer/view.py index e24da73d5c2..9565001d10b 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/view.py +++ b/mantidimaging/gui/windows/spectrum_viewer/view.py @@ -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') @@ -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) @@ -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 @@ -215,7 +219,10 @@ 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 + else: + self.current_roi = self.last_clicked_roi if self.roi_table_model.rowCount() == 0: self.disable_roi_properties() if not self.roi_table_model.rowCount() == 0: @@ -403,6 +410,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: """ @@ -500,3 +508,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') From 789b2771f349085ad76db33d183969adc4b56836 Mon Sep 17 00:00:00 2001 From: JackEAllen Date: Fri, 23 Feb 2024 15:37:54 +0000 Subject: [PATCH 2/6] Rename Sample Log to Sample / Spectra Log in Load Dialog Window --- mantidimaging/gui/ui/image_load_dialog.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mantidimaging/gui/ui/image_load_dialog.ui b/mantidimaging/gui/ui/image_load_dialog.ui index d2df097eb61..b69e0a920d8 100644 --- a/mantidimaging/gui/ui/image_load_dialog.ui +++ b/mantidimaging/gui/ui/image_load_dialog.ui @@ -116,7 +116,7 @@ - Sample Log + Sample / Spectra Log From 3360acfa67122d0585944c97dce2ae874821f1b0 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Fri, 23 Feb 2024 15:40:43 +0000 Subject: [PATCH 3/6] reset properties table on removing roi --- mantidimaging/gui/windows/spectrum_viewer/view.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mantidimaging/gui/windows/spectrum_viewer/view.py b/mantidimaging/gui/windows/spectrum_viewer/view.py index 9565001d10b..8658e68c4b9 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/view.py +++ b/mantidimaging/gui/windows/spectrum_viewer/view.py @@ -429,6 +429,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: """ From 8ccc465866a5fd73a04d8c86772c512930a71010 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Mon, 26 Feb 2024 11:32:35 +0000 Subject: [PATCH 4/6] Fixed inconsistent state on visibilty change --- mantidimaging/gui/windows/spectrum_viewer/view.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mantidimaging/gui/windows/spectrum_viewer/view.py b/mantidimaging/gui/windows/spectrum_viewer/view.py index 8658e68c4b9..77f2f8023d6 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/view.py +++ b/mantidimaging/gui/windows/spectrum_viewer/view.py @@ -221,8 +221,12 @@ def on_visibility_change(self) -> None: if self.presenter.export_mode == ExportMode.ROI_MODE: if self.current_roi in self.old_table_names and self.last_clicked_roi in self.old_table_names: pass - else: + 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: From 4107844e68c634740c9abf0b4f02f8c2b0b0fd87 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Mon, 26 Feb 2024 15:14:45 +0000 Subject: [PATCH 5/6] When changing the colour of an ROI in RITS mode, call on_visibility_change() to update plot --- mantidimaging/gui/windows/spectrum_viewer/presenter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mantidimaging/gui/windows/spectrum_viewer/presenter.py b/mantidimaging/gui/windows/spectrum_viewer/presenter.py index 73df17444d3..5bb7fb6e5da 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/presenter.py +++ b/mantidimaging/gui/windows/spectrum_viewer/presenter.py @@ -243,6 +243,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 From f39f4a3dc585ef4c8685d547c9213cf032588516 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Mon, 26 Feb 2024 15:20:03 +0000 Subject: [PATCH 6/6] prevent the RITS_ROI from becoming the last_clicked_roi --- mantidimaging/gui/windows/spectrum_viewer/presenter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mantidimaging/gui/windows/spectrum_viewer/presenter.py b/mantidimaging/gui/windows/spectrum_viewer/presenter.py index 5bb7fb6e5da..812b7dc8baa 100644 --- a/mantidimaging/gui/windows/spectrum_viewer/presenter.py +++ b/mantidimaging/gui/windows/spectrum_viewer/presenter.py @@ -137,9 +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.last_clicked_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: """