Skip to content

Commit

Permalink
Ewm6381 fix pixel masks dropdown (#506)
Browse files Browse the repository at this point in the history
* Updates to fix issues with Pixel Mask DropDown.

* Whoops, forgot this.

* Changes based on Reece's comments.
  • Loading branch information
darshdinger authored Nov 27, 2024
1 parent 1f0b521 commit 0720419
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/snapred/ui/view/reduction/ReductionRequestView.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())]
Expand Down
36 changes: 20 additions & 16 deletions src/snapred/ui/workflow/ReductionWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand Down

0 comments on commit 0720419

Please sign in to comment.