From 400092dd8462d4aee31d6beda7c2ef315a0bc002 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 2 Mar 2025 13:34:23 -0800 Subject: [PATCH] Notify user when no tags are enabled --- comicapi/comicarchive.py | 1 + comictaggerlib/ctsettings/commandline.py | 25 +++++++++++++++++++++++- comictaggerlib/ctsettings/types.py | 5 +++-- comictaggerlib/gui.py | 2 +- comictaggerlib/main.py | 7 ------- comictaggerlib/taggerwindow.py | 17 +++++++++++++--- 6 files changed, 43 insertions(+), 14 deletions(-) diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index 22b56d9..f93c953 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -234,6 +234,7 @@ class ComicArchive: if tag_id in self.md: del self.md[tag_id] if not tags[tag_id].enabled: + logger.warning("%s tags not enabled", tags[tag_id].name()) return False self.apply_archive_info_to_metadata(metadata, True, True, hash_archive=self.hash_archive) diff --git a/comictaggerlib/ctsettings/commandline.py b/comictaggerlib/ctsettings/commandline.py index f821774..f1adb53 100644 --- a/comictaggerlib/ctsettings/commandline.py +++ b/comictaggerlib/ctsettings/commandline.py @@ -26,7 +26,7 @@ import subprocess import settngs -from comicapi import utils +from comicapi import comicarchive, utils from comicapi.comicarchive import tags from comictaggerlib import ctversion, quick_tag from comictaggerlib.ctsettings.settngs_namespace import SettngsNS as ct_ns @@ -283,6 +283,9 @@ def validate_commandline_settings(config: settngs.Config[ct_ns], parser: settngs + "Distributed under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)\n", ) + if not config[0].Metadata_Options__cr and "cr" in comicarchive.tags and comicarchive.tags["cr"].enabled: + comicarchive.tags["cr"].enabled = False + config[0].Runtime_Options__no_gui = any( (config[0].Commands__command != Action.gui, config[0].Runtime_Options__no_gui, config[0].Commands__copy) ) @@ -302,6 +305,26 @@ def validate_commandline_settings(config: settngs.Config[ct_ns], parser: settngs if config[0].Runtime_Options__tags_read and not config[0].Runtime_Options__tags_write: config[0].Runtime_Options__tags_write = config[0].Runtime_Options__tags_read + disabled_tags = {tag for tag in comicarchive.tags if not comicarchive.tags[tag].enabled} + to_be_removed = ( + set(config[0].Runtime_Options__tags_read).union(config[0].Runtime_Options__tags_write).union(disabled_tags) + ) + if to_be_removed: + logger.debug("Removing disabled tags: %s", to_be_removed) + config[0].Runtime_Options__tags_read = [ + tag for tag in config[0].Runtime_Options__tags_read if tag not in to_be_removed + ] + config[0].Runtime_Options__tags_write = [ + tag for tag in config[0].Runtime_Options__tags_write if tag not in to_be_removed + ] + + if ( + config[0].Runtime_Options__no_gui + and not [tag.id for tag in tags.values() if tag.enabled] + and config[0].Commands__command != Action.list_plugins + ): + parser.exit(status=1, message="There are no tags enabled see --list-plugins\n") + if config[0].Runtime_Options__no_gui and not config[0].Runtime_Options__files: if config[0].Commands__command == Action.print and not config[0].Auto_Tag__metadata.is_empty: ... # allow printing the metadata provided on the commandline diff --git a/comictaggerlib/ctsettings/types.py b/comictaggerlib/ctsettings/types.py index 09d8c4c..e3589f2 100644 --- a/comictaggerlib/ctsettings/types.py +++ b/comictaggerlib/ctsettings/types.py @@ -152,11 +152,12 @@ class ComicTaggerPaths(AppDirs): def tag(types: str) -> list[str]: + enabled_tags = [tag for tag in tags if tags[tag].enabled] result = [] types = types.casefold() for typ in utils.split(types, ","): - if typ not in tags: - choices = ", ".join(tags) + if typ not in enabled_tags: + choices = ", ".join(enabled_tags) raise argparse.ArgumentTypeError(f"invalid choice: {typ} (choose from {choices.upper()})") result.append(tags[typ].id) return result diff --git a/comictaggerlib/gui.py b/comictaggerlib/gui.py index 74ee72b..dcb82d3 100644 --- a/comictaggerlib/gui.py +++ b/comictaggerlib/gui.py @@ -82,7 +82,7 @@ try: # Handles "Open With" from Finder on macOS def event(self, event: QtCore.QEvent) -> bool: if event.type() == QtCore.QEvent.FileOpen: - logger.info(event.url().toLocalFile()) + logger.info("file open recieved: %s", event.url().toLocalFile()) self.openFileRequest.emit(event.url()) return True return super().event(event) diff --git a/comictaggerlib/main.py b/comictaggerlib/main.py index 9e59891..4c88b14 100644 --- a/comictaggerlib/main.py +++ b/comictaggerlib/main.py @@ -246,13 +246,6 @@ class App: # config already loaded error = None - if ( - not self.config[0].Metadata_Options__cr - and "cr" in comicapi.comicarchive.tags - and comicapi.comicarchive.tags["cr"].enabled - ): - comicapi.comicarchive.tags["cr"].enabled = False - if len(self.talkers) < 1: error = ( "Failed to load any talkers, please re-install and check the log located in '" diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index f3b1f9a..d44ab51 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -234,8 +234,8 @@ class TaggerWindow(QtWidgets.QMainWindow): if self.config[0].Runtime_Options__preferred_hash: self.config[0].internal__embedded_hash_type = self.config[0].Runtime_Options__preferred_hash - self.selected_write_tags: list[str] = config[0].internal__write_tags or [self.enabled_tags()[0]] - self.selected_read_tags: list[str] = config[0].internal__read_tags or [self.enabled_tags()[0]] + self.selected_write_tags: list[str] = config[0].internal__write_tags + self.selected_read_tags: list[str] = config[0].internal__read_tags self.setAcceptDrops(True) self.view_tag_actions, self.remove_tag_actions = self.tag_actions() @@ -352,7 +352,18 @@ class TaggerWindow(QtWidgets.QMainWindow): """, ) self.config[0].Dialog_Flags__notify_plugin_changes = not checked - + if self.enabled_tags(): + self.selected_write_tags = [self.enabled_tags()[0]] + self.selected_read_tags = [self.enabled_tags()[0]] + else: + checked = OptionalMessageDialog.msg_no_checkbox( + self, + "No tags enabled", + """ + There are no tags enabled!

+ Go to the "Metadata Options" tab in settings to enable the builtin "Comic Rack" tags + """, + ) if self.config[0].General__check_for_new_version: self.check_latest_version_online()