More stupid PyQt enums

More stupid PyQt enums
This commit is contained in:
Kovid Goyal 2020-12-19 12:42:57 +05:30
parent 63fbb991e1
commit 48000d4514
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
16 changed files with 37 additions and 37 deletions

View File

@ -7,7 +7,7 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from functools import partial from functools import partial
from PyQt5.Qt import QTimer, QApplication, Qt from PyQt5.Qt import QTimer, QApplication, Qt, QEvent
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import InterfaceAction
@ -79,7 +79,7 @@ class MarkBooksAction(InterfaceAction):
continue continue
def eventFilter(self, obj, ev): def eventFilter(self, obj, ev):
if ev.type() == ev.MouseButtonPress and ev.button() == Qt.MouseButton.LeftButton: if ev.type() == QEvent.Type.MouseButtonPress and ev.button() == Qt.MouseButton.LeftButton:
mods = QApplication.keyboardModifiers() mods = QApplication.keyboardModifiers()
if mods & Qt.KeyboardModifier.ControlModifier or mods & Qt.KeyboardModifier.ShiftModifier: if mods & Qt.KeyboardModifier.ControlModifier or mods & Qt.KeyboardModifier.ShiftModifier:
self.show_marked() self.show_marked()

View File

@ -512,7 +512,7 @@ class EditWithComplete(EnComboBox):
except AttributeError: except AttributeError:
return False return False
etype = e.type() etype = e.type()
if self.eat_focus_out and self is obj and etype == e.FocusOut: if self.eat_focus_out and self is obj and etype == QEvent.Type.FocusOut:
if c.isVisible(): if c.isVisible():
return True return True
return EnComboBox.eventFilter(self, obj, e) return EnComboBox.eventFilter(self, obj, e)

View File

@ -8,7 +8,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import time import time
from PyQt5.Qt import ( from PyQt5.Qt import (
QApplication, QMainWindow, QVBoxLayout, Qt, QKeySequence, QAction, QApplication, QMainWindow, QVBoxLayout, Qt, QKeySequence, QAction, QEvent,
QActionGroup, QMenu, QPushButton, QWidget, QTimer, QMessageBox, pyqtSignal) QActionGroup, QMenu, QPushButton, QWidget, QTimer, QMessageBox, pyqtSignal)
from calibre.gui2.dbus_export.utils import setup_for_cli_run from calibre.gui2.dbus_export.utils import setup_for_cli_run
@ -153,8 +153,8 @@ class MainWindow(QMainWindow):
QMessageBox.information(self, 'A test dialog', 'While this dialog is shown, the global menu should be hidden') QMessageBox.information(self, 'A test dialog', 'While this dialog is shown, the global menu should be hidden')
def event(self, ev): def event(self, ev):
if ev.type() in (ev.WindowBlocked, ev.WindowUnblocked): if ev.type() in (QEvent.Type.WindowBlocked, QEvent.Type.WindowUnblocked):
if ev.type() == ev.WindowBlocked: if ev.type() == QEvent.Type.WindowBlocked:
self.window_blocked.emit() self.window_blocked.emit()
else: else:
self.window_unblocked.emit() self.window_unblocked.emit()

View File

@ -10,7 +10,7 @@ import functools
from PyQt5.Qt import ( from PyQt5.Qt import (
QAction, QApplication, QIcon, QLabel, QMenu, QPainter, QSizePolicy, QSplitter, QAction, QApplication, QIcon, QLabel, QMenu, QPainter, QSizePolicy, QSplitter,
QStackedWidget, QStatusBar, QStyle, QStyleOption, Qt, QTabBar, QTimer, QStackedWidget, QStatusBar, QStyle, QStyleOption, Qt, QTabBar, QTimer,
QToolButton, QVBoxLayout, QWidget, QDialog QToolButton, QVBoxLayout, QWidget, QDialog, QEvent
) )
from calibre.constants import __appname__, get_version, ismacos from calibre.constants import __appname__, get_version, ismacos
@ -239,9 +239,9 @@ class VersionLabel(QLabel): # {{{
def event(self, ev): def event(self, ev):
m = None m = None
et = ev.type() et = ev.type()
if et == ev.Enter: if et == QEvent.Type.Enter:
m = True m = True
elif et == ev.Leave: elif et == QEvent.Type.Leave:
m = False m = False
if m is not None and m != self.mouse_over: if m is not None and m != self.mouse_over:
self.mouse_over = m self.mouse_over = m

View File

@ -7,8 +7,8 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from PyQt5.Qt import ( from PyQt5.Qt import (
QBrush, QColor, QEasingCurve, QPainter, QPainterPath, QPalette, QPoint, QPointF, QAbstractAnimation, QBrush, QColor, QEasingCurve, QPainter, QPainterPath,
QPropertyAnimation, QRect, Qt, QWidget QPalette, QPoint, QPointF, QPropertyAnimation, QRect, Qt, QWidget
) )
from calibre.gui2 import config from calibre.gui2 import config
@ -78,7 +78,7 @@ class Pointer(QWidget):
self.path.closeSubpath() self.path.closeSubpath()
self.animation.setStartValue(self.rect_at(0.0)) self.animation.setStartValue(self.rect_at(0.0))
self.animation.setEndValue(self.rect_at(1.0)) self.animation.setEndValue(self.rect_at(1.0))
self.animation.setDirection(self.animation.Backward) self.animation.setDirection(QAbstractAnimation.Direction.Backward)
num_keys = 100 num_keys = 100
for i in range(1, num_keys): for i in range(1, num_keys):
i /= num_keys i /= num_keys

View File

@ -12,7 +12,7 @@ Job management.
import time import time
from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter, from PyQt5.Qt import (QAbstractTableModel, QModelIndex, Qt, QPainter,
QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QTimer, pyqtSignal, QIcon, QDialog, QAbstractItemDelegate, QApplication, QEvent,
QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption, QSize, QStyleOptionProgressBar, QStyle, QToolTip, QWidget, QStyleOption,
QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction, QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QCoreApplication, QAction,
QByteArray, QSortFilterProxyModel, QTextBrowser, QPlainTextEdit, QDialogButtonBox) QByteArray, QSortFilterProxyModel, QTextBrowser, QPlainTextEdit, QDialogButtonBox)
@ -533,9 +533,9 @@ class JobsButton(QWidget): # {{{
def event(self, ev): def event(self, ev):
m = None m = None
et = ev.type() et = ev.type()
if et == ev.Enter: if et == QEvent.Type.Enter:
m = True m = True
elif et == ev.Leave: elif et == QEvent.Type.Leave:
m = False m = False
if m is not None and m != self.mouse_over: if m is not None and m != self.mouse_over:
self.mouse_over = m self.mouse_over = m

View File

@ -5,7 +5,7 @@
from PyQt5.Qt import ( from PyQt5.Qt import (
QFontMetrics, QHBoxLayout, QIcon, QMenu, QPainter, QPushButton, QSize, QFontMetrics, QHBoxLayout, QIcon, QMenu, QPainter, QPushButton, QSize,
QSizePolicy, Qt, QWidget, QStyleOption, QStyle) QSizePolicy, Qt, QWidget, QStyleOption, QStyle, QEvent)
ICON_SZ = 64 ICON_SZ = 64
@ -38,9 +38,9 @@ class LayoutItem(QWidget):
def event(self, ev): def event(self, ev):
m = None m = None
et = ev.type() et = ev.type()
if et == ev.Enter: if et == QEvent.Type.Enter:
m = True m = True
elif et == ev.Leave: elif et == QEvent.Type.Leave:
m = False m = False
if m is not None and m != self.mouse_over: if m is not None and m != self.mouse_over:
self.mouse_over = m self.mouse_over = m

View File

@ -60,9 +60,9 @@ class HeaderView(QHeaderView): # {{{
self.fm = QFontMetrics(self.current_font) self.fm = QFontMetrics(self.current_font)
def event(self, e): def event(self, e):
if e.type() in (e.HoverMove, e.HoverEnter): if e.type() in (QEvent.Type.HoverMove, QEvent.Type.HoverEnter):
self.hover = self.logicalIndexAt(e.pos()) self.hover = self.logicalIndexAt(e.pos())
elif e.type() in (e.Leave, e.HoverLeave): elif e.type() in (QEvent.Type.Leave, QEvent.Type.HoverLeave):
self.hover = -1 self.hover = -1
return QHeaderView.event(self, e) return QHeaderView.event(self, e)

View File

@ -717,8 +717,8 @@ class MetadataSingleDialogBase(QDialog):
' [Alt+Left]')%prev ' [Alt+Left]')%prev
self.prev_button.setToolTip(tip) self.prev_button.setToolTip(tip)
self.prev_button.setEnabled(prev is not None) self.prev_button.setEnabled(prev is not None)
self.button_box.button(self.button_box.Ok).setDefault(True) self.button_box.button(QDialogButtonBox.StandardButton.Ok).setDefault(True)
self.button_box.button(self.button_box.Ok).setFocus(Qt.FocusReason.OtherFocusReason) self.button_box.button(QDialogButtonBox.StandardButton.Ok).setFocus(Qt.FocusReason.OtherFocusReason)
self(self.db.id(self.row_list[self.current_row])) self(self.db.id(self.row_list[self.current_row]))
for w, state in iteritems(self.comments_edit_state_at_apply): for w, state in iteritems(self.comments_edit_state_at_apply):
if state == 'code': if state == 'code':

View File

@ -258,8 +258,8 @@ class Preferences(QDialog):
self.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu) self.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)
self.title_bar = TitleBar(self) self.title_bar = TitleBar(self)
for ac, tt in [(self.bb.Apply, _('Save changes')), for ac, tt in [(QDialogButtonBox.StandardButton.Apply, _('Save changes')),
(self.bb.Discard, _('Cancel and return to overview'))]: (QDialogButtonBox.StandardButton.Discard, _('Cancel and return to overview'))]:
self.bb.button(ac).setToolTip(tt) self.bb.button(ac).setToolTip(tt)
l.addWidget(self.title_bar), l.addWidget(self.stack), l.addWidget(self.bb) l.addWidget(self.title_bar), l.addWidget(self.stack), l.addWidget(self.bb)
@ -323,7 +323,7 @@ class Preferences(QDialog):
self.bb.button(QDialogButtonBox.StandardButton.Close).setVisible(False) self.bb.button(QDialogButtonBox.StandardButton.Close).setVisible(False)
self.wizard_button.setVisible(False) self.wizard_button.setVisible(False)
for button in (self.bb.Apply, self.bb.RestoreDefaults, self.bb.Discard): for button in (QDialogButtonBox.StandardButton.Apply, QDialogButtonBox.StandardButton.RestoreDefaults, QDialogButtonBox.StandardButton.Discard):
button = self.bb.button(button) button = self.bb.button(button)
button.setVisible(True) button.setVisible(True)
@ -353,7 +353,7 @@ class Preferences(QDialog):
self.title_bar.show_plugin() self.title_bar.show_plugin()
self.setWindowIcon(QIcon(I('config.png'))) self.setWindowIcon(QIcon(I('config.png')))
for button in (self.bb.Apply, self.bb.RestoreDefaults, self.bb.Discard): for button in (QDialogButtonBox.StandardButton.Apply, QDialogButtonBox.StandardButton.RestoreDefaults, QDialogButtonBox.StandardButton.Discard):
button = self.bb.button(button) button = self.bb.button(button)
button.setVisible(False) button.setVisible(False)

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from collections import namedtuple 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, QEvent,
QSize, pyqtSignal, QIcon, QPlainTextEdit, QCheckBox, QPainter, QHBoxLayout, QFontMetrics, QSize, pyqtSignal, QIcon, QPlainTextEdit, QCheckBox, QPainter, QHBoxLayout, QFontMetrics,
QPainterPath, QRectF, pyqtProperty, QPropertyAnimation, QEasingCurve, QSizePolicy, QImage, QPalette) QPainterPath, QRectF, pyqtProperty, QPropertyAnimation, QEasingCurve, QSizePolicy, QImage, QPalette)
@ -160,7 +160,7 @@ class ProceedQuestion(QWidget):
t.setSingleShot(True), t.setInterval(100), t.timeout.connect(self.parent_resized) t.setSingleShot(True), t.setInterval(100), t.timeout.connect(self.parent_resized)
def eventFilter(self, obj, ev): def eventFilter(self, obj, ev):
if ev.type() == ev.Resize and self.isVisible(): if ev.type() == QEvent.Type.Resize and self.isVisible():
self.resize_timer.start() self.resize_timer.start()
return False return False

View File

@ -11,7 +11,7 @@ from PyQt5.Qt import (
QApplication, QCheckBox, QCursor, QDialog, QDialogButtonBox, QFrame, QGridLayout, QApplication, QCheckBox, QCursor, QDialog, QDialogButtonBox, QFrame, QGridLayout,
QIcon, QInputDialog, QItemSelectionModel, QKeySequence, QLabel, QMenu, QIcon, QInputDialog, QItemSelectionModel, QKeySequence, QLabel, QMenu,
QPushButton, QScrollArea, QSize, QSizePolicy, QStackedWidget, Qt, QAbstractItemView, QPushButton, QScrollArea, QSize, QSizePolicy, QStackedWidget, Qt, QAbstractItemView,
QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal, QEvent
) )
from threading import Thread from threading import Thread
@ -770,7 +770,7 @@ class TOCView(QWidget): # {{{
self.item_view.edit_item() self.item_view.edit_item()
def event(self, e): def event(self, e):
if e.type() == e.StatusTip: if e.type() == QEvent.Type.StatusTip:
txt = unicode_type(e.tip()) or self.default_msg txt = unicode_type(e.tip()) or self.default_msg
self.hl.setText(txt) self.hl.setText(txt)
return super(TOCView, self).event(e) return super(TOCView, self).event(e)

View File

@ -200,7 +200,7 @@ class ChoosePopupWidget(QWidget):
if ret: if ret:
ev.accept() ev.accept()
return ret return ret
elif etype == ev.Resize: elif etype == QEvent.Type.Resize:
self.relayout_timer.start() self.relayout_timer.start()
return False return False

View File

@ -15,7 +15,7 @@ from polyglot.builtins import iteritems, unicode_type, zip, range, as_bytes, map
import regex import regex
from PyQt5.Qt import ( from PyQt5.Qt import (
QSplitter, QApplication, QTimer, QSplitter, QApplication, QTimer, QEvent,
QTextCursor, QTextCharFormat, Qt, QRect, QPainter, QPalette, QPen, QBrush, QTextCursor, QTextCharFormat, Qt, QRect, QPainter, QPalette, QPen, QBrush,
QColor, QTextLayout, QCursor, QFont, QSplitterHandle, QPainterPath, QColor, QTextLayout, QCursor, QFont, QSplitterHandle, QPainterPath,
QHBoxLayout, QWidget, QScrollBar, QEventLoop, pyqtSignal, QImage, QPixmap, QHBoxLayout, QWidget, QScrollBar, QEventLoop, pyqtSignal, QImage, QPixmap,
@ -401,8 +401,8 @@ class DiffSplitHandle(QSplitterHandle): # {{{
wheel_event = pyqtSignal(object) wheel_event = pyqtSignal(object)
def event(self, ev): def event(self, ev):
if ev.type() in (ev.HoverEnter, ev.HoverLeave): if ev.type() in (QEvent.Type.HoverEnter, QEvent.Type.HoverLeave):
self.hover = ev.type() == ev.HoverEnter self.hover = ev.type() == QEvent.Type.HoverEnter
return QSplitterHandle.event(self, ev) return QSplitterHandle.event(self, ev)
def paintEvent(self, event): def paintEvent(self, event):

View File

@ -699,7 +699,7 @@ class EbookViewer(MainWindow):
t.start() t.start()
def eventFilter(self, obj, ev): def eventFilter(self, obj, ev):
if ev.type() == ev.MouseMove: if ev.type() == QEvent.Type.MouseMove:
if self.cursor_hidden: if self.cursor_hidden:
self.cursor_hidden = False self.cursor_hidden = False
QApplication.instance().restoreOverrideCursor() QApplication.instance().restoreOverrideCursor()

View File

@ -8,7 +8,7 @@ import shutil
import sys import sys
from itertools import count from itertools import count
from PyQt5.Qt import ( from PyQt5.Qt import (
QT_VERSION, QApplication, QBuffer, QByteArray, QFontDatabase, QFontInfo, QPalette, QT_VERSION, QApplication, QBuffer, QByteArray, QFontDatabase, QFontInfo, QPalette, QEvent,
QHBoxLayout, QMimeData, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal, QIODevice, QLocale QHBoxLayout, QMimeData, QSize, Qt, QTimer, QUrl, QWidget, pyqtSignal, QIODevice, QLocale
) )
from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
@ -572,7 +572,7 @@ class WebView(RestartingWebEngineView):
' You should try restarting the viewer.') , show=True) ' You should try restarting the viewer.') , show=True)
def event(self, event): def event(self, event):
if event.type() == event.ChildPolished: if event.type() == QEvent.Type.ChildPolished:
child = event.child() child = event.child()
if 'HostView' in child.metaObject().className(): if 'HostView' in child.metaObject().className():
self._host_widget = child self._host_widget = child