More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-08 20:42:41 +05:30
parent 89304c2e17
commit 70e383ccbf
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
9 changed files with 20 additions and 20 deletions

View File

@ -681,7 +681,7 @@ else:
def is_dark_theme(): def is_dark_theme():
pal = QApplication.instance().palette() pal = QApplication.instance().palette()
col = pal.color(pal.Window) col = pal.color(QPalette.ColorRole.Window)
return max(col.getRgb()[:3]) < 115 return max(col.getRgb()[:3]) < 115
@ -1068,7 +1068,7 @@ class Application(QApplication):
# Workaround for https://bugreports.qt.io/browse/QTBUG-75321 # Workaround for https://bugreports.qt.io/browse/QTBUG-75321
# Buttontext is set to black for some reason # Buttontext is set to black for some reason
pal = QPalette(self.palette()) 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.ignore_palette_changes = True
self.setPalette(pal, 'QComboBox') self.setPalette(pal, 'QComboBox')
self.ignore_palette_changes = False self.ignore_palette_changes = False

View File

@ -344,7 +344,7 @@ class LineEdit(QLineEdit, LineEditECM):
def event(self, ev): def event(self, ev):
# See https://bugreports.qt.io/browse/QTBUG-46911 # See https://bugreports.qt.io/browse/QTBUG-46911
try: 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.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right) and (
ev.modifiers() & ~Qt.KeyboardModifier.KeypadModifier) == Qt.KeyboardModifier.ControlModifier): ev.modifiers() & ~Qt.KeyboardModifier.KeypadModifier) == Qt.KeyboardModifier.ControlModifier):
ev.accept() ev.accept()

View File

@ -10,7 +10,7 @@ import sys
from PyQt5.Qt import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox, QStyleOptionViewItem, from PyQt5.Qt import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox, QStyleOptionViewItem,
QSpinBox, QStyledItemDelegate, QComboBox, QTextDocument, QMenu, QKeySequence, 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) QStyleOptionComboBox, QStyleOptionSpinBox, QLocale, QSize, QLineEdit, QDialog)
from calibre.ebooks.metadata import rating_to_stars from calibre.ebooks.metadata import rating_to_stars
@ -680,7 +680,7 @@ class DelegateCB(QComboBox): # {{{
QComboBox.__init__(self, parent) QComboBox.__init__(self, parent)
def event(self, e): def event(self, e):
if e.type() == e.ShortcutOverride: if e.type() == QEvent.Type.ShortcutOverride:
e.accept() e.accept()
return QComboBox.event(self, e) return QComboBox.event(self, e)
# }}} # }}}

View File

@ -11,7 +11,7 @@ from collections import namedtuple
from PyQt5.Qt import ( from PyQt5.Qt import (
QWidget, Qt, QLabel, QVBoxLayout, QDialogButtonBox, QApplication, QTimer, QPixmap, QWidget, Qt, QLabel, QVBoxLayout, QDialogButtonBox, QApplication, QTimer, QPixmap,
QSize, pyqtSignal, QIcon, QPlainTextEdit, QCheckBox, QPainter, QHBoxLayout, QFontMetrics, 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.constants import __version__
from calibre.gui2.dialogs.message_box import ViewLog from calibre.gui2.dialogs.message_box import ViewLog
@ -394,13 +394,13 @@ class ProceedQuestion(QWidget):
br = 12 # border_radius br = 12 # border_radius
bw = 1 # border_width bw = 1 # border_width
pal = self.palette() pal = self.palette()
c = pal.color(pal.Window) c = pal.color(QPalette.ColorRole.Window)
c.setAlphaF(0.9) c.setAlphaF(0.9)
p = QPainterPath() p = QPainterPath()
p.addRoundedRect(QRectF(self.rect()), br, br) p.addRoundedRect(QRectF(self.rect()), br, br)
painter.fillPath(p, c) painter.fillPath(p, c)
p.addRoundedRect(QRectF(self.rect()).adjusted(bw, bw, -bw, -bw), br, br) 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(): def main():

View File

@ -429,11 +429,11 @@ class LiveCSS(QWidget):
self.setFont(f) self.setFont(f)
theme = get_theme(tprefs['editor_theme']) theme = get_theme(tprefs['editor_theme'])
pal = self.palette() pal = self.palette()
pal.setColor(pal.Window, theme_color(theme, 'Normal', 'bg')) pal.setColor(QPalette.ColorRole.Window, theme_color(theme, 'Normal', 'bg'))
pal.setColor(pal.WindowText, theme_color(theme, 'Normal', 'fg')) pal.setColor(QPalette.ColorRole.WindowText, theme_color(theme, 'Normal', 'fg'))
pal.setColor(pal.AlternateBase, theme_color(theme, 'HighlightRegion', 'bg')) pal.setColor(QPalette.ColorRole.AlternateBase, theme_color(theme, 'HighlightRegion', 'bg'))
pal.setColor(pal.Link, theme_color(theme, 'Link', 'fg')) pal.setColor(QPalette.ColorRole.Link, theme_color(theme, 'Link', 'fg'))
pal.setColor(pal.LinkVisited, theme_color(theme, 'Keyword', 'fg')) pal.setColor(QPalette.ColorRole.LinkVisited, theme_color(theme, 'Keyword', 'fg'))
self.setPalette(pal) self.setPalette(pal)
if hasattr(self, 'box'): if hasattr(self, 'box'):
self.box.relayout() self.box.relayout()

View File

@ -87,7 +87,7 @@ class Central(QStackedWidget): # {{{
t.setTabsClosable(True) t.setTabsClosable(True)
t.setMovable(True) t.setMovable(True)
pal = self.palette() pal = self.palette()
if pal.color(pal.WindowText).lightness() > 128: if pal.color(QPalette.ColorRole.WindowText).lightness() > 128:
i = QImage(I('modified.png')) i = QImage(I('modified.png'))
i.invertPixels() i.invertPixels()
self.modified_icon = QIcon(QPixmap.fromImage(i)) self.modified_icon = QIcon(QPixmap.fromImage(i))

View File

@ -1239,7 +1239,7 @@ class PlainTextEdit(QPlainTextEdit): # {{{
if et == QEvent.Type.ToolTip: if et == QEvent.Type.ToolTip:
self.show_tooltip(ev) self.show_tooltip(ev)
return True return True
if et == ev.ShortcutOverride: if et == QEvent.Type.ShortcutOverride:
ret = self.override_shortcut(ev) ret = self.override_shortcut(ev)
if ret: if ret:
return True return True

View File

@ -3,7 +3,7 @@
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
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 from calibre.gui2.progress_indicator import ProgressIndicator
@ -26,9 +26,9 @@ class LoadingOverlay(QWidget):
self.resize(parent.size()) self.resize(parent.size())
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
pal = self.palette() pal = self.palette()
col = pal.color(pal.Window) col = pal.color(QPalette.ColorRole.Window)
col.setAlphaF(0.8) col.setAlphaF(0.8)
pal.setColor(pal.Window, col) pal.setColor(QPalette.ColorRole.Window, col)
self.setPalette(pal) self.setPalette(pal)
self.move(0, 0) self.move(0, 0)
f = self.font() f = self.font()

View File

@ -7,7 +7,7 @@ Miscellaneous widgets used in the GUI
''' '''
import re, os 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, QListWidgetItem, QTextCharFormat, QApplication, QSyntaxHighlighter,
QCursor, QColor, QWidget, QPixmap, QSplitterHandle, QToolButton, QCursor, QColor, QWidget, QPixmap, QSplitterHandle, QToolButton,
Qt, pyqtSignal, QRegExp, QSize, QSplitter, QPainter, QPageSize, QPrinter, Qt, pyqtSignal, QRegExp, QSize, QSplitter, QPainter, QPageSize, QPrinter,
@ -523,7 +523,7 @@ class EnLineEdit(LineEditECM, QLineEdit): # {{{
def event(self, ev): def event(self, ev):
# See https://bugreports.qt.io/browse/QTBUG-46911 # 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 ( 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.modifiers() & ~Qt.KeyboardModifier.KeypadModifier) == Qt.KeyboardModifier.ControlModifier):
ev.accept() ev.accept()