Fix #485
As mentioned in the comment in comictaggerlib/main.py:186 The default value should be None not the empty string. We also check if the given value is the default or the empty string and the setting is unset so the default value is not saved in the settings file. The default_api_url is shown in the GUI Settings Window it is not currently show in the cli help.
This commit is contained in:
parent
4a7aae4045
commit
2e01672e68
@ -29,15 +29,15 @@ def register_talker_settings(manager: settngs.Manager) -> None:
|
||||
for talker_id, talker in comictaggerlib.ctsettings.talkers.items():
|
||||
|
||||
def api_options(manager: settngs.Manager) -> None:
|
||||
# The default needs to be unset or None.
|
||||
# This allows this setting to be unset with the empty string, allowing the default to change
|
||||
manager.add_setting(
|
||||
f"--{talker_id}-key",
|
||||
default="",
|
||||
display_name="API Key",
|
||||
help=f"API Key for {talker.name} (default: {talker.default_api_key})",
|
||||
)
|
||||
manager.add_setting(
|
||||
f"--{talker_id}-url",
|
||||
default="",
|
||||
display_name="URL",
|
||||
help=f"URL for {talker.name} (default: {talker.default_api_url})",
|
||||
)
|
||||
|
@ -99,6 +99,9 @@ def generate_api_widgets(
|
||||
# We overwrite so that the default will be next to the url text box
|
||||
btn_test_row = layout.rowCount()
|
||||
le_url = generate_textbox(talker_url, layout)
|
||||
value, _ = settngs.get_option(config[0], talker_url)
|
||||
if not value:
|
||||
le_url.setText(talkers[talker_id].default_api_url)
|
||||
# To enable setting and getting
|
||||
sources["tabs"][talker_id].widgets[f"talker_{talker_id}_{talker_id}_url"] = le_url
|
||||
|
||||
@ -177,7 +180,7 @@ def settings_to_talker_form(sources: dict[str, QtWidgets.QWidget], config: settn
|
||||
value = getattr(config[0], name)
|
||||
value_type = type(value)
|
||||
try:
|
||||
if value_type is str:
|
||||
if value_type is str and value:
|
||||
widget.setText(value)
|
||||
if value_type is int or value_type is float:
|
||||
widget.setValue(value)
|
||||
|
@ -130,17 +130,17 @@ class ComicTalker:
|
||||
settings is a dictionary of settings defined in register_settings.
|
||||
It is only guaranteed that the settings defined in register_settings will be present.
|
||||
"""
|
||||
if settings.get(f"{self.id}_key"):
|
||||
if settings.get(f"{self.id}_key") is not None:
|
||||
self.api_key = settings[f"{self.id}_key"]
|
||||
if settings.get(f"{self.id}_url"):
|
||||
if settings.get(f"{self.id}_url") is not None:
|
||||
self.api_url = fix_url(settings[f"{self.id}_url"])
|
||||
|
||||
settings[f"{self.id}_url"] = self.api_url
|
||||
|
||||
if self.api_key == "":
|
||||
if self.api_key in ("", self.default_api_key):
|
||||
self.api_key = self.default_api_key
|
||||
if self.api_url == "":
|
||||
settings[f"{self.id}_key"] = None
|
||||
if self.api_url in ("", self.default_api_url):
|
||||
self.api_url = self.default_api_url
|
||||
settings[f"{self.id}_url"] = None
|
||||
return settings
|
||||
|
||||
def check_api_key(self, url: str, key: str) -> tuple[str, bool]:
|
||||
|
@ -194,16 +194,16 @@ class ComicVineTalker(ComicTalker):
|
||||
display_name="Remove HTML tables",
|
||||
help="Removes html tables instead of converting them to text",
|
||||
)
|
||||
# The empty string being the default allows this setting to be unset, allowing the default to change
|
||||
|
||||
# The default needs to be unset or None.
|
||||
# This allows this setting to be unset with the empty string, allowing the default to change
|
||||
parser.add_setting(
|
||||
f"--{self.id}-key",
|
||||
default="",
|
||||
display_name="API Key",
|
||||
help=f"Use the given Comic Vine API Key. (default: {self.default_api_key})",
|
||||
)
|
||||
parser.add_setting(
|
||||
f"--{self.id}-url",
|
||||
default="",
|
||||
display_name="API URL",
|
||||
help=f"Use the given Comic Vine URL. (default: {self.default_api_url})",
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user