diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index ecc21b9100..767bd2cc48 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -681,7 +681,7 @@ else: def is_dark_theme(): pal = QApplication.instance().palette() - col = pal.color(pal.Window) + col = pal.color(QPalette.ColorRole.Window) return max(col.getRgb()[:3]) < 115 @@ -1068,7 +1068,7 @@ class Application(QApplication): # Workaround for https://bugreports.qt.io/browse/QTBUG-75321 # Buttontext is set to black for some reason pal = QPalette(self.palette()) - pal.setColor(pal.ButtonText, pal.color(pal.WindowText)) + pal.setColor(QPalette.ColorRole.ButtonText, pal.color(QPalette.ColorRole.WindowText)) self.ignore_palette_changes = True self.setPalette(pal, 'QComboBox') self.ignore_palette_changes = False diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index 951b2a2eed..3783abe5c5 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -344,7 +344,7 @@ class LineEdit(QLineEdit, LineEditECM): def event(self, ev): # See https://bugreports.qt.io/browse/QTBUG-46911 try: - if ev.type() == ev.ShortcutOverride and ( + if ev.type() == QEvent.Type.ShortcutOverride and ( ev.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right) and ( ev.modifiers() & ~Qt.KeyboardModifier.KeypadModifier) == Qt.KeyboardModifier.ControlModifier): ev.accept() diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index ce86e541d7..a2f679e475 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -10,7 +10,7 @@ import sys from PyQt5.Qt import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox, QStyleOptionViewItem, QSpinBox, QStyledItemDelegate, QComboBox, QTextDocument, QMenu, QKeySequence, - QAbstractTextDocumentLayout, QFont, QFontInfo, QDate, QDateTimeEdit, QDateTime, + QAbstractTextDocumentLayout, QFont, QFontInfo, QDate, QDateTimeEdit, QDateTime, QEvent, QStyleOptionComboBox, QStyleOptionSpinBox, QLocale, QSize, QLineEdit, QDialog) from calibre.ebooks.metadata import rating_to_stars @@ -680,7 +680,7 @@ class DelegateCB(QComboBox): # {{{ QComboBox.__init__(self, parent) def event(self, e): - if e.type() == e.ShortcutOverride: + if e.type() == QEvent.Type.ShortcutOverride: e.accept() return QComboBox.event(self, e) # }}} diff --git a/src/calibre/gui2/proceed.py b/src/calibre/gui2/proceed.py index 6581faa927..81b74689ae 100644 --- a/src/calibre/gui2/proceed.py +++ b/src/calibre/gui2/proceed.py @@ -11,7 +11,7 @@ from collections import namedtuple from PyQt5.Qt import ( QWidget, Qt, QLabel, QVBoxLayout, QDialogButtonBox, QApplication, QTimer, QPixmap, QSize, pyqtSignal, QIcon, QPlainTextEdit, QCheckBox, QPainter, QHBoxLayout, QFontMetrics, - QPainterPath, QRectF, pyqtProperty, QPropertyAnimation, QEasingCurve, QSizePolicy, QImage) + QPainterPath, QRectF, pyqtProperty, QPropertyAnimation, QEasingCurve, QSizePolicy, QImage, QPalette) from calibre.constants import __version__ from calibre.gui2.dialogs.message_box import ViewLog @@ -394,13 +394,13 @@ class ProceedQuestion(QWidget): br = 12 # border_radius bw = 1 # border_width pal = self.palette() - c = pal.color(pal.Window) + c = pal.color(QPalette.ColorRole.Window) c.setAlphaF(0.9) p = QPainterPath() p.addRoundedRect(QRectF(self.rect()), br, br) painter.fillPath(p, c) p.addRoundedRect(QRectF(self.rect()).adjusted(bw, bw, -bw, -bw), br, br) - painter.fillPath(p, pal.color(pal.WindowText)) + painter.fillPath(p, pal.color(QPalette.ColorRole.WindowText)) def main(): diff --git a/src/calibre/gui2/tweak_book/live_css.py b/src/calibre/gui2/tweak_book/live_css.py index a440aae711..08db1aac03 100644 --- a/src/calibre/gui2/tweak_book/live_css.py +++ b/src/calibre/gui2/tweak_book/live_css.py @@ -429,11 +429,11 @@ class LiveCSS(QWidget): self.setFont(f) theme = get_theme(tprefs['editor_theme']) pal = self.palette() - pal.setColor(pal.Window, theme_color(theme, 'Normal', 'bg')) - pal.setColor(pal.WindowText, theme_color(theme, 'Normal', 'fg')) - pal.setColor(pal.AlternateBase, theme_color(theme, 'HighlightRegion', 'bg')) - pal.setColor(pal.Link, theme_color(theme, 'Link', 'fg')) - pal.setColor(pal.LinkVisited, theme_color(theme, 'Keyword', 'fg')) + pal.setColor(QPalette.ColorRole.Window, theme_color(theme, 'Normal', 'bg')) + pal.setColor(QPalette.ColorRole.WindowText, theme_color(theme, 'Normal', 'fg')) + pal.setColor(QPalette.ColorRole.AlternateBase, theme_color(theme, 'HighlightRegion', 'bg')) + pal.setColor(QPalette.ColorRole.Link, theme_color(theme, 'Link', 'fg')) + pal.setColor(QPalette.ColorRole.LinkVisited, theme_color(theme, 'Keyword', 'fg')) self.setPalette(pal) if hasattr(self, 'box'): self.box.relayout() diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index a1859663c3..2c4a554bdd 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -87,7 +87,7 @@ class Central(QStackedWidget): # {{{ t.setTabsClosable(True) t.setMovable(True) pal = self.palette() - if pal.color(pal.WindowText).lightness() > 128: + if pal.color(QPalette.ColorRole.WindowText).lightness() > 128: i = QImage(I('modified.png')) i.invertPixels() self.modified_icon = QIcon(QPixmap.fromImage(i)) diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index c27328e9fe..2df294a958 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -1239,7 +1239,7 @@ class PlainTextEdit(QPlainTextEdit): # {{{ if et == QEvent.Type.ToolTip: self.show_tooltip(ev) return True - if et == ev.ShortcutOverride: + if et == QEvent.Type.ShortcutOverride: ret = self.override_shortcut(ev) if ret: return True diff --git a/src/calibre/gui2/viewer/overlay.py b/src/calibre/gui2/viewer/overlay.py index 28ce7939e1..c0f69cc227 100644 --- a/src/calibre/gui2/viewer/overlay.py +++ b/src/calibre/gui2/viewer/overlay.py @@ -3,7 +3,7 @@ # License: GPL v3 Copyright: 2019, Kovid Goyal -from PyQt5.Qt import QWidget, Qt, QFontInfo, QLabel, QVBoxLayout +from PyQt5.Qt import QWidget, Qt, QFontInfo, QLabel, QVBoxLayout, QPalette from calibre.gui2.progress_indicator import ProgressIndicator @@ -26,9 +26,9 @@ class LoadingOverlay(QWidget): self.resize(parent.size()) self.setAutoFillBackground(True) pal = self.palette() - col = pal.color(pal.Window) + col = pal.color(QPalette.ColorRole.Window) col.setAlphaF(0.8) - pal.setColor(pal.Window, col) + pal.setColor(QPalette.ColorRole.Window, col) self.setPalette(pal) self.move(0, 0) f = self.font() diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 84dcb8dcf9..b529e8af44 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -7,7 +7,7 @@ Miscellaneous widgets used in the GUI ''' import re, os -from PyQt5.Qt import (QIcon, QFont, QLabel, QListWidget, QAction, +from PyQt5.Qt import (QIcon, QFont, QLabel, QListWidget, QAction, QEvent, QListWidgetItem, QTextCharFormat, QApplication, QSyntaxHighlighter, QCursor, QColor, QWidget, QPixmap, QSplitterHandle, QToolButton, Qt, pyqtSignal, QRegExp, QSize, QSplitter, QPainter, QPageSize, QPrinter, @@ -523,7 +523,7 @@ class EnLineEdit(LineEditECM, QLineEdit): # {{{ def event(self, ev): # See https://bugreports.qt.io/browse/QTBUG-46911 - if ev.type() == ev.ShortcutOverride and ( + if ev.type() == QEvent.Type.ShortcutOverride and ( hasattr(ev, 'key') and ev.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right) and ( ev.modifiers() & ~Qt.KeyboardModifier.KeypadModifier) == Qt.KeyboardModifier.ControlModifier): ev.accept()