Skip to content

Commit

Permalink
fix: Fixed some compatibility issues for lower versions of Calibre.
Browse files Browse the repository at this point in the history
  • Loading branch information
bookfere committed Mar 10, 2024
1 parent 602b30d commit 4ce7ed3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
18 changes: 0 additions & 18 deletions components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,3 @@
from .alert import AlertMessage
from .table import AdvancedTranslationTable
from .mode import ModeSelection


try:
from qt.core import Qt, QFrame
except ImportError:
from PyQt5.Qt import Qt, QFrame


def get_divider():
divider = QFrame()
divider.setFrameShape(QFrame.HLine)
divider.setFrameShadow(QFrame.Sunken)
# divider.setFrameStyle(QFrame.HLine | QFrame.Sunken)
return divider


def qt_version():
return vars(Qt).get('QT_VERSION_STR')
16 changes: 11 additions & 5 deletions components/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from qt.core import (
Qt, QTableWidget, QHeaderView, QMenu, QAbstractItemView, QCursor,
QBrush, QTableWidgetItem, pyqtSignal, QTableWidgetSelectionRange,
QColor)
QColor, QT_VERSION_STR)
except ImportError:
from PyQt5.Qt import (
Qt, QTableWidget, QHeaderView, QMenu, QAbstractItemView, QCursor,
QBrush, QTableWidgetItem, pyqtSignal, QTableWidgetSelectionRange,
QColor)
QColor, QT_VERSION_STR)

load_translations()

Expand All @@ -25,6 +25,9 @@ def __init__(self, parent, paragraphs):
QTableWidget.__init__(self, parent)
self.parent = parent
self.paragraphs = paragraphs

# self.setFocusPolicy(Qt.NoFocus)

self.alert = AlertMessage(self)
self.layout()

Expand Down Expand Up @@ -77,6 +80,7 @@ def track_row_data(self, row):

def check_row_alignment(self, paragraph):
item = self.verticalHeaderItem(paragraph.row)

if paragraph.background is None:
paragraph.background = item.background()
if paragraph.foreground is None:
Expand All @@ -96,12 +100,14 @@ def check_row_alignment(self, paragraph):
'the translated text.')
paragraph.aligned = False

item.setBackground(background)
item.setForeground(foreground)
item.setToolTip(tip)
if QT_VERSION_STR >= '6.0.0':
item.setBackground(background)
item.setForeground(foreground)
item.setToolTip(tip)
for column in range(self.columnCount()):
item = self.item(paragraph.row, column)
item.setBackground(background)
item.setForeground(foreground)
item.setToolTip(tip)

def non_aligned_count(self):
Expand Down
26 changes: 18 additions & 8 deletions setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
from .engines import GeminiPro
from .components import (
layout_info, AlertMessage, TargetLang, SourceLang, EngineList,
EngineTester, get_divider, ManageCustomEngine, InputFormat, OutputFormat)
EngineTester, ManageCustomEngine, InputFormat, OutputFormat)

try:
from qt.core import (
Qt, QLabel, QDialog, QWidget, QLineEdit, QPushButton, QPlainTextEdit,
QTabWidget, QHBoxLayout, QVBoxLayout, QGroupBox, QFileDialog, QColor,
QIntValidator, QScrollArea, QRadioButton, QGridLayout, QCheckBox,
QButtonGroup, QColorDialog, QSpinBox, QPalette, QApplication,
QButtonGroup, QColorDialog, QSpinBox, QPalette, QApplication, QFrame,
QComboBox, QRegularExpression, pyqtSignal, QFormLayout, QDoubleSpinBox,
QSettings, QSpacerItem, QRegularExpressionValidator, QBoxLayout)
except ImportError:
from PyQt5.Qt import (
Qt, QLabel, QDialog, QWidget, QLineEdit, QPushButton, QPlainTextEdit,
QTabWidget, QHBoxLayout, QVBoxLayout, QGroupBox, QFileDialog, QColor,
QIntValidator, QScrollArea, QRadioButton, QGridLayout, QCheckBox,
QButtonGroup, QColorDialog, QSpinBox, QPalette, QApplication,
QButtonGroup, QColorDialog, QSpinBox, QPalette, QApplication, QFrame,
QComboBox, QRegularExpression, pyqtSignal, QFormLayout, QDoubleSpinBox,
QSettings, QSpacerItem, QRegularExpressionValidator, QBoxLayout)

Expand All @@ -46,6 +46,13 @@ def __init__(self, plugin, parent, icon):

self.main_layout()

def _divider(self):
divider = QFrame()
divider.setFrameShape(QFrame.HLine)
divider.setFrameShadow(QFrame.Sunken)
# divider.setFrameStyle(QFrame.HLine | QFrame.Sunken)
return divider

def main_layout(self):
layout = QVBoxLayout(self)

Expand Down Expand Up @@ -111,7 +118,7 @@ def layout_general(self):
mode_layout.addWidget(advanced_mode, 0, 1)
mode_layout.addWidget(batch_mode, 0, 2)
mode_layout.addItem(QSpacerItem(0, 0), 0, 3)
mode_layout.addWidget(get_divider(), 1, 1, 1, 4)
mode_layout.addWidget(self._divider(), 1, 1, 1, 4)
mode_layout.addWidget(QLabel(
_('Choose a translation mode for clicking the icon button.')),
2, 1, 1, 4)
Expand Down Expand Up @@ -757,9 +764,12 @@ def layout_content(self):
or position_btn_group.buttonClicked[int]

names = ('TopToBottom', 'BottomToTop', 'RightToLeft', 'LeftToRight')
directions = [
getattr(QBoxLayout, name, None) or getattr(
QBoxLayout.Direction, name) for name in names]
directions = []
for name in names:
direction = getattr(QBoxLayout, name, None)
if direction is None:
direction = getattr(QBoxLayout.Direction, name)
directions.append(direction)

def choose_option(btn_id):
original_sample.setVisible(btn_id != 4)
Expand Down Expand Up @@ -906,7 +916,7 @@ def choose_glossary_file():

filter_layout.addWidget(scope_group)
filter_layout.addWidget(mode_group)
filter_layout.addWidget(get_divider())
filter_layout.addWidget(self._divider())
filter_layout.addWidget(tip)
filter_layout.addWidget(self.filter_rules)
layout.addWidget(filter_group)
Expand Down

0 comments on commit 4ce7ed3

Please sign in to comment.