From 4dfc31a84c90a1bd1c7f901136eb90a5a6c91075 Mon Sep 17 00:00:00 2001 From: Darsh Date: Wed, 20 Nov 2024 14:52:55 -0500 Subject: [PATCH 1/3] Updates to fix issues with Pixel Mask DropDown. --- .../ui/view/reduction/ReductionRequestView.py | 1 + src/snapred/ui/workflow/ReductionWorkflow.py | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/snapred/ui/view/reduction/ReductionRequestView.py b/src/snapred/ui/view/reduction/ReductionRequestView.py index bdbb859d4..c0fd683ff 100644 --- a/src/snapred/ui/view/reduction/ReductionRequestView.py +++ b/src/snapred/ui/view/reduction/ReductionRequestView.py @@ -147,6 +147,7 @@ def updateRunNumberList(self): def clearRunNumbers(self): self.runNumbers.clear() self.runNumberDisplay.clear() + self.pixelMaskDropdown.setItems([]) def verify(self): currentText = self.runNumberDisplay.toPlainText() diff --git a/src/snapred/ui/workflow/ReductionWorkflow.py b/src/snapred/ui/workflow/ReductionWorkflow.py index d4a615f60..52f7cf4f7 100644 --- a/src/snapred/ui/workflow/ReductionWorkflow.py +++ b/src/snapred/ui/workflow/ReductionWorkflow.py @@ -92,20 +92,19 @@ def completionMessage(self): @ExceptionToErrLog def _populatePixelMaskDropdown(self): - if len(self._reductionRequestView.getRunNumbers()) == 0: - return - runNumbers = self._reductionRequestView.getRunNumbers() + if not runNumbers: + self._reductionRequestView.pixelMaskDropdown.setItems([]) + return [] + useLiteMode = self._reductionRequestView.liteModeToggle.field.getState() # noqa: F841 self._reductionRequestView.liteModeToggle.setEnabled(False) self._reductionRequestView.pixelMaskDropdown.setEnabled(False) self._reductionRequestView.retainUnfocusedDataCheckbox.setEnabled(False) - # Assemble the list of compatible masks for the current reduction state -- - # note that all run numbers should be from the same state. - compatibleMasks = [] try: + # Get compatible masks for the current reduction state. compatibleMasks = self.request( path="reduction/getCompatibleMasks", payload=ReductionRequest( @@ -114,19 +113,23 @@ def _populatePixelMaskDropdown(self): useLiteMode=useLiteMode, ), ).data - except Exception as e: # noqa: BLE001 - print(e) - # Create a mapping back to the original `WorkspaceName` - # for reconstruction of the complete type after passing through Qt. - self._compatibleMasks = {name.toString(): name for name in compatibleMasks} + # Map mask names to their corresponding WorkspaceName objects. + self._compatibleMasks = {name.toString(): name for name in compatibleMasks} - self._reductionRequestView.pixelMaskDropdown.setItems(list(self._compatibleMasks.keys())) + # Populate the dropdown with the mask names. + self._reductionRequestView.pixelMaskDropdown.setItems(list(self._compatibleMasks.keys())) + except Exception as e: # noqa: BLE001 + print(f"Error retrieving compatible masks: {e}") + self._compatibleMasks = {} + self._reductionRequestView.pixelMaskDropdown.setItems([]) + finally: + # Re-enable UI elements. + self._reductionRequestView.liteModeToggle.setEnabled(True) + self._reductionRequestView.pixelMaskDropdown.setEnabled(True) + self._reductionRequestView.retainUnfocusedDataCheckbox.setEnabled(True) - self._reductionRequestView.liteModeToggle.setEnabled(True) - self._reductionRequestView.pixelMaskDropdown.setEnabled(True) - self._reductionRequestView.retainUnfocusedDataCheckbox.setEnabled(True) - # self._reductionRequestView.convertUnitsDropdown.setEnabled(True) + return list(self._compatibleMasks.keys()) def _validateRunNumbers(self, runNumbers: List[str]): # For now, all run numbers in a reduction batch must be from the same instrument state. @@ -281,6 +284,9 @@ def _finalizeReduction(self, record, unfocusedData): # TODO: make '_clearWorkspaces' a public method (i.e make this combination a special `cleanup` method). self._clearWorkspaces(exclude=self.outputs, clearCachedWorkspaces=True) + def _resetPixelMaskDropDown(self): + self._populatePixelMaskDropdown() + @property def widget(self): return self.workflow.presenter.widget From 84e7e7214e40c1f80c9e63dd57e515a6fb14c4fd Mon Sep 17 00:00:00 2001 From: Darsh Date: Thu, 21 Nov 2024 08:54:57 -0500 Subject: [PATCH 2/3] Whoops, forgot this. --- src/snapred/ui/workflow/ReductionWorkflow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snapred/ui/workflow/ReductionWorkflow.py b/src/snapred/ui/workflow/ReductionWorkflow.py index 4057c6ad1..8240c2b03 100644 --- a/src/snapred/ui/workflow/ReductionWorkflow.py +++ b/src/snapred/ui/workflow/ReductionWorkflow.py @@ -97,7 +97,7 @@ def _populatePixelMaskDropdown(self): self._reductionRequestView.pixelMaskDropdown.setItems([]) return [] - useLiteMode = self._reductionRequestView.liteModeToggle.field.getState() # noqa: F841 + self.useLiteMode = self._reductionRequestView.liteModeToggle.field.getState() # noqa: F841 self._reductionRequestView.liteModeToggle.setEnabled(False) self._reductionRequestView.pixelMaskDropdown.setEnabled(False) From c8335503864bd8d1d94cc3f6cc254cd711f1d905 Mon Sep 17 00:00:00 2001 From: Darsh Date: Thu, 21 Nov 2024 16:21:34 -0500 Subject: [PATCH 3/3] Changes based on Reece's comments. --- src/snapred/ui/workflow/ReductionWorkflow.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/snapred/ui/workflow/ReductionWorkflow.py b/src/snapred/ui/workflow/ReductionWorkflow.py index 8240c2b03..f754647a1 100644 --- a/src/snapred/ui/workflow/ReductionWorkflow.py +++ b/src/snapred/ui/workflow/ReductionWorkflow.py @@ -299,14 +299,6 @@ def _finalizeReduction(self, record, unfocusedData): # Note that the run number is deliberately not deleted from the run numbers list. # Almost certainly it should be moved to a "completed run numbers" list. - # SPECIAL FOR THE REDUCTION WORKFLOW: clear everything _except_ the output workspaces - # _before_ transitioning to the "save" panel. - # TODO: make '_clearWorkspaces' a public method (i.e make this combination a special `cleanup` method). - self._clearWorkspaces(exclude=self.outputs, clearCachedWorkspaces=True) - - def _resetPixelMaskDropDown(self): - self._populatePixelMaskDropdown() - @property def widget(self): return self.workflow.presenter.widget