2015-02-21 18:30:32 -08:00
|
|
|
"""A PyQT4 dialog to enter app settings"""
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# Copyright 2012-2014 Anthony Beville
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# 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
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2015-02-21 18:30:32 -08:00
|
|
|
# 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.
|
2012-11-12 16:12:43 -08:00
|
|
|
|
|
|
|
import platform
|
|
|
|
import os
|
2018-09-19 13:05:39 -07:00
|
|
|
import sys
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets, uic
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
from .settings import ComicTaggerSettings
|
|
|
|
from .comicvinecacher import ComicVineCacher
|
|
|
|
from .comicvinetalker import ComicVineTalker
|
|
|
|
from .imagefetcher import ImageFetcher
|
|
|
|
from . import utils
|
2012-11-12 16:12:43 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
windowsRarHelp = """
|
2018-09-19 13:05:39 -07:00
|
|
|
<html><head/><body><p>To write to CBR/RAR archives,
|
2015-02-12 14:57:46 -08:00
|
|
|
you will need to have the tools from
|
2018-09-19 13:05:39 -07:00
|
|
|
<span style=" text-decoration: underline; color:#0000ff;">
|
|
|
|
<a href="http://www.win-rar.com/download.html">WINRar</a></span>
|
|
|
|
installed. (ComicTagger only uses the command-line rar tool,
|
|
|
|
which is free to use.)</p></body></html>
|
2012-11-12 16:12:43 -08:00
|
|
|
"""
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
linuxRarHelp = """
|
2018-09-19 13:05:39 -07:00
|
|
|
<html><head/><body><p>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
|
|
|
|
<span style=" text-decoration: underline; color:#0000ff;">
|
|
|
|
<a href="https://www.rarlab.com/download.htm">here</a></span>,
|
|
|
|
and install in your path. </p></body></html>
|
2012-11-12 16:12:43 -08:00
|
|
|
"""
|
2018-09-19 13:05:39 -07:00
|
|
|
|
2012-11-12 16:12:43 -08:00
|
|
|
macRarHelp = """
|
2018-09-19 13:05:39 -07:00
|
|
|
<html><head/><body><p>To write to CBR/RAR archives,
|
|
|
|
you will need the rar tool. The easiest way to get this is
|
|
|
|
to install <span style=" text-decoration: underline; color:#0000ff;">
|
|
|
|
<a href="https://brew.sh/">homebrew</a></span>.
|
|
|
|
</p>Once homebrew is installed, run: <b>brew install caskroom/cask/rar</b></body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
class SettingsWindow(QtWidgets.QDialog):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def __init__(self, parent, settings):
|
2015-02-12 14:57:46 -08:00
|
|
|
super(SettingsWindow, self).__init__(parent)
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
uic.loadUi(ComicTaggerSettings.getUIFile('settingswindow.ui'), self)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.setWindowFlags(self.windowFlags() &
|
2015-02-15 02:44:00 -08:00
|
|
|
~QtCore.Qt.WindowContextHelpButtonHint)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.settings = settings
|
2019-10-05 14:59:52 -07:00
|
|
|
self.name = "Settings"
|
2018-09-19 13:05:39 -07:00
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
if platform.system() == "Windows":
|
2015-02-13 15:08:07 -08:00
|
|
|
self.lblRarHelp.setText(windowsRarHelp)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
elif platform.system() == "Linux":
|
2015-02-13 15:08:07 -08:00
|
|
|
self.lblRarHelp.setText(linuxRarHelp)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
elif platform.system() == "Darwin":
|
2018-09-19 13:05:39 -07:00
|
|
|
self.leRarExePath.setReadOnly(False)
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
self.lblRarHelp.setText(macRarHelp)
|
2015-02-12 14:57:46 -08:00
|
|
|
self.name = "Preferences"
|
|
|
|
|
|
|
|
self.setWindowTitle("ComicTagger " + self.name)
|
2015-02-15 02:44:00 -08:00
|
|
|
self.lblDefaultSettings.setText(
|
|
|
|
"Revert to default " + self.name.lower())
|
2015-02-13 15:08:07 -08:00
|
|
|
self.btnResetSettings.setText("Default " + self.name)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
nldtTip = (
|
2015-02-21 18:30:32 -08:00
|
|
|
"""<html>The <b>Default Name Length Match Tolerance</b> is for eliminating automatic
|
2015-02-12 14:57:46 -08:00
|
|
|
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
|
2015-02-13 15:08:07 -08:00
|
|
|
explored.</html>""")
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.leNameLengthDeltaThresh.setToolTip(nldtTip)
|
|
|
|
|
|
|
|
pblTip = (
|
|
|
|
"""<html>
|
2022-01-22 15:00:22 -08:00
|
|
|
The <b>Publisher Filter</b> is for eliminating automatic matches to certain publishers
|
2015-02-12 14:57:46 -08:00
|
|
|
that you know are incorrect. Useful for avoiding international re-prints with same
|
|
|
|
covers or series names. Enter publisher names separated by commas.
|
|
|
|
</html>"""
|
2015-02-15 02:44:00 -08:00
|
|
|
)
|
2022-01-22 15:00:22 -08:00
|
|
|
self.tePublisherFilter.setToolTip(pblTip)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def settingsToForm(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
# Copy values from settings to form
|
2015-02-13 15:08:07 -08:00
|
|
|
self.leRarExePath.setText(self.settings.rar_exe_path)
|
2015-02-15 02:44:00 -08:00
|
|
|
self.leNameLengthDeltaThresh.setText(
|
|
|
|
str(self.settings.id_length_delta_thresh))
|
2022-01-22 15:00:22 -08:00
|
|
|
self.tePublisherFilter.setPlainText(
|
|
|
|
self.settings.id_publisher_filter)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if self.settings.check_for_new_version:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCheckForNewVersion.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if self.settings.parse_scan_info:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxParseScanInfo.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if self.settings.use_series_start_as_volume:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxUseSeriesStartAsVolume.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.clear_form_before_populating_from_cv:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxClearFormBeforePopulating.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.remove_html_tables:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxRemoveHtmlTables.setCheckState(QtCore.Qt.Checked)
|
2022-01-22 14:40:45 -08:00
|
|
|
|
2022-01-22 15:00:22 -08:00
|
|
|
if self.settings.always_use_publisher_filter:
|
|
|
|
self.cbxUseFilter.setCheckState(QtCore.Qt.Checked)
|
2022-01-22 14:40:45 -08:00
|
|
|
if self.settings.sort_series_by_year:
|
|
|
|
self.cbxSortByYear.setCheckState(QtCore.Qt.Checked)
|
|
|
|
if self.settings.exact_series_matches_first:
|
|
|
|
self.cbxExactMatches.setCheckState(QtCore.Qt.Checked)
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
self.leKey.setText(str(self.settings.cv_api_key))
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if self.settings.assume_lone_credit_is_primary:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxAssumeLoneCreditIsPrimary.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.copy_characters_to_tags:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCopyCharactersToTags.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.copy_teams_to_tags:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCopyTeamsToTags.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.copy_locations_to_tags:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCopyLocationsToTags.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.copy_storyarcs_to_tags:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCopyStoryArcsToTags.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.copy_notes_to_comments:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCopyNotesToComments.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.copy_weblink_to_comments:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxCopyWebLinkToComments.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.apply_cbl_transform_on_cv_import:
|
2015-02-15 02:44:00 -08:00
|
|
|
self.cbxApplyCBLTransformOnCVIMport.setCheckState(
|
|
|
|
QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.apply_cbl_transform_on_bulk_operation:
|
2015-02-15 02:44:00 -08:00
|
|
|
self.cbxApplyCBLTransformOnBatchOperation.setCheckState(
|
|
|
|
QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
self.leRenameTemplate.setText(self.settings.rename_template)
|
2015-02-15 02:44:00 -08:00
|
|
|
self.leIssueNumPadding.setText(
|
|
|
|
str(self.settings.rename_issue_number_padding))
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.rename_use_smart_string_cleanup:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxSmartCleanup.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
if self.settings.rename_extension_based_on_archive:
|
2015-02-13 15:08:07 -08:00
|
|
|
self.cbxChangeExtension.setCheckState(QtCore.Qt.Checked)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def accept(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
# Copy values from form to settings and save
|
|
|
|
self.settings.rar_exe_path = str(self.leRarExePath.text())
|
2018-09-19 13:05:39 -07:00
|
|
|
|
|
|
|
# make sure rar program is now in the path for the rar class
|
|
|
|
if self.settings.rar_exe_path:
|
|
|
|
utils.addtopath(os.path.dirname(self.settings.rar_exe_path))
|
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
if not str(self.leNameLengthDeltaThresh.text()).isdigit():
|
|
|
|
self.leNameLengthDeltaThresh.setText("0")
|
|
|
|
|
|
|
|
if not str(self.leIssueNumPadding.text()).isdigit():
|
|
|
|
self.leIssueNumPadding.setText("0")
|
|
|
|
|
|
|
|
self.settings.check_for_new_version = self.cbxCheckForNewVersion.isChecked()
|
|
|
|
|
2015-02-15 02:44:00 -08:00
|
|
|
self.settings.id_length_delta_thresh = int(
|
|
|
|
self.leNameLengthDeltaThresh.text())
|
2022-01-22 15:00:22 -08:00
|
|
|
self.settings.id_publisher_filter = str(
|
|
|
|
self.tePublisherFilter.toPlainText())
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
self.settings.parse_scan_info = self.cbxParseScanInfo.isChecked()
|
|
|
|
|
|
|
|
self.settings.use_series_start_as_volume = self.cbxUseSeriesStartAsVolume.isChecked()
|
|
|
|
self.settings.clear_form_before_populating_from_cv = self.cbxClearFormBeforePopulating.isChecked()
|
|
|
|
self.settings.remove_html_tables = self.cbxRemoveHtmlTables.isChecked()
|
2022-01-22 14:40:45 -08:00
|
|
|
|
2022-01-22 15:00:22 -08:00
|
|
|
self.settings.always_use_publisher_filter = self.cbxUseFilter.isChecked()
|
2022-01-22 14:40:45 -08:00
|
|
|
self.settings.sort_series_by_year = self.cbxSortByYear.isChecked()
|
|
|
|
self.settings.exact_series_matches_first = self.cbxExactMatches.isChecked()
|
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
self.settings.cv_api_key = str(self.leKey.text())
|
|
|
|
ComicVineTalker.api_key = self.settings.cv_api_key.strip()
|
2015-02-12 14:57:46 -08:00
|
|
|
self.settings.assume_lone_credit_is_primary = self.cbxAssumeLoneCreditIsPrimary.isChecked()
|
|
|
|
self.settings.copy_characters_to_tags = self.cbxCopyCharactersToTags.isChecked()
|
|
|
|
self.settings.copy_teams_to_tags = self.cbxCopyTeamsToTags.isChecked()
|
|
|
|
self.settings.copy_locations_to_tags = self.cbxCopyLocationsToTags.isChecked()
|
|
|
|
self.settings.copy_storyarcs_to_tags = self.cbxCopyStoryArcsToTags.isChecked()
|
|
|
|
self.settings.copy_notes_to_comments = self.cbxCopyNotesToComments.isChecked()
|
|
|
|
self.settings.copy_weblink_to_comments = self.cbxCopyWebLinkToComments.isChecked()
|
|
|
|
self.settings.apply_cbl_transform_on_cv_import = self.cbxApplyCBLTransformOnCVIMport.isChecked()
|
|
|
|
self.settings.apply_cbl_transform_on_bulk_operation = self.cbxApplyCBLTransformOnBatchOperation.isChecked()
|
|
|
|
|
|
|
|
self.settings.rename_template = str(self.leRenameTemplate.text())
|
2015-02-15 02:44:00 -08:00
|
|
|
self.settings.rename_issue_number_padding = int(
|
|
|
|
self.leIssueNumPadding.text())
|
2015-02-12 14:57:46 -08:00
|
|
|
self.settings.rename_use_smart_string_cleanup = self.cbxSmartCleanup.isChecked()
|
|
|
|
self.settings.rename_extension_based_on_archive = self.cbxChangeExtension.isChecked()
|
|
|
|
|
|
|
|
self.settings.save()
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QDialog.accept(self)
|
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def selectRar(self):
|
|
|
|
self.selectFile(self.leRarExePath, "RAR")
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def clearCache(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
ImageFetcher().clearCache()
|
2015-02-13 15:08:07 -08:00
|
|
|
ComicVineCacher().clearCache()
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QMessageBox.information(
|
2015-02-15 02:44:00 -08:00
|
|
|
self, self.name, "Cache has been cleared.")
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def testAPIKey(self):
|
2018-09-19 13:05:39 -07:00
|
|
|
if ComicVineTalker().testKey(str(self.leKey.text()).strip()):
|
|
|
|
QtWidgets.QMessageBox.information(
|
2015-02-15 02:44:00 -08:00
|
|
|
self, "API Key Test", "Key is valid!")
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QMessageBox.warning(
|
2015-02-15 02:44:00 -08:00
|
|
|
self, "API Key Test", "Key is NOT valid.")
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def resetSettings(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
self.settings.reset()
|
|
|
|
self.settingsToForm()
|
2018-09-19 13:05:39 -07:00
|
|
|
QtWidgets.QMessageBox.information(
|
2015-02-15 03:55:04 -08:00
|
|
|
self,
|
|
|
|
self.name,
|
|
|
|
self.name +
|
|
|
|
" have been returned to default values.")
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def selectFile(self, control, name):
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2018-09-19 13:05:39 -07:00
|
|
|
dialog = QtWidgets.QFileDialog(self)
|
|
|
|
dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile)
|
2015-02-12 14:57:46 -08:00
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
if name == "RAR":
|
2015-02-15 02:44:00 -08:00
|
|
|
filter = self.tr("Rar Program (Rar.exe)")
|
2015-02-12 14:57:46 -08:00
|
|
|
else:
|
2018-09-19 13:05:39 -07:00
|
|
|
filter = self.tr("Libraries (*.dll)")
|
2015-02-12 14:57:46 -08:00
|
|
|
dialog.setNameFilter(filter)
|
|
|
|
else:
|
2015-02-15 02:44:00 -08:00
|
|
|
# QtCore.QDir.Executable | QtCore.QDir.Files)
|
|
|
|
dialog.setFilter(QtCore.QDir.Files)
|
2015-02-12 14:57:46 -08:00
|
|
|
pass
|
|
|
|
|
|
|
|
dialog.setDirectory(os.path.dirname(str(control.text())))
|
2018-09-19 13:05:39 -07:00
|
|
|
if name == "RAR":
|
|
|
|
dialog.setWindowTitle("Find " + name + " program")
|
|
|
|
else:
|
|
|
|
dialog.setWindowTitle("Find " + name + " library")
|
|
|
|
|
2015-02-12 14:57:46 -08:00
|
|
|
if (dialog.exec_()):
|
|
|
|
fileList = dialog.selectedFiles()
|
2015-02-13 15:08:07 -08:00
|
|
|
control.setText(str(fileList[0]))
|
2015-02-12 14:57:46 -08:00
|
|
|
|
2015-02-13 15:08:07 -08:00
|
|
|
def showRenameTab(self):
|
2015-02-12 14:57:46 -08:00
|
|
|
self.tabWidget.setCurrentIndex(5)
|