From 013635ed531f3fd7cf9bc615ef78e41310a1d81a Mon Sep 17 00:00:00 2001 From: Willi L Stepp <52414717+wl-stepp@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:27:22 +0000 Subject: [PATCH] refactor: split run mda in mda widget (#350) --- src/pymmcore_widgets/mda/_core_mda.py | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/pymmcore_widgets/mda/_core_mda.py b/src/pymmcore_widgets/mda/_core_mda.py index 44397b38e..18e7e71b2 100644 --- a/src/pymmcore_widgets/mda/_core_mda.py +++ b/src/pymmcore_widgets/mda/_core_mda.py @@ -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() @@ -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 ----------------------