Merge branch 'mizaki-talker_file_picker' into develop

This commit is contained in:
Timmy Welch 2023-11-09 16:53:15 -08:00
commit 770f64b746

View File

@ -2,6 +2,7 @@ from __future__ import annotations
import logging
from functools import partial
from pathlib import Path
from typing import Any, NamedTuple, cast
import settngs
@ -169,6 +170,31 @@ def generate_password_textbox(option: settngs.Setting, layout: QtWidgets.QGridLa
return widget
def generate_path_textbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QLineEdit:
def open_file_picker():
if widget.text():
current_path = Path(widget.text())
else:
current_path = Path.home()
file_path, _ = QtWidgets.QFileDialog.getOpenFileName(None, "Select File", str(current_path), "")
if file_path:
widget.setText(file_path)
row = layout.rowCount()
lbl = QtWidgets.QLabel(option.display_name)
lbl.setToolTip(option.help)
layout.addWidget(lbl, row, 0)
widget = QtWidgets.QLineEdit()
widget.setToolTip(option.help)
layout.addWidget(widget, row, 1)
browse_button = QtWidgets.QPushButton("Browse")
browse_button.clicked.connect(partial(open_file_picker))
layout.addWidget(browse_button, row, 2)
return widget
def generate_talker_info(talker: ComicTalker, config: settngs.Config, layout: QtWidgets.QGridLayout) -> None:
row = layout.rowCount()
@ -349,6 +375,10 @@ def generate_source_option_tabs(
current_widget = generate_doublespinbox(option, layout_grid)
tab.widgets[option.dest] = current_widget
elif option._guess_type() is Path:
current_widget = generate_path_textbox(option, layout_grid)
tab.widgets[option.dest] = current_widget
elif option._guess_type() is str:
if option.choices is not None:
current_widget = generate_combobox(option, layout_grid)