Skip to content

Commit 8d00017

Browse files
author
shrey
committed
fix merge conflicts, slight refactor
1 parent baa005a commit 8d00017

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

datashuttle/configs/canonical_configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def get_tui_config_defaults() -> Dict:
242242
"bypass_validation": False,
243243
"overwrite_existing_files": "never",
244244
"dry_run": False,
245+
"suggest_next_sub_ses_remote": False,
245246
}
246247
}
247248

datashuttle/datashuttle_class.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,11 @@ def _update_settings_with_new_canonical_keys(self, settings: Dict):
15411541
if "tui" not in settings:
15421542
settings.update(canonical_tui_configs)
15431543

1544-
for key in ["overwrite_existing_files", "dry_run"]:
1544+
for key in [
1545+
"overwrite_existing_files",
1546+
"dry_run",
1547+
"suggest_next_sub_ses_remote",
1548+
]:
15451549
if key not in settings["tui"]:
15461550
settings["tui"][key] = canonical_tui_configs["tui"][key]
15471551

datashuttle/tui/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ def load_project_page(self, interface: Interface) -> None:
103103
def show_modal_error_dialog(self, message: str) -> None:
104104
self.push_screen(modal_dialogs.MessageBox(message, border_color="red"))
105105

106+
def show_modal_error_dialog_from_main_thread(self, message: str) -> None:
107+
"""
108+
Used to call `show_modal_error_dialog from main thread when executing
109+
in another thread. Throws error when called from main thread.
110+
"""
111+
self.call_from_thread(self.show_modal_error_dialog, message)
112+
106113
def handle_open_filesystem_browser(self, path_: Path) -> None:
107114
"""
108115
Open the system file browser to the path with the `showinfm`

datashuttle/tui/interface.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,28 +399,28 @@ def get_textual_compatible_project_configs(self) -> Configs:
399399
return cfg_to_load
400400

401401
def get_next_sub(
402-
self, top_level_folder: TopLevelFolder
402+
self, top_level_folder: TopLevelFolder, include_central: bool
403403
) -> InterfaceOutput:
404404
try:
405405
next_sub = self.project.get_next_sub(
406406
top_level_folder,
407407
return_with_prefix=True,
408-
include_central=False,
408+
include_central=include_central,
409409
)
410410
return True, next_sub
411411
except BaseException as e:
412412
return False, str(e)
413413

414414
def get_next_ses(
415-
self, top_level_folder: TopLevelFolder, sub: str
415+
self, top_level_folder: TopLevelFolder, sub: str, include_central: bool
416416
) -> InterfaceOutput:
417417

418418
try:
419419
next_ses = self.project.get_next_ses(
420420
top_level_folder,
421421
sub,
422422
return_with_prefix=True,
423-
include_central=False,
423+
include_central=include_central,
424424
)
425425
return True, next_ses
426426
except BaseException as e:

datashuttle/tui/screens/create_folder_settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def compose(self) -> ComposeResult:
8686
"""
8787

8888
bypass_validation = self.interface.tui_settings["bypass_validation"]
89-
suggest_next_sub_ses_local_only = self.interface.tui_settings[
90-
"suggest_next_sub_ses_local_only"
89+
suggest_next_sub_ses_remote = self.interface.tui_settings[
90+
"suggest_next_sub_ses_remote"
9191
]
9292

9393
yield Container(
@@ -105,7 +105,7 @@ def compose(self) -> ComposeResult:
105105
Container(
106106
Checkbox(
107107
"Search Remote For Suggestions",
108-
value=not suggest_next_sub_ses_local_only,
108+
value=suggest_next_sub_ses_remote,
109109
id="suggest_next_sub_ses_remote",
110110
),
111111
Checkbox(
@@ -250,7 +250,7 @@ def on_checkbox_changed(self, event: Checkbox.Changed) -> None:
250250
)
251251
elif event.checkbox.id == "suggest_next_sub_ses_remote":
252252
self.interface.save_tui_settings(
253-
not is_on, "suggest_next_sub_ses_local_only"
253+
is_on, "suggest_next_sub_ses_remote"
254254
)
255255

256256
def on_radio_set_changed(self, event: RadioSet.Changed) -> None:

datashuttle/tui/tabs/create_folders.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ def on_clickable_input_clicked(
157157

158158
prefix: Prefix = "sub" if "subject" in input_id else "ses"
159159

160-
async def _on_clickable_input_clicked():
161-
if event.ctrl:
162-
self.fill_input_with_template(prefix, input_id)
163-
else:
160+
if event.ctrl:
161+
self.fill_input_with_template(prefix, input_id)
162+
else:
163+
164+
async def _on_clickable_input_clicked():
164165
input_box = self.query_one(f"#{input_id}")
165166
spinner = CustomSpinner(id="input_suggestion_spinner")
166167
input_box.mount(spinner)
@@ -169,14 +170,14 @@ async def _on_clickable_input_clicked():
169170
prefix,
170171
input_id,
171172
self.interface.get_tui_settings()[
172-
"suggest_next_sub_ses_local_only"
173+
"suggest_next_sub_ses_remote"
173174
],
174175
)
175176
await worker.wait()
176177
spinner.remove()
177178
input_box.disabled = False
178179

179-
asyncio.create_task(_on_clickable_input_clicked())
180+
asyncio.create_task(_on_clickable_input_clicked())
180181

181182
def on_custom_directory_tree_directory_tree_special_key_press(
182183
self, event: CustomDirectoryTree.DirectoryTreeSpecialKeyPress
@@ -293,7 +294,7 @@ def reload_directorytree(self) -> None:
293294
# ----------------------------------------------------------------------------------
294295
@work(exclusive=False, thread=True)
295296
def fill_input_with_next_sub_or_ses_template(
296-
self, prefix: Prefix, input_id: str, local_only: bool
297+
self, prefix: Prefix, input_id: str, include_central: bool
297298
) -> Worker:
298299
"""
299300
This fills a sub / ses Input with a suggested name based on the
@@ -316,17 +317,14 @@ def fill_input_with_next_sub_or_ses_template(
316317
"top_level_folder_select"
317318
]["create_tab"]
318319

319-
def show_error_dialog(output: str) -> None:
320-
self.mainwindow.call_from_thread(
321-
self.mainwindow.show_modal_error_dialog, output
322-
)
323-
324320
if prefix == "sub":
325321
success, output = self.interface.get_next_sub(
326-
top_level_folder, local_only=local_only
322+
top_level_folder, include_central=include_central
327323
)
328324
if not success:
329-
show_error_dialog(output)
325+
self.mainwindow.show_modal_error_dialog_from_main_thread(
326+
output
327+
)
330328
return
331329
else:
332330
next_val = output
@@ -336,14 +334,14 @@ def show_error_dialog(output: str) -> None:
336334
).as_names_list()
337335

338336
if len(sub_names) > 1:
339-
show_error_dialog(
337+
self.mainwindow.show_modal_error_dialog_from_main_thread(
340338
"Can only suggest next session number when a "
341339
"single subject is provided."
342340
)
343341
return
344342

345343
if sub_names == [""]:
346-
show_error_dialog(
344+
self.mainwindow.show_modal_error_dialog_from_main_thread(
347345
"Must input a subject number before suggesting "
348346
"next session number."
349347
)
@@ -353,10 +351,12 @@ def show_error_dialog(output: str) -> None:
353351
sub = sub_names[0]
354352

355353
success, output = self.interface.get_next_ses(
356-
top_level_folder, sub, local_only=local_only
354+
top_level_folder, sub, include_central=include_central
357355
)
358356
if not success:
359-
show_error_dialog(output)
357+
self.mainwindow.show_modal_error_dialog_from_main_thread(
358+
output
359+
)
360360
return
361361
else:
362362
next_val = output

0 commit comments

Comments
 (0)