More stupid PyQt enums

This commit is contained in:
Kovid Goyal
2020-12-08 20:42:41 +05:30
parent 89304c2e17
commit 70e383ccbf
9 changed files with 20 additions and 20 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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()
+2 -2
View File
@@ -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)
# }}}
+3 -3
View File
@@ -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():
+5 -5
View File
@@ -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()
+1 -1
View File
@@ -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))
+1 -1
View File
@@ -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
+3 -3
View File
@@ -3,7 +3,7 @@
# 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
@@ -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()
+2 -2
View File
@@ -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()