diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index a0c454d782..951b2a2eed 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en' from PyQt5.Qt import ( QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, QKeySequence, QAbstractItemView, - QApplication, QListView, QPoint, QModelIndex, + QApplication, QListView, QPoint, QModelIndex, QEvent, QStyleOptionComboBox, QStyle, QComboBox, QTimer) try: from PyQt5 import sip @@ -184,7 +184,7 @@ class Completer(QListView): # {{{ def debug_event(self, ev): from calibre.gui2 import event_type_name print('Event:', event_type_name(ev)) - if ev.type() in (ev.KeyPress, ev.ShortcutOverride, ev.KeyRelease): + if ev.type() in (QEvent.Type.KeyPress, QEvent.Type.ShortcutOverride, QEvent.Type.KeyRelease): print('\tkey:', QKeySequence(ev.key()).toString()) def mouseMoveEvent(self, ev): @@ -206,7 +206,7 @@ class Completer(QListView): # {{{ # self.debug_event(e) - if etype == e.KeyPress: + if etype == QEvent.Type.KeyPress: try: key = e.key() except AttributeError: @@ -253,13 +253,14 @@ class Completer(QListView): # {{{ self.hide() if e.isAccepted(): return True - elif ismacos and etype == e.InputMethodQuery and e.queries() == (Qt.InputMethodQuery.ImHints | Qt.InputMethodQuery.ImEnabled) and self.isVisible(): + elif ismacos and etype == QEvent.Type.InputMethodQuery and e.queries() == ( + Qt.InputMethodQuery.ImHints | Qt.InputMethodQuery.ImEnabled) and self.isVisible(): # In Qt 5 the Esc key causes this event and the line edit does not # handle it, which causes the parent dialog to be closed # See https://bugreports.qt-project.org/browse/QTBUG-41806 e.accept() return True - elif etype == e.MouseButtonPress and hasattr(e, 'globalPos') and not self.rect().contains(self.mapFromGlobal(e.globalPos())): + elif etype == QEvent.Type.MouseButtonPress and hasattr(e, 'globalPos') and not self.rect().contains(self.mapFromGlobal(e.globalPos())): # A click outside the popup, close it if isinstance(widget, QComboBox): # This workaround is needed to ensure clicking on the drop down @@ -274,7 +275,7 @@ class Completer(QListView): # {{{ self.hide() e.accept() return True - elif etype in (e.InputMethod, e.ShortcutOverride): + elif etype in (QEvent.Type.InputMethod, QEvent.Type.ShortcutOverride): QApplication.sendEvent(widget, e) return False # }}} diff --git a/src/calibre/gui2/keyboard.py b/src/calibre/gui2/keyboard.py index 85c7ac6b29..f55264f960 100644 --- a/src/calibre/gui2/keyboard.py +++ b/src/calibre/gui2/keyboard.py @@ -12,7 +12,7 @@ from functools import partial from PyQt5.Qt import (QObject, QKeySequence, QAbstractItemModel, QModelIndex, Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame, QApplication, QSize, QRectF, QWidget, QTreeView, QHBoxLayout, QVBoxLayout, - QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon) + QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon, QEvent) try: from PyQt5 import sip except ImportError: @@ -490,10 +490,10 @@ class Editor(QFrame): # {{{ def eventFilter(self, obj, event): if self.capture and obj in (self.button1, self.button2): t = event.type() - if t == event.ShortcutOverride: + if t == QEvent.Type.ShortcutOverride: event.accept() return True - if t == event.KeyPress: + if t == QEvent.Type.KeyPress: self.key_press_event(event, 1 if obj is self.button1 else 2) return True return QFrame.eventFilter(self, obj, event) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 97be85729f..0f45097357 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -1146,7 +1146,7 @@ class GridView(QListView): return index def selectionCommand(self, index, event): - if event and event.type() == event.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.Modifier.CTRL: + if event and event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.Modifier.CTRL: return QItemSelectionModel.SelectionFlag.ClearAndSelect | QItemSelectionModel.SelectionFlag.Rows return super(GridView, self).selectionCommand(index, event) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 8cb6dc6bdb..9db22d1f77 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -1184,7 +1184,7 @@ class BooksView(QTableView): # {{{ return index def selectionCommand(self, index, event): - if event and event.type() == event.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.Modifier.CTRL: + if event and event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.Modifier.CTRL: return QItemSelectionModel.SelectionFlag.ClearAndSelect | QItemSelectionModel.SelectionFlag.Rows return super(BooksView, self).selectionCommand(index, event) diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 4c06e32ca5..ea2ebe61db 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -11,7 +11,7 @@ from functools import partial from PyQt5.Qt import ( - QComboBox, Qt, QLineEdit, pyqtSlot, QDialog, + QComboBox, Qt, QLineEdit, pyqtSlot, QDialog, QEvent, pyqtSignal, QCompleter, QAction, QKeySequence, QTimer, QIcon, QMenu, QApplication, QKeyEvent) @@ -69,7 +69,7 @@ class SearchLineEdit(QLineEdit): # {{{ def paste_and_search(self): self.paste() - ev = QKeyEvent(QKeyEvent.KeyPress, Qt.Key.Key_Enter, Qt.KeyboardModifier.NoModifier) + ev = QKeyEvent(QEvent.Type.KeyPress, Qt.Key.Key_Enter, Qt.KeyboardModifier.NoModifier) self.keyPressEvent(ev) @pyqtSlot() diff --git a/src/calibre/gui2/shortcuts.py b/src/calibre/gui2/shortcuts.py index 9711a6009b..9eafce88ac 100644 --- a/src/calibre/gui2/shortcuts.py +++ b/src/calibre/gui2/shortcuts.py @@ -11,7 +11,7 @@ from functools import partial from PyQt5.Qt import ( QAbstractListModel, Qt, QKeySequence, QListView, QVBoxLayout, QLabel, QHBoxLayout, QWidget, QApplication, QStyledItemDelegate, QStyle, QIcon, - QTextDocument, QRectF, QFrame, QSize, QFont, QKeyEvent, QRadioButton, QPushButton, QToolButton + QTextDocument, QRectF, QFrame, QSize, QFont, QKeyEvent, QRadioButton, QPushButton, QToolButton, QEvent ) from calibre.gui2 import error_dialog @@ -72,10 +72,10 @@ class Customize(QFrame): if self.capture == 0 or obj not in (self.button1, self.button2): return QFrame.eventFilter(self, obj, event) t = event.type() - if t == event.ShortcutOverride: + if t == QEvent.Type.ShortcutOverride: event.accept() return True - if t == event.KeyPress: + if t == QEvent.Type.KeyPress: self.key_press_event(event, 1 if obj is self.button1 else 2) return True return QFrame.eventFilter(self, obj, event) diff --git a/src/calibre/gui2/tag_mapper.py b/src/calibre/gui2/tag_mapper.py index 1e44057fbd..ecb7a25722 100644 --- a/src/calibre/gui2/tag_mapper.py +++ b/src/calibre/gui2/tag_mapper.py @@ -9,7 +9,7 @@ import textwrap from PyQt5.Qt import ( QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QListWidget, QIcon, QDialog, QSize, QComboBox, QLineEdit, QListWidgetItem, QStyledItemDelegate, QAbstractItemView, - QStaticText, Qt, QStyle, QToolButton, QInputDialog, QMenu, pyqtSignal + QStaticText, Qt, QStyle, QToolButton, QInputDialog, QMenu, pyqtSignal, QPalette ) from calibre.ebooks.metadata.tag_mapper import map_tags, compile_pat @@ -256,7 +256,7 @@ class Delegate(QStyledItemDelegate): def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) pal = option.palette - color = pal.color(pal.HighlightedText if option.state & QStyle.StateFlag.State_Selected else pal.Text).name() + color = pal.color(QPalette.ColorRole.HighlightedText if option.state & QStyle.StateFlag.State_Selected else QPalette.ColorRole.Text).name() text = '