"""A PyQT4 dialog to enter app settings""" # # Copyright 2012-2014 Anthony Beville # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import annotations import html import logging import os import pathlib import platform from PyQt5 import QtCore, QtGui, QtWidgets, uic from comicapi import utils from comicapi.genericmetadata import md_test from comictaggerlib.comiccacher import ComicCacher from comictaggerlib.comicvinetalker import ComicVineTalker from comictaggerlib.filerenamer import FileRenamer from comictaggerlib.imagefetcher import ImageFetcher from comictaggerlib.settings import ComicTaggerSettings logger = logging.getLogger(__name__) windowsRarHelp = """
To write to CBR/RAR archives, you will need to have the tools from WINRar installed. (ComicTagger only uses the command-line rar tool, which is free to use.)
""" linuxRarHelp = """To write to CBR/RAR archives, you will need to have the shareware rar tool from RARLab installed. Your package manager should have rar (e.g. "apt-get install rar"). If not, download it here, and install in your path.
""" macRarHelp = """To write to CBR/RAR archives, you will need the rar tool. The easiest way to get this is to install homebrew.
Once homebrew is installed, run: brew install caskroom/cask/rar """ template_tooltip = """ The template for the new filename. Uses python format strings https://docs.python.org/3/library/string.html#format-string-syntax Accepts the following variables: {is_empty} (boolean) {tag_origin} (string) {series} (string) {issue} (string) {title} (string) {publisher} (string) {month} (integer) {year} (integer) {day} (integer) {issue_count} (integer) {volume} (integer) {genre} (string) {language} (string) {comments} (string) {volume_count} (integer) {critical_rating} (float) {country} (string) {alternate_series} (string) {alternate_number} (string) {alternate_count} (integer) {imprint} (string) {notes} (string) {web_link} (string) {format} (string) {manga} (string) {black_and_white} (boolean) {page_count} (integer) {maturity_rating} (string) {story_arc} (string) {series_group} (string) {scan_info} (string) {characters} (string) {teams} (string) {locations} (string) {credits} (list of dict({'role': string, 'person': string, 'primary': boolean})) {writer} (string) {penciller} (string) {inker} (string) {colorist} (string) {letterer} (string) {cover artist} (string) {editor} (string) {tags} (list of str) {pages} (list of dict({'Image': string(int), 'Type': string, 'Bookmark': string, 'DoublePage': string})) CoMet-only items: {price} (float) {is_version_of} (string) {rights} (string) {identifier} (string) {last_mark} (string) {cover_image} (string) Examples: {series} {issue} ({year}) Spider-Geddon 1 (2018) {series} #{issue} - {title} Spider-Geddon #1 - New Players; Check In """ class SettingsWindow(QtWidgets.QDialog): def __init__(self, parent: QtWidgets.QWidget, settings: ComicTaggerSettings) -> None: super().__init__(parent) uic.loadUi(ComicTaggerSettings.get_ui_file("settingswindow.ui"), self) self.setWindowFlags( QtCore.Qt.WindowType(self.windowFlags() & ~QtCore.Qt.WindowType.WindowContextHelpButtonHint) ) self.settings = settings self.name = "Settings" if platform.system() == "Windows": self.lblRarHelp.setText(windowsRarHelp) elif platform.system() == "Linux": self.lblRarHelp.setText(linuxRarHelp) elif platform.system() == "Darwin": self.leRarExePath.setReadOnly(False) self.lblRarHelp.setText(macRarHelp) self.name = "Preferences" self.setWindowTitle("ComicTagger " + self.name) self.lblDefaultSettings.setText("Revert to default " + self.name.casefold()) self.btnResetSettings.setText("Default " + self.name) nldt_tip = """The Default Name Length Match Tolerance is for eliminating automatic search matches that are too long compared to your series name search. The higher it is, the more likely to have a good match, but each search will take longer and use more bandwidth. Too low, and only the very closest lexical matches will be explored.""" self.leNameLengthDeltaThresh.setToolTip(nldt_tip) pbl_tip = """ The Publisher Filter is for eliminating automatic matches to certain publishers that you know are incorrect. Useful for avoiding international re-prints with same covers or series names. Enter publisher names separated by commas. """ self.tePublisherFilter.setToolTip(pbl_tip) validator = QtGui.QIntValidator(1, 4, self) self.leIssueNumPadding.setValidator(validator) validator = QtGui.QIntValidator(0, 99, self) self.leNameLengthDeltaThresh.setValidator(validator) self.leRenameTemplate.setToolTip(f"{html.escape(template_tooltip)}") self.settings_to_form() self.rename_error: Exception | None = None self.rename_test() self.dir_test() self.btnBrowseRar.clicked.connect(self.select_rar) self.btnClearCache.clicked.connect(self.clear_cache) self.btnResetSettings.clicked.connect(self.reset_settings) self.btnTestKey.clicked.connect(self.test_api_key) self.btnTemplateHelp.clicked.connect(self.show_template_help) self.leRenameTemplate.textEdited.connect(self._rename_test) self.cbxMoveFiles.clicked.connect(self.rename_test) self.cbxMoveFiles.clicked.connect(self.dir_test) self.cbxRenameStrict.clicked.connect(self.rename_test) self.leDirectory.textEdited.connect(self.dir_test) self.cbxComplicatedParser.clicked.connect(self.switch_parser) def rename_test(self) -> None: self._rename_test(self.leRenameTemplate.text()) def dir_test(self) -> None: self.lblDir.setText( str(pathlib.Path(self.leDirectory.text().strip()).absolute()) if self.cbxMoveFiles.isChecked() else "" ) def _rename_test(self, template: str) -> None: fr = FileRenamer(md_test, platform="universal" if self.cbxRenameStrict.isChecked() else "auto") fr.move = self.cbxMoveFiles.isChecked() fr.set_template(template) fr.set_issue_zero_padding(int(self.leIssueNumPadding.text())) fr.set_smart_cleanup(self.cbxSmartCleanup.isChecked()) try: self.lblRenameTest.setText(fr.determine_name(".cbz")) self.rename_error = None except Exception as e: self.rename_error = e self.lblRenameTest.setText(str(e)) def switch_parser(self) -> None: complicated = self.cbxComplicatedParser.isChecked() self.cbxRemoveC2C.setEnabled(complicated) self.cbxRemoveFCBD.setEnabled(complicated) self.cbxRemovePublisher.setEnabled(complicated) def settings_to_form(self) -> None: # Copy values from settings to form self.leRarExePath.setText(self.settings.rar_exe_path) self.leNameLengthDeltaThresh.setText(str(self.settings.id_length_delta_thresh)) self.tePublisherFilter.setPlainText(self.settings.id_publisher_filter) self.cbxCheckForNewVersion.setChecked(self.settings.check_for_new_version) self.cbxComplicatedParser.setChecked(self.settings.complicated_parser) self.cbxRemoveC2C.setChecked(self.settings.remove_c2c) self.cbxRemoveFCBD.setChecked(self.settings.remove_fcbd) self.cbxRemovePublisher.setChecked(self.settings.remove_publisher) self.switch_parser() self.cbxUseSeriesStartAsVolume.setChecked(self.settings.use_series_start_as_volume) self.cbxClearFormBeforePopulating.setChecked(self.settings.clear_form_before_populating_from_cv) self.cbxRemoveHtmlTables.setChecked(self.settings.remove_html_tables) self.cbxUseFilter.setChecked(self.settings.always_use_publisher_filter) self.cbxSortByYear.setChecked(self.settings.sort_series_by_year) self.cbxExactMatches.setChecked(self.settings.exact_series_matches_first) self.leKey.setText(self.settings.cv_api_key) self.leURL.setText(self.settings.cv_url) self.cbxAssumeLoneCreditIsPrimary.setChecked(self.settings.assume_lone_credit_is_primary) self.cbxCopyCharactersToTags.setChecked(self.settings.copy_characters_to_tags) self.cbxCopyTeamsToTags.setChecked(self.settings.copy_teams_to_tags) self.cbxCopyLocationsToTags.setChecked(self.settings.copy_locations_to_tags) self.cbxCopyStoryArcsToTags.setChecked(self.settings.copy_storyarcs_to_tags) self.cbxCopyNotesToComments.setChecked(self.settings.copy_notes_to_comments) self.cbxCopyWebLinkToComments.setChecked(self.settings.copy_weblink_to_comments) self.cbxApplyCBLTransformOnCVIMport.setChecked(self.settings.apply_cbl_transform_on_cv_import) self.cbxApplyCBLTransformOnBatchOperation.setChecked(self.settings.apply_cbl_transform_on_bulk_operation) self.leRenameTemplate.setText(self.settings.rename_template) self.leIssueNumPadding.setText(str(self.settings.rename_issue_number_padding)) self.cbxSmartCleanup.setChecked(self.settings.rename_use_smart_string_cleanup) self.cbxChangeExtension.setChecked(self.settings.rename_extension_based_on_archive) self.cbxMoveFiles.setChecked(self.settings.rename_move_dir) self.leDirectory.setText(self.settings.rename_dir) self.cbxRenameStrict.setChecked(self.settings.rename_strict) def accept(self) -> None: self.rename_test() if self.rename_error is not None: QtWidgets.QMessageBox.critical( self, "Invalid format string!", "Your rename template is invalid!" f"