"""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. import platform import os import sys from PyQt5 import QtCore, QtGui, QtWidgets, uic from .settings import ComicTaggerSettings from .comicvinecacher import ComicVineCacher from .comicvinetalker import ComicVineTalker from .imagefetcher import ImageFetcher from .filerenamer import FileRenamer from .genericmetadata import GenericMetadata from . import utils 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 """ class SettingsWindow(QtWidgets.QDialog): def __init__(self, parent, settings): super(SettingsWindow, self).__init__(parent) uic.loadUi(ComicTaggerSettings.getUIFile('settingswindow.ui'), self) self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.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.lower()) self.btnResetSettings.setText("Default " + self.name) nldtTip = ( """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(nldtTip) pblTip = ( """ The Publisher Blacklist 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.tePublisherBlacklist.setToolTip(pblTip) validator = QtGui.QIntValidator(1, 4, self) self.leIssueNumPadding.setValidator(validator) validator = QtGui.QIntValidator(0, 99, self) self.leNameLengthDeltaThresh.setValidator(validator) self.settingsToForm() self.btnBrowseRar.clicked.connect(self.selectRar) self.btnClearCache.clicked.connect(self.clearCache) self.btnResetSettings.clicked.connect(self.resetSettings) self.btnTestKey.clicked.connect(self.testAPIKey) self.btnTemplateHelp.clicked.connect(self.showTemplateHelp) def configRenamer(self): md = GenericMetadata() md.isEmpty = False md.tagOrigin = "testing" md.series = "series name" md.issue = "1" md.title = "issue title" md.publisher = "publisher" md.year = 1998 md.month = 4 md.day = 4 md.issueCount = 1 md.volume = 256 md.genre = "test" md.language = "en" # 2 letter iso code md.comments = "This is definitly a comic." # use same way as Summary in CIX md.volumeCount = 4096 md.criticalRating = "Worst Comic Ever" md.country = "US" md.alternateSeries = "None" md.alternateNumber = 4.4 md.alternateCount = 4444 md.imprint = 'imprint' md.notes = "This doesn't actually exist" md.webLink = "https://example.com/series name/1" md.format = "Box Set" md.manga = "Yes" md.blackAndWhite = False md.pageCount = 4 md.maturityRating = "Everyone" md.storyArc = "story" md.seriesGroup = "seriesGroup" md.scanInfo = "(lordwelch)" md.characters = "character 1, character 2" md.teams = "None" md.locations = "Earth, 444 B.C." md.credits = [dict({'role': 'Everything', 'person': 'author', 'primary': True})] md.tags = ["testing", "not real"] md.pages = [dict({'Image': '0', 'Type': 'Front Cover'}), dict({'Image': '1', 'Type': 'Story'})] # Some CoMet-only items md.price = 0.00 md.isVersionOf = "SERIES #1" md.rights = "None" md.identifier = "LW4444-Comic" md.lastMark = "0" md.coverImage = "https://example.com/series name/1/cover" self.renamer = FileRenamer(md) self.renamer.setTemplate(str(self.leRenameTemplate.text())) self.renamer.setIssueZeroPadding(self.settings.rename_issue_number_padding) self.renamer.setSmartCleanup(self.settings.rename_use_smart_string_cleanup) def settingsToForm(self): # 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.tePublisherBlacklist.setPlainText( self.settings.id_publisher_blacklist) if self.settings.check_for_new_version: self.cbxCheckForNewVersion.setCheckState(QtCore.Qt.Checked) if self.settings.parse_scan_info: self.cbxParseScanInfo.setCheckState(QtCore.Qt.Checked) if self.settings.use_series_start_as_volume: self.cbxUseSeriesStartAsVolume.setCheckState(QtCore.Qt.Checked) if self.settings.clear_form_before_populating_from_cv: self.cbxClearFormBeforePopulating.setCheckState(QtCore.Qt.Checked) if self.settings.remove_html_tables: self.cbxRemoveHtmlTables.setCheckState(QtCore.Qt.Checked) self.leKey.setText(str(self.settings.cv_api_key)) if self.settings.assume_lone_credit_is_primary: self.cbxAssumeLoneCreditIsPrimary.setCheckState(QtCore.Qt.Checked) if self.settings.copy_characters_to_tags: self.cbxCopyCharactersToTags.setCheckState(QtCore.Qt.Checked) if self.settings.copy_teams_to_tags: self.cbxCopyTeamsToTags.setCheckState(QtCore.Qt.Checked) if self.settings.copy_locations_to_tags: self.cbxCopyLocationsToTags.setCheckState(QtCore.Qt.Checked) if self.settings.copy_storyarcs_to_tags: self.cbxCopyStoryArcsToTags.setCheckState(QtCore.Qt.Checked) if self.settings.copy_notes_to_comments: self.cbxCopyNotesToComments.setCheckState(QtCore.Qt.Checked) if self.settings.copy_weblink_to_comments: self.cbxCopyWebLinkToComments.setCheckState(QtCore.Qt.Checked) if self.settings.apply_cbl_transform_on_cv_import: self.cbxApplyCBLTransformOnCVIMport.setCheckState( QtCore.Qt.Checked) if self.settings.apply_cbl_transform_on_bulk_operation: self.cbxApplyCBLTransformOnBatchOperation.setCheckState( QtCore.Qt.Checked) self.leRenameTemplate.setText(self.settings.rename_template) self.leIssueNumPadding.setText( str(self.settings.rename_issue_number_padding)) if self.settings.rename_use_smart_string_cleanup: self.cbxSmartCleanup.setCheckState(QtCore.Qt.Checked) if self.settings.rename_extension_based_on_archive: self.cbxChangeExtension.setCheckState(QtCore.Qt.Checked) if self.settings.rename_move_dir: self.cbxMoveFiles.setCheckState(QtCore.Qt.Checked) self.leDirectory.setText(self.settings.rename_dir) def accept(self): self.configRenamer() try: new_name = self.renamer.determineName('test.cbz') except Exception as e: QtWidgets.QMessageBox.critical(self, 'Invalid format string!', 'Your rename template is invalid!' '