Fix saving merge settings

This commit is contained in:
Timmy Welch 2024-06-06 20:41:21 -07:00
parent 0457e19913
commit 0198eb9e2b
9 changed files with 153 additions and 141 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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,

View File

@ -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:

View File

@ -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):

View File

@ -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"

View File

@ -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()

View File

@ -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

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>703</width>
<height>597</height>
<height>615</height>
</rect>
</property>
<property name="windowTitle">
@ -619,12 +619,6 @@ One Publisher per line</string>
</item>
<item row="4" column="0">
<widget class="QGroupBox" name="groupBox_6">
<property name="minimumSize">
<size>
<width>0</width>
<height>165</height>
</size>
</property>
<property name="title">
<string>Merge Modes</string>
</property>
@ -645,51 +639,105 @@ One Publisher per line</string>
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lblOverlayReadStyle">
<property name="toolTip">
<string>The merge mode to use when reading multiple metadata styles from a single comic archive (ComicRack, ComicBookInfo, etc.)</string>
</property>
<property name="text">
<string>Comic Merge Mode:</string>
</property>
<property name="margin">
<number>6</number>
</property>
<property name="buddy">
<cstring>cbxOverlayReadStyle</cstring>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Comic Merge</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblOverlayComic">
<property name="toolTip">
<string>The merge mode to use when reading multiple metadata styles from a single comic archive (ComicRack, ComicBookInfo, etc.)</string>
</property>
<property name="text">
<string>Merge Mode:</string>
</property>
<property name="margin">
<number>6</number>
</property>
<property name="buddy">
<cstring>cbxOverlayReadStyle</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbMergeModeComic">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The merge mode to use when reading multiple metadata styles from a comic archive (ComicRack, ComicBookInfo, etc.)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="cbxMergeListsComic">
<property name="toolTip">
<string>Merge lists (characters, tags, locations, etc.) together or the &quot;new&quot; list replaces the old</string>
</property>
<property name="text">
<string>Merge Lists</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblOverlaySource">
<property name="toolTip">
<string>The merge mode to use when fetching metadata from a Metadata Source (Comic Vine, Metron, GCD, etc.)</string>
</property>
<property name="text">
<string>Metadata Merge Mode:</string>
</property>
<property name="margin">
<number>6</number>
</property>
<property name="buddy">
<cstring>cbxOverlaySource</cstring>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Metadata Merge</string>
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="lblOverlayMetadata">
<property name="toolTip">
<string>The merge mode to use when fetching metadata from a Metadata Source (Comic Vine, Metron, GCD, etc.)</string>
</property>
<property name="text">
<string>Merge Mode:</string>
</property>
<property name="margin">
<number>6</number>
</property>
<property name="buddy">
<cstring>cbxOverlaySource</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbMergeModeMetadata">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The merge mode to use when fetching data from a Metadata Source (Comic Vine, Metron, GCD, etc.)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="cbxMergeListsMetadata">
<property name="toolTip">
<string>Merge lists (characters, tags, locations, etc.) together or the &quot;new&quot; list replaces the old</string>
</property>
<property name="text">
<string>Merge Lists</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbxOverlaySource">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The merge mode to use when fetching data from a Metadata Source (Comic Vine, Metron, GCD, etc.)</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<item row="0" column="2" rowspan="2">
<widget class="QTabWidget" name="tabWidgetOverlay">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
@ -709,12 +757,6 @@ One Publisher per line</string>
<height>200</height>
</size>
</property>
<property name="tabPosition">
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tOverlay">
<property name="maximumSize">
<size>
@ -849,32 +891,6 @@ Example Merge:
</widget>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbxOverlayReadStyle">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The merge mode to use when reading multiple metadata styles from a comic archive (ComicRack, ComicBookInfo, etc.)</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="cbxOverlayMergeLists">
<property name="toolTip">
<string>Merge lists (characters, tags, locations, etc.) together or the &quot;new&quot; list replaces the old</string>
</property>
<property name="text">
<string>Merge Lists</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>