Skip to content

Commit

Permalink
get around the windows gooey issue chriskiehl/Gooey#907
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurmasson committed Jun 26, 2024
1 parent 0087f27 commit f226b7f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions deepfinder/commands/convert_tiff_to_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']])

Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/detect_spots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/exodeepfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/generate_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/generate_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/merge_detector_expert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions deepfinder/commands/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/structure_training_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions deepfinder/commands/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion deepfinder/commands/utils.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit f226b7f

Please sign in to comment.