From f226b7f52efc908606bcea6391311de69c113550 Mon Sep 17 00:00:00 2001 From: Arthur Masson Date: Wed, 26 Jun 2024 17:49:45 +0200 Subject: [PATCH] get around the windows gooey issue https://github.com/chriskiehl/Gooey/issues/907 --- deepfinder/commands/convert_tiff_to_h5.py | 2 ++ deepfinder/commands/detect_spots.py | 2 ++ deepfinder/commands/exodeepfinder.py | 2 ++ deepfinder/commands/generate_annotation.py | 2 ++ deepfinder/commands/generate_segmentation.py | 2 ++ deepfinder/commands/merge_detector_expert.py | 2 ++ deepfinder/commands/segment.py | 5 +---- deepfinder/commands/structure_training_dataset.py | 2 ++ deepfinder/commands/train.py | 2 ++ deepfinder/commands/utils.py | 9 ++++++++- 10 files changed, 25 insertions(+), 5 deletions(-) diff --git a/deepfinder/commands/convert_tiff_to_h5.py b/deepfinder/commands/convert_tiff_to_h5.py index 40a0694..6594ff4 100755 --- a/deepfinder/commands/convert_tiff_to_h5.py +++ b/deepfinder/commands/convert_tiff_to_h5.py @@ -6,6 +6,8 @@ from deepfinder.commands import utils from gooey import Gooey +utils.run_with_python_on_windows(__file__) + def get_tiff_files(path): return sorted([f for f in path.iterdir() if f.suffix.lower() in ['.tif', '.tiff']]) diff --git a/deepfinder/commands/detect_spots.py b/deepfinder/commands/detect_spots.py index adb41ff..0f18875 100644 --- a/deepfinder/commands/detect_spots.py +++ b/deepfinder/commands/detect_spots.py @@ -6,6 +6,8 @@ from deepfinder.commands.convert_tiff_to_h5 import convert_tiff_to_h5 from gooey import Gooey +utils.run_with_python_on_windows(__file__) + def detect_spots(tiffs_path, detector_path, command, output_path): output_folder = output_path.with_suffix('') output_folder.mkdir(exist_ok=True, parents=True) diff --git a/deepfinder/commands/exodeepfinder.py b/deepfinder/commands/exodeepfinder.py index 69f09d4..ade34c6 100644 --- a/deepfinder/commands/exodeepfinder.py +++ b/deepfinder/commands/exodeepfinder.py @@ -11,6 +11,8 @@ import inspect from gooey import Gooey, GooeyParser +deepfinder.commands.utils.run_with_python_on_windows(__file__) + deepfinder.commands.utils.ignore_gooey_if_args() def get_description(function): diff --git a/deepfinder/commands/generate_annotation.py b/deepfinder/commands/generate_annotation.py index a969a61..b51fc1a 100755 --- a/deepfinder/commands/generate_annotation.py +++ b/deepfinder/commands/generate_annotation.py @@ -12,6 +12,8 @@ import deepfinder.utils.objl as ol from gooey import Gooey +utils.run_with_python_on_windows(__file__) + def cluster(segmentation_path, cluster_radius, output_path=None): output_path.parent.mkdir(exist_ok=True, parents=True) diff --git a/deepfinder/commands/generate_segmentation.py b/deepfinder/commands/generate_segmentation.py index acb5a77..7a43030 100755 --- a/deepfinder/commands/generate_segmentation.py +++ b/deepfinder/commands/generate_segmentation.py @@ -7,6 +7,8 @@ import deepfinder.utils.objl as ol from gooey import Gooey +utils.run_with_python_on_windows(__file__) + # path_output.mkdir(exist_ok=True, parents=True) # First, define the (t,y,x) mask for exocytosis event: diff --git a/deepfinder/commands/merge_detector_expert.py b/deepfinder/commands/merge_detector_expert.py index a25c744..9fc39f7 100755 --- a/deepfinder/commands/merge_detector_expert.py +++ b/deepfinder/commands/merge_detector_expert.py @@ -7,6 +7,8 @@ from deepfinder.commands import utils from gooey import Gooey +utils.run_with_python_on_windows(__file__) + def objlist2motl(objlist_path): """Translate function from MATLAB. Returns the motive list filled up with particle information from xml file. diff --git a/deepfinder/commands/segment.py b/deepfinder/commands/segment.py index 9a43ee3..d6689a7 100755 --- a/deepfinder/commands/segment.py +++ b/deepfinder/commands/segment.py @@ -4,11 +4,8 @@ import deepfinder.utils.common as cm import deepfinder.utils.smap as sm from gooey import Gooey -import platform, sys, subprocess -if platform.system() == 'Windows' and len(sys.argv) == 1: - subprocess.call([sys.executable, __file__]) - sys.exit() +utils.run_with_python_on_windows(__file__) def segment(image_path, weights_path, output_path=None, visualization=False, patch_size=160): if output_path is None: diff --git a/deepfinder/commands/structure_training_dataset.py b/deepfinder/commands/structure_training_dataset.py index d20a198..923485a 100755 --- a/deepfinder/commands/structure_training_dataset.py +++ b/deepfinder/commands/structure_training_dataset.py @@ -5,6 +5,8 @@ from deepfinder.commands import utils from gooey import Gooey +utils.run_with_python_on_windows(__file__) + def structure_training_dataset(input_path:Path, output_path:Path, movie:Path, merged_segmentation:Path, merged_annotation:Path, split:float): if output_path.exists() and len(list(output_path.iterdir()))>0: diff --git a/deepfinder/commands/train.py b/deepfinder/commands/train.py index ff575db..b43b88c 100755 --- a/deepfinder/commands/train.py +++ b/deepfinder/commands/train.py @@ -2,6 +2,8 @@ from deepfinder.commands import utils from gooey import Gooey +utils.run_with_python_on_windows(__file__) + def train(dataset_path, output_path, n_epochs, steps_per_epoch): from deepfinder.training import Train from deepfinder.utils.dataloader import Dataloader diff --git a/deepfinder/commands/utils.py b/deepfinder/commands/utils.py index a079efb..c5bb6b6 100644 --- a/deepfinder/commands/utils.py +++ b/deepfinder/commands/utils.py @@ -1,6 +1,13 @@ -import sys, argparse +import sys, argparse, platform, subprocess from gooey import GooeyParser +# On windows, the command GUIs cannot be used directly, they must be called with python and full path to the command (because of [a known Gooey issue](https://github.com/chriskiehl/Gooey/issues/907)) +# So, if called from the command: rerun the same file but with python and full path +def run_with_python_on_windows(file): + if platform.system() == 'Windows' and len(sys.argv) == 1 and not sys.argv[0].endswith('.py'): + subprocess.call([sys.executable, file]) + sys.exit() + def ignore_gooey_if_args(): if len(sys.argv) > 1 and '--ignore-gooey' not in sys.argv: sys.argv.append('--ignore-gooey')