Use new display_name from settngs. Add source combobox getting and setting and add to sources dict of widgets.

This commit is contained in:
Mizaki 2023-02-20 18:45:39 +00:00
parent bd5e23f93f
commit f439797b03
4 changed files with 44 additions and 54 deletions

View File

@ -63,17 +63,8 @@ def api_url_btn_connect(
btn.clicked.connect(lambda: call_check_api_url(talker_id, sources_info, talkers))
def format_internal_name(dest_name: str) -> str:
int_name_split = dest_name.split("_")
del int_name_split[0:1]
int_name_split[0] = int_name_split[0].capitalize()
new_name = " ".join(int_name_split)
return new_name
def generate_checkbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QCheckBox:
widget = QtWidgets.QCheckBox(format_internal_name(option.dest))
widget = QtWidgets.QCheckBox(option.display_name)
widget.setToolTip(option.help)
layout.addWidget(widget, layout.rowCount(), 0, 1, -1)
@ -82,7 +73,7 @@ def generate_checkbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) ->
def generate_spinbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QSpinBox:
row = layout.rowCount()
lbl = QtWidgets.QLabel(format_internal_name(option.dest))
lbl = QtWidgets.QLabel(option.display_name)
layout.addWidget(lbl, row, 0)
widget = QtWidgets.QSpinBox()
widget.setRange(0, 9999)
@ -94,7 +85,7 @@ def generate_spinbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) ->
def generate_doublespinbox(option: settngs.Setting, layout: QtWidgets.QGridLayout) -> QtWidgets.QDoubleSpinBox:
row = layout.rowCount()
lbl = QtWidgets.QLabel(format_internal_name(option.dest))
lbl = QtWidgets.QLabel(option.display_name)
layout.addWidget(lbl, row, 0)
widget = QtWidgets.QDoubleSpinBox()
widget.setRange(0, 9999.99)
@ -109,7 +100,7 @@ def generate_textbox(
) -> tuple[QtWidgets.QLineEdit, QtWidgets.QPushButton]:
btn = None
row = layout.rowCount()
lbl = QtWidgets.QLabel(format_internal_name(option.dest))
lbl = QtWidgets.QLabel(option.display_name)
layout.addWidget(lbl, row, 0)
widget = QtWidgets.QLineEdit()
widget.setObjectName(option.internal_name)
@ -129,17 +120,16 @@ def generate_textbox(
def settings_to_talker_form(sources: dict[str, QtWidgets.QWidget], config: settngs.Config[settngs.Namespace]) -> None:
for talker in sources.items():
# Set the active talker in sources combo box
sources["talker_source"].setCurrentIndex(sources["talker_source"].findData(config[0].talker_source))
for talker in sources["tabs"].items():
for name, widget in talker[1]["widgets"].items():
value = getattr(config[0], name)
value_type = type(value)
try:
if value_type is str:
# Special case for general dropdown box
if name == "talker_source":
widget.setCurrentIndex(widget.findData(config[0].talker_source))
else:
widget.setText(value)
widget.setText(value)
if value_type is int or value_type is float:
widget.setValue(value)
if value_type is bool:
@ -149,7 +139,10 @@ def settings_to_talker_form(sources: dict[str, QtWidgets.QWidget], config: settn
def form_settings_to_config(sources: dict[str, QtWidgets.QWidget], config: settngs.Config[settngs.Namespace]) -> None:
for tab in sources.items():
# Source combo box value
config[0].talker_source = sources["talker_source"].itemData(sources["talker_source"].currentIndex())
for tab in sources["tabs"].items():
for name, widget in tab[1]["widgets"].items():
widget_value = None
if isinstance(widget, (QtWidgets.QSpinBox, QtWidgets.QDoubleSpinBox)):
@ -158,9 +151,6 @@ def form_settings_to_config(sources: dict[str, QtWidgets.QWidget], config: settn
widget_value = widget.text().strip()
elif isinstance(widget, QtWidgets.QCheckBox):
widget_value = widget.isChecked()
# The talker source dropdown
elif isinstance(widget, QtWidgets.QComboBox):
widget_value = widget.itemData(widget.currentIndex())
setattr(config[0], name, widget_value)
@ -174,7 +164,8 @@ def generate_source_option_tabs(
Generate GUI tabs and settings for talkers
"""
sources: dict = {}
# Store all widgets as to allow easier access to their values vs. using findChildren etc. on the tab widget
sources: dict = {"tabs": {}}
# Tab comes with a QVBoxLayout
comic_talker_tab_layout = comic_talker_tab.layout()
@ -194,13 +185,16 @@ def generate_source_option_tabs(
comic_talker_tab_layout.addLayout(talker_layout)
# Add cbx_info combobox to sources for getting and setting talker
sources["talker_source"] = cbx_info
# Add source sub tabs to Comic Sources tab
for talker_id, talker_obj in talkers.items():
# Add source to general tab dropdown list
cbx_info.addItem(talker_obj.name, talker_id)
tab_name = talker_id
sources[tab_name] = {"tab": QtWidgets.QWidget(), "widgets": {}}
sources["tabs"][tab_name] = {"tab": QtWidgets.QWidget(), "widgets": {}}
layout_grid = QtWidgets.QGridLayout()
for option in config[1][f"talker_{talker_id}"][1].values():
@ -212,17 +206,17 @@ def generate_source_option_tabs(
or option.action == "store_false"
):
current_widget = generate_checkbox(option, layout_grid)
sources[tab_name]["widgets"][option.internal_name] = current_widget
sources["tabs"][tab_name]["widgets"][option.internal_name] = current_widget
elif option.type is int:
current_widget = generate_spinbox(option, layout_grid)
sources[tab_name]["widgets"][option.internal_name] = current_widget
sources["tabs"][tab_name]["widgets"][option.internal_name] = current_widget
elif option.type is float:
current_widget = generate_doublespinbox(option, layout_grid)
sources[tab_name]["widgets"][option.internal_name] = current_widget
sources["tabs"][tab_name]["widgets"][option.internal_name] = current_widget
# option.type of None should be string
elif option.type is None or option.type is str:
current_widget, btn = generate_textbox(option, layout_grid)
sources[tab_name]["widgets"][option.internal_name] = current_widget
sources["tabs"][tab_name]["widgets"][option.internal_name] = current_widget
if option.internal_name.endswith("key"):
# Attach test api function to button. A better way?
@ -237,9 +231,9 @@ def generate_source_option_tabs(
vspacer = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
layout_grid.addItem(vspacer, layout_grid.rowCount() + 1, 0)
# Display the new widgets
sources[tab_name]["tab"].setLayout(layout_grid)
sources["tabs"][tab_name]["tab"].setLayout(layout_grid)
# Add new sub tab to Comic Source tab
talker_tabs.addTab(sources[tab_name]["tab"], talker_obj.name)
talker_tabs.addTab(sources["tabs"][tab_name]["tab"], talker_obj.name)
return sources

View File

@ -181,16 +181,29 @@ class ComicVineTalker(ComicTalker):
self.wait_on_ratelimit_time: int = 20
def register_settings(self, parser: settngs.Manager) -> None:
parser.add_setting("--cv-use-series-start-as-volume", default=False, action=argparse.BooleanOptionalAction)
parser.add_setting("--cv-wait-on-ratelimit", default=False, action=argparse.BooleanOptionalAction)
parser.add_setting(
"--cv-use-series-start-as-volume",
default=False,
action=argparse.BooleanOptionalAction,
display_name="Use series start as volume",
help="Use the series start year as the volume number",
)
parser.add_setting(
"--cv-wait-on-ratelimit",
default=False,
action=argparse.BooleanOptionalAction,
display_name="Wait on ratelimit",
help="Wait when the rate limit is hit",
)
parser.add_setting(
"--cv-remove-html-tables",
default=False,
action=argparse.BooleanOptionalAction,
help="Removes html tables instead of converting them to text.",
display_name="Remove HTML tables",
help="Removes html tables instead of converting them to text",
)
parser.add_setting("--cv-api-key", help="Use the given Comic Vine API Key.")
parser.add_setting("--cv-url", help="Use the given Comic Vine URL.")
parser.add_setting("--cv-api-key", display_name="API Key", help="Use the given Comic Vine API Key")
parser.add_setting("--cv-url", display_name="URL", help="Use the given Comic Vine URL")
def parse_settings(self, settings: dict[str, Any]) -> dict[str, Any]:
if settings["cv_api_key"]:

View File

@ -8,7 +8,7 @@ pycountry
#pyicu; sys_platform == 'linux' or sys_platform == 'darwin'
rapidfuzz>=2.12.0
requests==2.*
settngs==0.5.0
settngs==0.6.2
text2digits
typing_extensions
wordninja

View File

@ -1,17 +0,0 @@
from __future__ import annotations
import pytest
import comictaggerlib.ui.talkeruigenerator
test_names = [
("cv_test_name", "Test name"),
("cv2_test_name", "Test name"),
("mu_use_this_test", "Use this test"),
]
@pytest.mark.parametrize("int_name, expected", test_names)
def test_format_internal_name(int_name, expected):
results = comictaggerlib.ui.talkeruigenerator.format_internal_name(int_name)
assert results == expected