Skip to content

Commit

Permalink
fix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrgsp committed Nov 7, 2024
1 parent d8eac31 commit ccd76d2
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/pymmcore_widgets/useq_widgets/_mda_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ def _settings_extensions(self) -> str:
# Only JSON
return "All (*.json);;JSON (*.json)"

def _enable_af(self, state: bool, tooltip1: str, tooltip2: str) -> None:
"""Enable or disable autofocus settings."""
self.af_axis.setEnabled(state)
self.af_axis.setToolTip(tooltip1)
self.stage_positions.af_per_position.setEnabled(state)
self.stage_positions.af_per_position.setChecked(state)
self.stage_positions.af_per_position.setToolTip(tooltip2)

def _validate_af_with_z_plan(self) -> None:
"""Check if the autofocus plan can be used with the current Z Plan.
Expand All @@ -510,11 +518,7 @@ def _validate_af_with_z_plan(self) -> None:
"The hardware autofocus cannot be used with absolute Z positions "
"(TOP_BOTTOM mode)."
)
self.af_axis.setEnabled(False)
self.af_axis.setToolTip(tooltip)
self.stage_positions.af_per_position.setEnabled(False)
self.stage_positions.af_per_position.setChecked(False)
self.stage_positions.af_per_position.setToolTip(tooltip)
self._enable_af(False, tooltip, tooltip)
if self.af_axis.use_af_p.isChecked():
QMessageBox.warning(
self,
Expand All @@ -527,10 +531,7 @@ def _validate_af_with_z_plan(self) -> None:
defaultButton=QMessageBox.StandardButton.Ok,
)
else:
self.af_axis.setEnabled(True)
self.af_axis.setToolTip(AF_TOOLTIP)
self.stage_positions.af_per_position.setEnabled(True)
self.stage_positions.af_per_position.setToolTip(AF_DEFAULT_TOOLTIP)
self._enable_af(True, AF_TOOLTIP, AF_DEFAULT_TOOLTIP)

self.valueChanged.emit()

Expand All @@ -540,10 +541,7 @@ def _on_tab_checked(self, tab_idx: int) -> None:
if self.tab_wdg.isChecked(self.z_plan):
self._validate_af_with_z_plan()
else:
self.af_axis.setEnabled(True)
self.af_axis.setToolTip(AF_TOOLTIP)
self.stage_positions.af_per_position.setEnabled(True)
self.stage_positions.af_per_position.setToolTip(AF_DEFAULT_TOOLTIP)
self._enable_af(True, AF_TOOLTIP, AF_DEFAULT_TOOLTIP)

self._update_available_axis_orders()

Expand Down

0 comments on commit ccd76d2

Please sign in to comment.