From 0198eb9e2bd2717015792b7aead7ff10d76b8a74 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Thu, 6 Jun 2024 20:41:21 -0700 Subject: [PATCH] Fix saving merge settings --- comictaggerlib/autotagmatchwindow.py | 3 +- comictaggerlib/cli.py | 4 +- comictaggerlib/ctsettings/commandline.py | 27 +-- comictaggerlib/ctsettings/file.py | 31 +++- .../ctsettings/settngs_namespace.py | 20 +-- comictaggerlib/md.py | 2 +- comictaggerlib/settingswindow.py | 24 +-- comictaggerlib/taggerwindow.py | 13 +- comictaggerlib/ui/settingswindow.ui | 170 ++++++++++-------- 9 files changed, 153 insertions(+), 141 deletions(-) diff --git a/comictaggerlib/autotagmatchwindow.py b/comictaggerlib/autotagmatchwindow.py index dfcdca1..ecb4537 100644 --- a/comictaggerlib/autotagmatchwindow.py +++ b/comictaggerlib/autotagmatchwindow.py @@ -26,6 +26,7 @@ from comicapi.comicarchive import ComicArchive, metadata_styles from comicapi.genericmetadata import GenericMetadata from comictaggerlib.coverimagewidget import CoverImageWidget from comictaggerlib.ctsettings import ct_ns +from comictaggerlib.md import prepare_metadata from comictaggerlib.resulttypes import IssueResult, Result from comictaggerlib.ui import ui_path from comictaggerlib.ui.qtutils import reduce_widget_font_size @@ -262,7 +263,7 @@ class AutoTagMatchWindow(QtWidgets.QDialog): return QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.CursorShape.WaitCursor)) - md.overlay(ct_md, self.config.internal__source_data_overlay, self.config.internal__overlay_merge_lists) + md = prepare_metadata(md, ct_md, self.config) for style in self._styles: success = ca.write_metadata(md, style) QtWidgets.QApplication.restoreOverrideCursor() diff --git a/comictaggerlib/cli.py b/comictaggerlib/cli.py index ab5a106..74c3814 100644 --- a/comictaggerlib/cli.py +++ b/comictaggerlib/cli.py @@ -253,7 +253,9 @@ class CLI: if ca.has_metadata(style): try: t_md = ca.read_metadata(style) - md.overlay(t_md, self.config.internal__load_data_overlay, self.config.internal__overlay_merge_lists) + md.overlay( + t_md, self.config.Metadata_Options__comic_merge, self.config.Metadata_Options__comic_merge_lists + ) break except Exception as e: logger.error("Failed to load metadata for %s: %s", ca.path, e) diff --git a/comictaggerlib/ctsettings/commandline.py b/comictaggerlib/ctsettings/commandline.py index 0be17bd..10eee77 100644 --- a/comictaggerlib/ctsettings/commandline.py +++ b/comictaggerlib/ctsettings/commandline.py @@ -25,7 +25,7 @@ import subprocess import settngs -from comicapi import merge, utils +from comicapi import utils from comicapi.comicarchive import metadata_styles from comictaggerlib import ctversion from comictaggerlib.ctsettings.settngs_namespace import SettngsNS as ct_ns @@ -153,31 +153,6 @@ def register_runtime(parser: settngs.Manager) -> None: help="""Specify the type of tags to write.\nUse commas for multiple types.\nRead types will be used if unspecified\nSee --list-plugins for the available types.\n\n""", file=False, ) - parser.add_setting( - "--read-style-merge", - metavar=f"{{{','.join(merge.Mode)}}}", - default=merge.Mode.OVERLAY, - choices=merge.Mode, - type=merge.Mode, - help="How to merge additional metadata for enabled read styles (CR, CBL, etc.) See -t, --type-read default: %(default)s", - file=False, - ) - parser.add_setting( - "--source-merge", - metavar=f"{{{','.join(merge.Mode)}}}", - default=merge.Mode.OVERLAY, - choices=merge.Mode, - type=merge.Mode, - help="How to merge new metadata from a data source (CV, Metron, GCD, etc.) default: %(default)s", - file=False, - ) - parser.add_setting( - "--merge-lists", - action=argparse.BooleanOptionalAction, - default=True, - help="Merge all items of lists when merging new metadata (genres, characters, etc.) default: %(default)s", - file=False, - ) parser.add_setting( "--skip-existing-metadata", action=argparse.BooleanOptionalAction, diff --git a/comictaggerlib/ctsettings/file.py b/comictaggerlib/ctsettings/file.py index b82a772..e4769a8 100644 --- a/comictaggerlib/ctsettings/file.py +++ b/comictaggerlib/ctsettings/file.py @@ -28,9 +28,6 @@ def internal(parser: settngs.Manager) -> None: parser.add_setting("install_id", default=uuid.uuid4().hex, cmdline=False) parser.add_setting("save_data_style", default=["cbi"], cmdline=False) parser.add_setting("load_data_style", default=["cbi"], cmdline=False) - parser.add_setting("load_data_overlay", default=merge.Mode.OVERLAY, cmdline=False, type=merge.Mode) - parser.add_setting("source_data_overlay", default=merge.Mode.OVERLAY, cmdline=False, type=merge.Mode) - parser.add_setting("overlay_merge_lists", default=True, cmdline=False, action=argparse.BooleanOptionalAction) parser.add_setting("last_opened_folder", default="", cmdline=False) parser.add_setting("window_width", default=0, cmdline=False) parser.add_setting("window_height", default=0, cmdline=False) @@ -164,6 +161,34 @@ def md_options(parser: settngs.Manager) -> None: action=argparse.BooleanOptionalAction, help="Enable the ComicRack metadata type. Turn off to only use the CIX metadata type.\ndefault: %(default)s", ) + parser.add_setting( + "--comic-merge", + metavar=f"{{{','.join(merge.Mode)}}}", + default=merge.Mode.OVERLAY, + choices=merge.Mode, + type=merge.Mode, + help="How to merge additional metadata for enabled read styles (CR, CBL, etc.) See -t, --type-read default: %(default)s", + ) + parser.add_setting( + "--metadata-merge", + metavar=f"{{{','.join(merge.Mode)}}}", + default=merge.Mode.OVERLAY, + choices=merge.Mode, + type=merge.Mode, + help="How to merge new metadata from a data source (CV, Metron, GCD, etc.) default: %(default)s", + ) + parser.add_setting( + "--comic-merge-lists", + action=argparse.BooleanOptionalAction, + default=True, + help="Merge all items of lists when merging new metadata (genres, characters, etc.) default: %(default)s", + ) + parser.add_setting( + "--metadata-merge-lists", + action=argparse.BooleanOptionalAction, + default=True, + help="Merge all items of lists when merging new metadata (genres, characters, etc.) default: %(default)s", + ) def rename(parser: settngs.Manager) -> None: diff --git a/comictaggerlib/ctsettings/settngs_namespace.py b/comictaggerlib/ctsettings/settngs_namespace.py index a106485..052643e 100644 --- a/comictaggerlib/ctsettings/settngs_namespace.py +++ b/comictaggerlib/ctsettings/settngs_namespace.py @@ -34,18 +34,12 @@ class SettngsNS(settngs.TypedNS): Runtime_Options__delete_original: bool Runtime_Options__type_read: list[str] Runtime_Options__type_modify: list[str] - Runtime_Options__read_style_merge: comicapi.merge.Mode - Runtime_Options__source_merge: comicapi.merge.Mode - Runtime_Options__merge_lists: bool Runtime_Options__skip_existing_metadata: bool Runtime_Options__files: list[str] internal__install_id: str internal__save_data_style: list[str] internal__load_data_style: list[str] - internal__load_data_overlay: comicapi.merge.Mode - internal__source_data_overlay: comicapi.merge.Mode - internal__overlay_merge_lists: bool internal__last_opened_folder: str internal__window_width: int internal__window_height: int @@ -84,6 +78,10 @@ class SettngsNS(settngs.TypedNS): Metadata_Options__apply_transform_on_bulk_operation: bool Metadata_Options__use_short_metadata_names: bool Metadata_Options__cr: bool + Metadata_Options__comic_merge: comicapi.merge.Mode + Metadata_Options__metadata_merge: comicapi.merge.Mode + Metadata_Options__comic_merge_lists: bool + Metadata_Options__metadata_merge_lists: bool File_Rename__template: str File_Rename__issue_number_padding: int @@ -147,9 +145,6 @@ class Runtime_Options(typing.TypedDict): delete_original: bool type_read: list[str] type_modify: list[str] - read_style_merge: comicapi.merge.Mode - source_merge: comicapi.merge.Mode - merge_lists: bool skip_existing_metadata: bool files: list[str] @@ -158,9 +153,6 @@ class internal(typing.TypedDict): install_id: str save_data_style: list[str] load_data_style: list[str] - load_data_overlay: comicapi.merge.Mode - source_data_overlay: comicapi.merge.Mode - overlay_merge_lists: bool last_opened_folder: str window_width: int window_height: int @@ -207,6 +199,10 @@ class Metadata_Options(typing.TypedDict): apply_transform_on_bulk_operation: bool use_short_metadata_names: bool cr: bool + comic_merge: comicapi.merge.Mode + metadata_merge: comicapi.merge.Mode + comic_merge_lists: bool + metadata_merge_lists: bool class File_Rename(typing.TypedDict): diff --git a/comictaggerlib/md.py b/comictaggerlib/md.py index 33b00d9..bb90dbe 100644 --- a/comictaggerlib/md.py +++ b/comictaggerlib/md.py @@ -18,7 +18,7 @@ def prepare_metadata(md: GenericMetadata, new_md: GenericMetadata, opts: Settngs if opts.Auto_Tag__clear_metadata: final_md = GenericMetadata() - final_md.overlay(new_md) + final_md.overlay(new_md, opts.Metadata_Options__metadata_merge, opts.Metadata_Options__metadata_merge_lists) if final_md.tag_origin is not None: notes = ( f"Tagged with ComicTagger {ctversion.version} using info from {final_md.tag_origin.name} on" diff --git a/comictaggerlib/settingswindow.py b/comictaggerlib/settingswindow.py index 1dcda54..96f105b 100644 --- a/comictaggerlib/settingswindow.py +++ b/comictaggerlib/settingswindow.py @@ -195,8 +195,8 @@ class SettingsWindow(QtWidgets.QDialog): self.cbFilenameParser.clear() self.cbFilenameParser.addItems(utils.Parser) for mode in merge.Mode: - self.cbxOverlayReadStyle.addItem(mode.name.capitalize().replace("_", " "), mode.value) - self.cbxOverlaySource.addItem(mode.name.capitalize().replace("_", " "), mode.value) + self.cbMergeModeComic.addItem(mode.name.capitalize().replace("_", " "), mode) + self.cbMergeModeMetadata.addItem(mode.name.capitalize().replace("_", " "), mode) self.connect_signals() self.settings_to_form() self.rename_test() @@ -431,13 +431,15 @@ class SettingsWindow(QtWidgets.QDialog): self.cbxApplyCBLTransformOnBatchOperation.setChecked( self.config[0].Metadata_Options__apply_transform_on_bulk_operation ) - self.cbxOverlayReadStyle.setCurrentIndex( - self.cbxOverlayReadStyle.findData(self.config[0].internal__load_data_overlay.value) + + self.cbMergeModeComic.setCurrentIndex( + self.cbMergeModeComic.findData(self.config[0].Metadata_Options__comic_merge) ) - self.cbxOverlaySource.setCurrentIndex( - self.cbxOverlaySource.findData(self.config[0].internal__source_data_overlay.value) + self.cbMergeModeMetadata.setCurrentIndex( + self.cbMergeModeMetadata.findData(self.config[0].Metadata_Options__metadata_merge) ) - self.cbxOverlayMergeLists.setChecked(self.config[0].internal__overlay_merge_lists) + self.cbxMergeListsComic.setChecked(self.config[0].Metadata_Options__comic_merge_lists) + self.cbxMergeListsMetadata.setChecked(self.config[0].Metadata_Options__metadata_merge_lists) self.cbxShortMetadataNames.setChecked(self.config[0].Metadata_Options__use_short_metadata_names) self.cbxEnableCR.setChecked(self.config[0].Metadata_Options__cr) @@ -562,10 +564,12 @@ class SettingsWindow(QtWidgets.QDialog): self.cbxApplyCBLTransformOnBatchOperation.isChecked() ) - self.config[0].internal__load_data_overlay = merge.Mode[self.cbxOverlayReadStyle.currentData().upper()] - self.config[0].internal__source_data_overlay = merge.Mode[self.cbxOverlaySource.currentData().upper()] - self.config[0].internal__overlay_merge_lists = self.cbxOverlayMergeLists.isChecked() + self.config[0].Metadata_Options__comic_merge = merge.Mode(self.cbMergeModeComic.currentData()) + self.config[0].Metadata_Options__metadata_merge = merge.Mode(self.cbMergeModeMetadata.currentData()) + self.config[0].Metadata_Options__comic_merge_lists = self.cbxMergeListsComic.isChecked() + self.config[0].Metadata_Options__metadata_merge_lists = self.cbxMergeListsMetadata.isChecked() self.config[0].Metadata_Options__cr = self.cbxEnableCR.isChecked() + # Update metadata style names if required if self.config[0].Metadata_Options__use_short_metadata_names != self.cbxShortMetadataNames.isChecked(): self.config[0].Metadata_Options__use_short_metadata_names = self.cbxShortMetadataNames.isChecked() diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index c3bf113..61d2ae9 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -218,20 +218,13 @@ class TaggerWindow(QtWidgets.QMainWindow): if config[0].Runtime_Options__type_read: config[0].internal__load_data_style = config[0].Runtime_Options__type_read - # Respect command line overlay settings - if config[0].Runtime_Options__read_style_merge: - config[0].internal__load_data_overlay = config[0].Runtime_Options__read_style_merge - if config[0].Runtime_Options__source_merge: - config[0].internal__source_data_overlay = config[0].Runtime_Options__source_merge - if isinstance(config[0].Runtime_Options__merge_lists, bool): - config[0].internal__overlay_merge_lists = config[0].Runtime_Options__merge_lists - for style in config[0].internal__save_data_style: if style not in metadata_styles: config[0].internal__save_data_style.remove(style) for style in config[0].internal__load_data_style: if style not in metadata_styles: config[0].internal__load_data_style.remove(style) + self.save_data_styles: list[str] = config[0].internal__save_data_style self.load_data_styles: list[str] = config[0].internal__load_data_style @@ -2210,8 +2203,8 @@ class TaggerWindow(QtWidgets.QMainWindow): metadata = ca.read_metadata(style) md.overlay( metadata, - mode=self.config[0].internal__load_data_overlay, - merge_lists=self.config[0].internal__overlay_merge_lists, + mode=self.config[0].Metadata_Options__comic_merge, + merge_lists=self.config[0].Metadata_Options__comic_merge_lists, ) except Exception as e: error = e diff --git a/comictaggerlib/ui/settingswindow.ui b/comictaggerlib/ui/settingswindow.ui index 291a2eb..5ddb841 100644 --- a/comictaggerlib/ui/settingswindow.ui +++ b/comictaggerlib/ui/settingswindow.ui @@ -7,7 +7,7 @@ 0 0 703 - 597 + 615 @@ -619,12 +619,6 @@ One Publisher per line - - - 0 - 165 - - Merge Modes @@ -645,51 +639,105 @@ One Publisher per line 6 - - - The merge mode to use when reading multiple metadata styles from a single comic archive (ComicRack, ComicBookInfo, etc.) - - - Comic Merge Mode: - - - 6 - - - cbxOverlayReadStyle + + + Comic Merge + + + + + The merge mode to use when reading multiple metadata styles from a single comic archive (ComicRack, ComicBookInfo, etc.) + + + Merge Mode: + + + 6 + + + cbxOverlayReadStyle + + + + + + + true + + + + 0 + 0 + + + + The merge mode to use when reading multiple metadata styles from a comic archive (ComicRack, ComicBookInfo, etc.) + + + + + + + Merge lists (characters, tags, locations, etc.) together or the "new" list replaces the old + + + Merge Lists + + + + - - - The merge mode to use when fetching metadata from a Metadata Source (Comic Vine, Metron, GCD, etc.) - - - Metadata Merge Mode: - - - 6 - - - cbxOverlaySource + + + Metadata Merge + + + + + The merge mode to use when fetching metadata from a Metadata Source (Comic Vine, Metron, GCD, etc.) + + + Merge Mode: + + + 6 + + + cbxOverlaySource + + + + + + + + 0 + 0 + + + + The merge mode to use when fetching data from a Metadata Source (Comic Vine, Metron, GCD, etc.) + + + + + + + Merge lists (characters, tags, locations, etc.) together or the "new" list replaces the old + + + Merge Lists + + + + - - - - - 0 - 0 - - - - The merge mode to use when fetching data from a Metadata Source (Comic Vine, Metron, GCD, etc.) - - - - + @@ -709,12 +757,6 @@ One Publisher per line 200 - - QTabWidget::North - - - 0 - @@ -849,32 +891,6 @@ Example Merge: - - - - true - - - - 0 - 0 - - - - The merge mode to use when reading multiple metadata styles from a comic archive (ComicRack, ComicBookInfo, etc.) - - - - - - - Merge lists (characters, tags, locations, etc.) together or the "new" list replaces the old - - - Merge Lists - - -