Skip to content

Commit

Permalink
refactor: split run mda in mda widget (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-stepp authored Jul 19, 2024
1 parent 53e9ddf commit 013635e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/pymmcore_widgets/mda/_core_mda.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,18 @@ def get_next_available_path(self, requested_path: Path) -> Path:
"""
return get_next_available_path(requested_path=requested_path)

def run_mda(self) -> None:
"""Run the MDA sequence experiment."""
def prepare_mda(self) -> bool | str | Path | None:
"""Prepare the MDA sequence experiment.
Returns
-------
bool
False if MDA to be cancelled due to autofocus issue.
str | Path
Preparation successful, save path to be used for saving and saving active
None
Preparation successful, saving deactivated
"""
# in case the user does not press enter after editing the save name.
self.save_info.save_name.editingFinished.emit()

Expand All @@ -197,20 +207,27 @@ def run_mda(self) -> None:
and (not self.tab_wdg.isChecked(pos) or not pos.af_per_position.isChecked())
and not self._confirm_af_intentions()
):
return

sequence = self.value()
return False

# technically, this is in the metadata as well, but isChecked is more direct
if self.save_info.isChecked():
save_path = self._update_save_path_from_metadata(
sequence, update_metadata=True
return self._update_save_path_from_metadata(
self.value(), update_metadata=True
)
else:
save_path = None
return None

def execute_mda(self, output: Path | str | object | None) -> None:
"""Execute the MDA experiment corresponding to the current value."""
sequence = self.value()
# run the MDA experiment asynchronously
self._mmc.run_mda(sequence, output=save_path)
self._mmc.run_mda(sequence, output=output)

def run_mda(self) -> None:
save_path = self.prepare_mda()
if save_path is False:
return
self.execute_mda(save_path)

# ------------------- private Methods ----------------------

Expand Down

0 comments on commit 013635e

Please sign in to comment.