From 9ed3ada810af5e65d32c2f9b816846585c7c42f5 Mon Sep 17 00:00:00 2001 From: darodi <4682830+darodi@users.noreply.github.com> Date: Sun, 11 Dec 2022 19:23:43 +0100 Subject: [PATCH] Adding a switch on GUI interface in order to control cropping options (#19) --- CHANGELOG.md | 3 ++ gui/KCC.ui | 91 +++++++++++++++++++++++++------- kindlecomicconverter/KCC_gui.py | 28 +++++++++- kindlecomicconverter/KCC_ui.py | 46 ++++++++++++---- kindlecomicconverter/__init__.py | 2 +- 5 files changed, 137 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53ed146a..447b0940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +#### 5.5.3b15: +* Adding a switch on GUI interface in order to control cropping options [darodi/kcc#18](https://github.com/darodi/kcc/issues/18), thanks [@darodi](https://github.com/darodi) + #### 5.5.3b14: * profiles: add Kindle11 and Kindle Scribe [darodi/kcc#16](https://github.com/darodi/kcc/issues/16), thanks [@darodi](https://github.com/darodi) * Update with new Kobo models [darodi/kcc#15](https://github.com/darodi/kcc/issues/15), thanks [@lennie420](https://github.com/lennie420) diff --git a/gui/KCC.ui b/gui/KCC.ui index 861046b4..afc934d8 100644 --- a/gui/KCC.ui +++ b/gui/KCC.ui @@ -22,7 +22,7 @@ 5 - + @@ -139,16 +139,6 @@ - - - - <html><head/><body><p style='white-space:pre'>Do not process any image, ignore profil and processing options</p></body></html> - - - Disable processing - - - @@ -165,13 +155,36 @@ - <html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Unchecked - 1x4<br/></span>Keep format 1x4 panels strips.</p><p><span style=" font-weight:600; text-decoration: underline;">Checked - 2x2<br/></span>Turn 1x4 strips to 2x2 to maximize screen usage.</p></body></html> + <html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Unchecked - 1x4<br/></span>Keep format 1x4 panels strips.</p><p><span style=" font-weight:600; text-decoration: underline;">Checked - 2x2<br/></span>Turn 1x4 strips to 2x2 to maximize screen usage.</p></body></html> 1x4 to 2x2 strips + + + + <html><head/><body><p><span style=" font-weight:600; text-decoration: underline;">Unchecked - Disabled</span></p><p>Disabled</p><p><span style=" font-weight:600; text-decoration: underline;">Indeterminate - Margins<br/></span>Margins</p><p><span style=" font-weight:600; text-decoration: underline;">Checked - Margins + page numbers<br/></span>Margins +page numbers</p></body></html> + + + Cropping mode + + + true + + + + + + + <html><head/><body><p style='white-space:pre'>Do not process any image, ignore profil and processing options</p></body></html> + + + Disable processing + + + @@ -216,6 +229,47 @@ + + + + false + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Cropping power: + + + + + + + 10 + + + 1 + + + Qt::Horizontal + + + + + + @@ -288,9 +342,6 @@ <html><head/><body><p style='white-space:pre'>Target device.</p></body></html> - - QComboBox::AdjustToMinimumContentsLength - @@ -304,9 +355,6 @@ <html><head/><body><p style='white-space:pre'>Output format.</p></body></html> - - QComboBox::AdjustToMinimumContentsLength - @@ -319,7 +367,6 @@ - 75 true @@ -442,7 +489,6 @@ - 75 true @@ -551,12 +597,17 @@ borderBox outputSplit colorBox + croppingBox + mozJpegBox + maximizeStrips + disableProcessingBox editorButton wikiButton jobList gammaSlider widthBox heightBox + croppingPowerSlider diff --git a/kindlecomicconverter/KCC_gui.py b/kindlecomicconverter/KCC_gui.py index 7ae1ee08..14b459ca 100644 --- a/kindlecomicconverter/KCC_gui.py +++ b/kindlecomicconverter/KCC_gui.py @@ -278,6 +278,9 @@ def run(self): options.upscale = True if GUI.gammaBox.isChecked() and float(GUI.gammaValue) > 0.09: options.gamma = float(GUI.gammaValue) + options.cropping = GUI.croppingBox.checkState() + if GUI.croppingBox.checkState() >= 1: + options.croppingp = float(GUI.croppingPowerValue) if GUI.borderBox.checkState() == 1: options.white_borders = True elif GUI.borderBox.checkState() == 2: @@ -609,6 +612,13 @@ def togglegammaBox(self, value): if self.currentMode != 3: self.modeChange(1) + def togglecroppingBox(self, value): + if value: + GUI.croppingWidget.setVisible(True) + else: + GUI.croppingWidget.setVisible(False) + self.changeCroppingPower(100) # 1.0 + def togglewebtoonBox(self, value): if value: GUI.qualityBox.setEnabled(False) @@ -649,6 +659,13 @@ def changeGamma(self, value): GUI.gammaSlider.setValue(valueRaw) self.gammaValue = value + def changeCroppingPower(self, value): + valueRaw = int(5 * round(float(value) / 5)) + value = '%.2f' % (float(valueRaw) / 100) + GUI.croppingPowerLabel.setText('Cropping Power: ' + str(value)) + GUI.croppingPowerSlider.setValue(valueRaw) + self.croppingPowerValue = value + def changeDevice(self): profile = GUI.profiles[str(GUI.deviceBox.currentText())] if profile['ForceExpert']: @@ -794,6 +811,8 @@ def saveSettings(self, event): 'rotateBox': GUI.rotateBox.checkState(), 'qualityBox': GUI.qualityBox.checkState(), 'gammaBox': GUI.gammaBox.checkState(), + 'croppingBox': GUI.croppingBox.checkState(), + 'croppingPowerSlider': float(self.croppingPowerValue) * 100, 'upscaleBox': GUI.upscaleBox.checkState(), 'borderBox': GUI.borderBox.checkState(), 'webtoonBox': GUI.webtoonBox.checkState(), @@ -896,7 +915,7 @@ def __init__(self, kccapp, kccwindow): self.currentFormat = self.settings.value('currentFormat', 0, type=int) self.startNumber = self.settings.value('startNumber', 0, type=int) self.windowSize = self.settings.value('windowSize', '0x0', type=str) - self.options = self.settings.value('options', {'gammaSlider': 0}) + self.options = self.settings.value('options', {'gammaSlider': 0, 'croppingBox': 2, 'croppingPowerSlider': 100}) self.worker = WorkerThread() self.versionCheck = VersionThread() self.progress = ProgressThread() @@ -905,6 +924,7 @@ def __init__(self, kccapp, kccwindow): self.needClean = True self.kindleGen = False self.gammaValue = 1.0 + self.croppingPowerValue = 1.0 self.currentMode = 1 self.targetDirectory = '' self.sentry = Client(release=__version__) @@ -1063,6 +1083,8 @@ def __init__(self, kccapp, kccwindow): GUI.convertButton.clicked.connect(self.convertStart) GUI.gammaSlider.valueChanged.connect(self.changeGamma) GUI.gammaBox.stateChanged.connect(self.togglegammaBox) + GUI.croppingBox.stateChanged.connect(self.togglecroppingBox) + GUI.croppingPowerSlider.valueChanged.connect(self.changeCroppingPower) GUI.webtoonBox.stateChanged.connect(self.togglewebtoonBox) GUI.qualityBox.stateChanged.connect(self.togglequalityBox) GUI.deviceBox.activated.connect(self.changeDevice) @@ -1111,6 +1133,10 @@ def __init__(self, kccapp, kccwindow): if GUI.gammaSlider.isEnabled(): GUI.gammaSlider.setValue(int(self.options[option])) self.changeGamma(int(self.options[option])) + elif str(option) == "croppingPowerSlider": + if GUI.croppingPowerSlider.isEnabled(): + GUI.croppingPowerSlider.setValue(int(self.options[option])) + self.changeCroppingPower(int(self.options[option])) else: try: if eval('GUI.' + str(option)).isEnabled(): diff --git a/kindlecomicconverter/KCC_ui.py b/kindlecomicconverter/KCC_ui.py index b9f1b8c3..66b2d173 100644 --- a/kindlecomicconverter/KCC_ui.py +++ b/kindlecomicconverter/KCC_ui.py @@ -59,9 +59,6 @@ def setupUi(self, mainWindow): self.qualityBox.setTristate(True) self.qualityBox.setObjectName("qualityBox") self.gridLayout_2.addWidget(self.qualityBox, 0, 2, 1, 1) - self.disableProcessingBox = QtWidgets.QCheckBox(self.optionWidget) - self.disableProcessingBox.setObjectName("disableProcessingBox") - self.gridLayout_2.addWidget(self.disableProcessingBox, 3, 2, 1, 1) self.mozJpegBox = QtWidgets.QCheckBox(self.optionWidget) self.mozJpegBox.setTristate(True) self.mozJpegBox.setObjectName("mozJpegBox") @@ -69,7 +66,14 @@ def setupUi(self, mainWindow): self.maximizeStrips = QtWidgets.QCheckBox(self.optionWidget) self.maximizeStrips.setObjectName("maximizeStrips") self.gridLayout_2.addWidget(self.maximizeStrips, 3, 1, 1, 1) - self.gridLayout.addWidget(self.optionWidget, 4, 0, 1, 2) + self.croppingBox = QtWidgets.QCheckBox(self.optionWidget) + self.croppingBox.setTristate(True) + self.croppingBox.setObjectName("croppingBox") + self.gridLayout_2.addWidget(self.croppingBox, 3, 2, 1, 1) + self.disableProcessingBox = QtWidgets.QCheckBox(self.optionWidget) + self.disableProcessingBox.setObjectName("disableProcessingBox") + self.gridLayout_2.addWidget(self.disableProcessingBox, 4, 2, 1, 1) + self.gridLayout.addWidget(self.optionWidget, 5, 0, 1, 2) self.gammaWidget = QtWidgets.QWidget(self.centralWidget) self.gammaWidget.setVisible(False) self.gammaWidget.setObjectName("gammaWidget") @@ -86,6 +90,22 @@ def setupUi(self, mainWindow): self.gammaSlider.setObjectName("gammaSlider") self.horizontalLayout_2.addWidget(self.gammaSlider) self.gridLayout.addWidget(self.gammaWidget, 6, 0, 1, 2) + self.croppingWidget = QtWidgets.QWidget(self.centralWidget) + self.croppingWidget.setVisible(False) + self.croppingWidget.setObjectName("croppingWidget") + self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.croppingWidget) + self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0) + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.croppingPowerLabel = QtWidgets.QLabel(self.croppingWidget) + self.croppingPowerLabel.setObjectName("croppingPowerLabel") + self.horizontalLayout_3.addWidget(self.croppingPowerLabel) + self.croppingPowerSlider = QtWidgets.QSlider(self.croppingWidget) + self.croppingPowerSlider.setMaximum(200) + self.croppingPowerSlider.setSingleStep(1) + self.croppingPowerSlider.setOrientation(QtCore.Qt.Horizontal) + self.croppingPowerSlider.setObjectName("croppingPowerSlider") + self.horizontalLayout_3.addWidget(self.croppingPowerSlider) + self.gridLayout.addWidget(self.croppingWidget, 8, 0, 1, 2) self.buttonWidget = QtWidgets.QWidget(self.centralWidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) @@ -112,19 +132,16 @@ def setupUi(self, mainWindow): self.gridLayout_4.addWidget(self.fileButton, 0, 3, 1, 1) self.deviceBox = QtWidgets.QComboBox(self.buttonWidget) self.deviceBox.setMinimumSize(QtCore.QSize(0, 28)) - self.deviceBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToMinimumContentsLength) self.deviceBox.setObjectName("deviceBox") self.gridLayout_4.addWidget(self.deviceBox, 1, 0, 1, 1) self.formatBox = QtWidgets.QComboBox(self.buttonWidget) self.formatBox.setMinimumSize(QtCore.QSize(0, 28)) - self.formatBox.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToMinimumContentsLength) self.formatBox.setObjectName("formatBox") self.gridLayout_4.addWidget(self.formatBox, 1, 3, 1, 1) self.convertButton = QtWidgets.QPushButton(self.buttonWidget) self.convertButton.setMinimumSize(QtCore.QSize(0, 30)) font = QtGui.QFont() font.setBold(True) - font.setWeight(75) self.convertButton.setFont(font) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/Other/icons/convert.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) @@ -176,7 +193,6 @@ def setupUi(self, mainWindow): self.progressBar.setMinimumSize(QtCore.QSize(0, 30)) font = QtGui.QFont() font.setBold(True) - font.setWeight(75) self.progressBar.setFont(font) self.progressBar.setVisible(False) self.progressBar.setAlignment(QtCore.Qt.AlignJustify|QtCore.Qt.AlignVCenter) @@ -235,12 +251,17 @@ def setupUi(self, mainWindow): mainWindow.setTabOrder(self.gammaBox, self.borderBox) mainWindow.setTabOrder(self.borderBox, self.outputSplit) mainWindow.setTabOrder(self.outputSplit, self.colorBox) - mainWindow.setTabOrder(self.colorBox, self.editorButton) + mainWindow.setTabOrder(self.colorBox, self.croppingBox) + mainWindow.setTabOrder(self.croppingBox, self.mozJpegBox) + mainWindow.setTabOrder(self.mozJpegBox, self.maximizeStrips) + mainWindow.setTabOrder(self.maximizeStrips, self.disableProcessingBox) + mainWindow.setTabOrder(self.disableProcessingBox, self.editorButton) mainWindow.setTabOrder(self.editorButton, self.wikiButton) mainWindow.setTabOrder(self.wikiButton, self.jobList) mainWindow.setTabOrder(self.jobList, self.gammaSlider) mainWindow.setTabOrder(self.gammaSlider, self.widthBox) mainWindow.setTabOrder(self.widthBox, self.heightBox) + mainWindow.setTabOrder(self.heightBox, self.croppingPowerSlider) def retranslateUi(self, mainWindow): _translate = QtCore.QCoreApplication.translate @@ -263,13 +284,16 @@ def retranslateUi(self, mainWindow): self.mangaBox.setText(_translate("mainWindow", "Manga mode")) self.qualityBox.setToolTip(_translate("mainWindow", "

Unchecked - 4 panels
Zoom each corner separately.

Indeterminate - 2 panels
Zoom only the top and bottom of the page.

Checked - 4 high-quality panels
Zoom each corner separately. Try to increase the quality of magnification. Check wiki for more details.

")) self.qualityBox.setText(_translate("mainWindow", "Panel View 4/2/HQ")) - self.disableProcessingBox.setToolTip(_translate("mainWindow", "

Do not process any image, ignore profil and processing options

")) - self.disableProcessingBox.setText(_translate("mainWindow", "Disable processing")) self.mozJpegBox.setToolTip(_translate("mainWindow", "

Unchecked - JPEG
Use JPEG files

Indeterminate - force PNG
Create PNG files instead JPEG

Checked - mozJpeg
10-20% smaller JPEG file, with the same image quality, but processing time multiplied by 2

")) self.mozJpegBox.setText(_translate("mainWindow", "JPEG/PNG/mozJpeg")) self.maximizeStrips.setToolTip(_translate("mainWindow", "

Unchecked - 1x4
Keep format 1x4 panels strips.

Checked - 2x2
Turn 1x4 strips to 2x2 to maximize screen usage.

")) self.maximizeStrips.setText(_translate("mainWindow", "1x4 to 2x2 strips")) + self.croppingBox.setToolTip(_translate("mainWindow", "

Unchecked - Disabled

Disabled

Indeterminate - Margins
Margins

Checked - Margins + page numbers
Margins +page numbers

")) + self.croppingBox.setText(_translate("mainWindow", "Cropping mode")) + self.disableProcessingBox.setToolTip(_translate("mainWindow", "

Do not process any image, ignore profil and processing options

")) + self.disableProcessingBox.setText(_translate("mainWindow", "Disable processing")) self.gammaLabel.setText(_translate("mainWindow", "Gamma: Auto")) + self.croppingPowerLabel.setText(_translate("mainWindow", "Cropping power:")) self.directoryButton.setToolTip(_translate("mainWindow", "

Add directory containing JPG, PNG or GIF files to queue.
CBR, CBZ and CB7 files inside will not be processed!

")) self.directoryButton.setText(_translate("mainWindow", "Add directory")) self.fileButton.setToolTip(_translate("mainWindow", "

Add CBR, CBZ, CB7 or PDF file to queue.

")) diff --git a/kindlecomicconverter/__init__.py b/kindlecomicconverter/__init__.py index 0131f13c..59b64b2d 100644 --- a/kindlecomicconverter/__init__.py +++ b/kindlecomicconverter/__init__.py @@ -1,4 +1,4 @@ -__version__ = '5.5.3b14' +__version__ = '5.5.3b15' __license__ = 'ISC' __copyright__ = '2012-2022, Ciro Mattia Gonano , Pawel Jastrzebski , darodi' __docformat__ = 'restructuredtext en'