From 07204198e57e7589d518323cf267beb27a307fc9 Mon Sep 17 00:00:00 2001 From: Darsh Dinger <106342815+darshdinger@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:17:31 -0500 Subject: [PATCH] Ewm6381 fix pixel masks dropdown (#506) * Updates to fix issues with Pixel Mask DropDown. * Whoops, forgot this. * Changes based on Reece's comments. --- .../ui/view/reduction/ReductionRequestView.py | 1 + src/snapred/ui/workflow/ReductionWorkflow.py | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/snapred/ui/view/reduction/ReductionRequestView.py b/src/snapred/ui/view/reduction/ReductionRequestView.py index 383dc6eea..1af923129 100644 --- a/src/snapred/ui/view/reduction/ReductionRequestView.py +++ b/src/snapred/ui/view/reduction/ReductionRequestView.py @@ -130,6 +130,7 @@ def updateRunNumberList(self): def clearRunNumbers(self): self.runNumbers.clear() self.runNumberDisplay.clear() + self.pixelMaskDropdown.setItems([]) def verify(self): runNumbers = [self.runNumberDisplay.item(x).text() for x in range(self.runNumberDisplay.count())] diff --git a/src/snapred/ui/workflow/ReductionWorkflow.py b/src/snapred/ui/workflow/ReductionWorkflow.py index 2e197a004..d9d926610 100644 --- a/src/snapred/ui/workflow/ReductionWorkflow.py +++ b/src/snapred/ui/workflow/ReductionWorkflow.py @@ -93,20 +93,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 [] + self.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( @@ -115,18 +114,23 @@ def _populatePixelMaskDropdown(self): useLiteMode=self.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())) - - self._reductionRequestView.liteModeToggle.setEnabled(True) - self._reductionRequestView.pixelMaskDropdown.setEnabled(True) - self._reductionRequestView.retainUnfocusedDataCheckbox.setEnabled(True) + # 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) + + 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.