Cleanup previous PR

This commit is contained in:
Kovid Goyal 2024-10-05 14:35:10 +05:30
parent 57f4b5d37c
commit cc16d900ae
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,7 +7,22 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import os import os
import sys import sys
from qt.core import QCheckBox, QDialog, QDialogButtonBox, QFormLayout, QHBoxLayout, QIcon, QKeySequence, QLabel, QSize, QSpinBox, QDoubleSpinBox, Qt, QToolBar, QVBoxLayout from qt.core import (
QCheckBox,
QDialog,
QDialogButtonBox,
QDoubleSpinBox,
QFormLayout,
QHBoxLayout,
QIcon,
QKeySequence,
QLabel,
QSize,
QSpinBox,
Qt,
QToolBar,
QVBoxLayout,
)
from calibre.gui2 import gprefs from calibre.gui2 import gprefs
from calibre.gui2.tweak_book.editor.canvas import Canvas from calibre.gui2.tweak_book.editor.canvas import Canvas
@ -37,11 +52,12 @@ class Region(QDialog):
h.valueChanged.connect(self.value_changed) h.valueChanged.connect(self.value_changed)
l.addRow(_('&Height:'), h) l.addRow(_('&Height:'), h)
self.ratio_input = r = QDoubleSpinBox(self) self.ratio_input = r = QDoubleSpinBox(self)
r.setRange(0.0, 5.00), r.setDecimals(2), r.setValue(max_width/max_height), r.setSingleStep(0.01), r.setToolTip('For example, use 0.75 for kindle devices.') r.setRange(0.0, 5.00), r.setDecimals(2), r.setValue(max_width/max_height), r.setSingleStep(0.01)
r.setToolTip(_('For example, use 0.75 for kindle devices.'))
self.m_width = max_width self.m_width = max_width
self.m_height = max_height self.m_height = max_height
r.valueChanged.connect(self.aspect_changed) r.valueChanged.connect(self.aspect_changed)
l.addRow(_('&Adjust Aspect Ratio:'), r) l.addRow(_('&Aspect ratio:'), r)
self.const_aspect = ca = QCheckBox(_('Keep the ratio of width to height fixed')) self.const_aspect = ca = QCheckBox(_('Keep the ratio of width to height fixed'))
ca.toggled.connect(self.const_aspect_toggled) ca.toggled.connect(self.const_aspect_toggled)
l.addRow(ca) l.addRow(ca)
@ -57,6 +73,7 @@ class Region(QDialog):
l.addRow(bb) l.addRow(bb)
self.resize(self.sizeHint()) self.resize(self.sizeHint())
self.current_aspect = width / height self.current_aspect = width / height
self.ratio_input.setEnabled(not self.const_aspect.isChecked())
def aspect_changed(self): def aspect_changed(self):
inp = float(self.ratio_input.value()) inp = float(self.ratio_input.value())
@ -69,6 +86,7 @@ class Region(QDialog):
self.height_input.setValue(self.m_height) self.height_input.setValue(self.m_height)
def const_aspect_toggled(self): def const_aspect_toggled(self):
self.ratio_input.setEnabled(not self.const_aspect.isChecked())
if self.const_aspect.isChecked(): if self.const_aspect.isChecked():
self.current_aspect = self.width_input.value() / self.height_input.value() self.current_aspect = self.width_input.value() / self.height_input.value()