Skip to content

Commit

Permalink
Added flag to prevent data path none spam
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobpennington committed Oct 29, 2024
1 parent 5117a30 commit b01e00c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions kilosort/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 17 additions & 6 deletions kilosort/gui/settings_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b01e00c

Please sign in to comment.