def ask_path_gui(prompt_msg: str,
settings: Union['Settings', 'nhSettings'],
get_file: bool = False) -> str:
"""Prompt (file) path with Tkinter / CLI prompt.
:param prompt_msg: Directory selection prompt
:param settings: Settings object
:param get_file: When True, prompts for path to file instead of directory
:return: Selected directory / file
"""
try:
if settings.disable_gui_dialog:
raise _tkinter.TclError
root = Tk()
root.withdraw()
if get_file:
file_path = filedialog.askopenfilename(title=prompt_msg)
else:
file_path = filedialog.askdirectory(title=prompt_msg)
root.destroy()
if not file_path:
raise FunctionReturn(("File" if get_file else "Path") + " selection aborted.")
return file_path
except _tkinter.TclError:
return ask_path_cli(prompt_msg, get_file)
评论列表
文章目录