diff --git a/kilosort/gui/main.py b/kilosort/gui/main.py index 99a3634..3c2ac3c 100644 --- a/kilosort/gui/main.py +++ b/kilosort/gui/main.py @@ -460,6 +460,7 @@ def add_file_object(self): self.settings_box.use_file_object = True self.settings_box.data_file_path = Path(filename) self.settings_box.data_file_path_input.setText(filename) + self.settings_box.path_check = True def setup_data_view(self): self.data_view_box.setup_seek(self.context) diff --git a/kilosort/gui/settings_box.py b/kilosort/gui/settings_box.py index 3797401..209d9f5 100644 --- a/kilosort/gui/settings_box.py +++ b/kilosort/gui/settings_box.py @@ -31,6 +31,7 @@ def __init__(self, parent): self.gui = parent self.load_enabled = False self.use_file_object = False + self.path_check = None self.select_data_file = QtWidgets.QPushButton("Select Binary File") self.data_file_path = self.gui.data_path @@ -438,16 +439,17 @@ def on_results_directory_changed(self): self.disable_load() def on_data_file_path_changed(self): + self.path_check = None data_file_path = Path(self.data_file_path_input.text()) try: assert self.check_valid_binary_path(data_file_path) + self.data_file_path = data_file_path + self.gui.qt_settings.setValue('data_file_path', data_file_path) parent_folder = data_file_path.parent results_folder = parent_folder / "kilosort4" self.results_directory_input.setText(results_folder.as_posix()) self.results_directory_input.editingFinished.emit() - self.data_file_path = data_file_path - self.gui.qt_settings.setValue('data_file_path', data_file_path) if self.check_settings(): self.enable_load() @@ -458,20 +460,28 @@ def on_data_file_path_changed(self): self.disable_load() def check_valid_binary_path(self, filename): + if self.path_check is not None: + # Flag is set to False when path changes, this is to avoid checking + # the path repeatedly for no reason. + return self.path_check + if filename is None: print('Binary path is None.') - return False + check = False else: f = Path(filename) if f.exists() and f.is_file(): if f.suffix in _ALLOWED_FILE_TYPES or self.use_file_object: - return True + check = True else: print(f'Binary file has invalid suffix. Must be {_ALLOWED_FILE_TYPES}') - return False + check = False else: print('Binary file does not exist at that path.') - return False + check = False + + self.path_check = check + return check def disable_all_input(self, value): for button in self.buttons: @@ -796,6 +806,7 @@ def preapre_for_new_context(self): def reset(self): self.data_file_path_input.clear() self.data_file_path = None + self.path_check = None self.gui.qt_settings.setValue('data_file_path', None) self.results_directory_input.clear() self.results_directory_path = None