Port most remaining references to PyQt5

This commit is contained in:
Kovid Goyal 2021-03-01 16:22:00 +05:30
parent dae94f64ee
commit 3b79e215e8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
32 changed files with 545 additions and 573 deletions

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import re
from PyQt5.Qt import QAction, QInputDialog
from qt.core import QAction, QInputDialog
from css_parser.css import CSSRule
# The base class that all tools must inherit from

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from PyQt5.Qt import QWidget, QHBoxLayout, QLabel, QLineEdit
from qt.core import QWidget, QHBoxLayout, QLabel, QLineEdit
from calibre.utils.config import JSONConfig

View File

@ -12,7 +12,7 @@ if False:
# You do not need this code in your plugins
get_icons = get_resources = None
from PyQt5.Qt import QDialog, QVBoxLayout, QPushButton, QMessageBox, QLabel
from qt.core import QDialog, QVBoxLayout, QPushButton, QMessageBox, QLabel
from calibre_plugins.interface_demo.config import prefs

View File

@ -3,8 +3,8 @@
# License: GPL v3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
from PyQt5.Qt import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
from qt.core import QUrl
from qt.webengine import QWebEngineView
from calibre.gui2 import Application

View File

@ -11,7 +11,7 @@ if False:
# The class that all interface action plugins must inherit from
from calibre.gui2.actions import InterfaceAction
from PyQt5.Qt import QInputDialog
from qt.core import QInputDialog
class InterfacePlugin(InterfaceAction):

View File

@ -16,5 +16,6 @@ combine_as_imports = True
line_length = 85
multi_line_output = 5
known_future_library = __python__
known_third_party = qt
known_standard_library = aes,elementmaker,encodings
known_first_party = calibre_extensions

View File

@ -9,11 +9,7 @@ import sys
from collections import namedtuple
from itertools import repeat
try:
from PyQt5 import sip
except ImportError:
import sip
from qt.core import QApplication, QEventLoop, pyqtSignal
from qt.core import QApplication, QEventLoop, pyqtSignal, sip
from qt.webengine import (
QWebEnginePage, QWebEngineProfile, QWebEngineScript
)

View File

@ -10,11 +10,7 @@ import sys, copy
from polyglot.builtins import map, range
from collections import namedtuple
from qt.core import QLinearGradient, QPointF
try:
from PyQt5 import sip
except ImportError:
import sip
from qt.core import QLinearGradient, QPointF, sip
from calibre.ebooks.pdf.render.common import Name, Array, Dictionary

View File

@ -1468,7 +1468,6 @@ if is_running_from_develop:
def event_type_name(ev_or_etype):
from PyQt5.QtCore import QEvent
etype = ev_or_etype.type() if isinstance(ev_or_etype, QEvent) else ev_or_etype
for name, num in iteritems(vars(QEvent)):
if num == etype:

View File

@ -601,7 +601,7 @@ class ChooseLibraryAction(InterfaceAction):
# from calibre.utils.mem import memory
# import weakref
# from PyQt5.Qt import QTimer
# from qt.core import QTimer
# self.dbref = weakref.ref(self.gui.library_view.model().db)
# self.before_mem = memory()
self.gui.library_moved(loc, allow_rebuild=True)

View File

@ -6,11 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from qt.core import Qt
try:
from PyQt5 import sip
except ImportError:
import sip
from qt.core import Qt, sip
from calibre.gui2.actions import InterfaceAction
from calibre.gui2.dialogs.book_info import BookInfo

View File

@ -9,11 +9,7 @@ __docformat__ = 'restructuredtext en'
from functools import partial
from qt.core import (
Qt, QAction, QMenu, QObject, QToolBar, QToolButton, QSize, pyqtSignal, QKeySequence,
QTimer, QPropertyAnimation, QEasingCurve, pyqtProperty, QPainter, QWidget, QPalette)
try:
from PyQt5 import sip
except ImportError:
import sip
QTimer, QPropertyAnimation, QEasingCurve, pyqtProperty, QPainter, QWidget, QPalette, sip)
from calibre.constants import ismacos
from calibre.gui2 import gprefs, native_menubar_defaults, config

View File

@ -21,11 +21,7 @@ from .catalog_epub_mobi_ui import Ui_Form
from qt.core import (Qt, QAbstractItemView, QCheckBox, QComboBox,
QDoubleSpinBox, QIcon, QInputDialog, QLineEdit, QRadioButton,
QSize, QSizePolicy, QTableWidget, QTableWidgetItem, QTextEdit, QToolButton,
QUrl, QVBoxLayout, QWidget)
try:
from PyQt5 import sip
except ImportError:
import sip
QUrl, QVBoxLayout, QWidget, sip)
class PluginWidget(QWidget,Ui_Form):

View File

@ -9,11 +9,7 @@ __docformat__ = 'restructuredtext en'
from qt.core import (
QLineEdit, QAbstractListModel, Qt, pyqtSignal, QObject, QKeySequence, QAbstractItemView,
QApplication, QListView, QPoint, QModelIndex, QEvent,
QStyleOptionComboBox, QStyle, QComboBox, QTimer)
try:
from PyQt5 import sip
except ImportError:
import sip
QStyleOptionComboBox, QStyle, QComboBox, QTimer, sip)
from calibre.constants import ismacos
from calibre.utils.icu import sort_key, primary_startswith, primary_contains

View File

@ -15,13 +15,9 @@ from qt.core import (
QImageReader, QFormLayout, QVBoxLayout, QSplitter, QGroupBox, QListWidget,
QLineEdit, QSpinBox, QTextEdit, QSize, QListWidgetItem, QIcon, QImage,
pyqtSignal, QStackedLayout, QWidget, QLabel, Qt, QComboBox, QPixmap, QDialog,
QGridLayout, QStyledItemDelegate, QApplication, QStaticText,
QGridLayout, QStyledItemDelegate, QApplication, QStaticText, sip,
QStyle, QPen, QProgressDialog, QAbstractItemView, QDialogButtonBox
)
try:
from PyQt5 import sip
except ImportError:
import sip
from calibre import walk, fit_image, human_readable, detect_ncpus as cpu_count
from calibre.constants import cache_dir, config_dir

View File

@ -43,7 +43,7 @@ class Pointer(QWidget):
self.color.setAlpha(100)
self.brush = QBrush(self.color, Qt.BrushStyle.SolidPattern)
# from PyQt5.Qt import QTimer
# from qt.core import QTimer
# QTimer.singleShot(1000, self.start)
@property

View File

@ -12,11 +12,7 @@ from functools import partial
from qt.core import (QObject, QKeySequence, QAbstractItemModel, QModelIndex, QItemSelectionModel,
Qt, QStyledItemDelegate, QTextDocument, QStyle, pyqtSignal, QFrame, QAbstractItemView,
QApplication, QSize, QRectF, QWidget, QTreeView, QHBoxLayout, QVBoxLayout, QAbstractItemDelegate,
QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon, QEvent)
try:
from PyQt5 import sip
except ImportError:
import sip
QGridLayout, QLabel, QRadioButton, QPushButton, QToolButton, QIcon, QEvent, sip)
from calibre.utils.config import JSONConfig
from calibre.constants import DEBUG

View File

@ -361,7 +361,7 @@ class MainWindowMixin(object): # {{{
try:
self.setUnifiedTitleAndToolBarOnMac(True)
except AttributeError:
pass # PyQt5 seems to be missing this property
pass # PyQt seems to be missing this property
# And now, start adding the real widgets
l.addWidget(self.search_bar)

View File

@ -12,12 +12,8 @@ from glob import glob
from qt.core import (
QDialog, QApplication, QLabel, QVBoxLayout, QDialogButtonBox, Qt, QAbstractItemView, QListView,
pyqtSignal, QListWidget, QListWidgetItem, QSize, QPixmap, QStyledItemDelegate
pyqtSignal, QListWidget, QListWidgetItem, QSize, QPixmap, QStyledItemDelegate, sip
)
try:
from PyQt5 import sip
except ImportError:
import sip
from calibre import as_unicode
from calibre.ebooks.metadata.pdf import page_images

View File

@ -14,7 +14,7 @@ from qt.core import (
QCheckBox, QComboBox, QDialog, QDialogButtonBox, QDoubleSpinBox, QFormLayout,
QFrame, QHBoxLayout, QIcon, QLabel, QLineEdit, QListWidget, QPlainTextEdit, QLayout,
QPushButton, QScrollArea, QSize, QSizePolicy, QSpinBox, Qt, QTabWidget, QTimer,
QToolButton, QUrl, QVBoxLayout, QWidget, pyqtSignal
QToolButton, QUrl, QVBoxLayout, QWidget, pyqtSignal, sip
)
from calibre import as_unicode
@ -37,11 +37,6 @@ from calibre.utils.icu import primary_sort_key
from calibre.utils.shared_file import share_open
from polyglot.builtins import as_bytes, unicode_type
try:
from PyQt5 import sip
except ImportError:
import sip
if iswindows and not isportable:
from calibre_extensions import winutil

View File

@ -14,7 +14,7 @@ from qt.core import (
QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget, QAbstractItemView,
QListWidgetItem, QMenu, QPainter, QPixmap, QRadioButton, QScrollArea, QSize,
QSpinBox, QStyle, QStyledItemDelegate, Qt, QTimer, QTreeWidget, QTreeWidgetItem,
QVBoxLayout, QWidget, pyqtSignal
QVBoxLayout, QWidget, pyqtSignal, sip
)
from calibre import human_readable, sanitize_file_name
@ -42,11 +42,6 @@ from calibre_extensions.progress_indicator import set_no_activate_on_click
from polyglot.binary import as_hex_unicode
from polyglot.builtins import filter, iteritems, map, range, unicode_type
try:
from PyQt5 import sip
except ImportError:
import sip
FILE_COPY_MIME = 'application/calibre-edit-book-files'
TOP_ICON_SIZE = 24

View File

@ -10,7 +10,7 @@ from itertools import count
from qt.core import (
QT_VERSION, QApplication, QBuffer, QByteArray, QEvent, QFontDatabase, QFontInfo,
QHBoxLayout, QIODevice, QLocale, QMimeData, QPalette, QSize, Qt, QTimer, QUrl,
QWidget, pyqtSignal
QWidget, pyqtSignal, sip
)
from qt.webengine import (
QWebEngineUrlRequestInfo, QWebEngineUrlRequestJob, QWebEngineUrlSchemeHandler
@ -41,11 +41,6 @@ from calibre.utils.shared_file import share_open
from polyglot.builtins import as_bytes, iteritems, unicode_type
from polyglot.functools import lru_cache
try:
from PyQt5 import sip
except ImportError:
import sip
SANDBOX_HOST = FAKE_HOST.rpartition('.')[0] + '.sandbox'
# Override network access to load data from the book {{{

View File

@ -286,11 +286,11 @@ class BuildTest(unittest.TestCase):
@unittest.skipIf('SKIP_QT_BUILD_TEST' in os.environ, 'Skipping Qt build test as it causes crashes in the macOS VM')
def test_qt(self):
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication
from qt.core import QTimer
from qt.core import QApplication
from qt.webengine import QWebEnginePage
from PyQt5.QtGui import QImageReader, QFontDatabase
from PyQt5.QtNetwork import QNetworkAccessManager
from qt.core import QImageReader, QFontDatabase
from qt.core import QNetworkAccessManager
from calibre.utils.img import image_from_data, image_to_data, test
# Ensure that images can be read before QApplication is constructed.
# Note that this requires QCoreApplication.libraryPaths() to return the

View File

@ -10,10 +10,9 @@ import subprocess
import sys
import tempfile
from io import BytesIO
# We use explicit module imports so tracebacks when importing are more useful
from PyQt5.QtCore import QBuffer, QByteArray, Qt, QIODevice
from PyQt5.QtGui import (
QColor, QImage, QImageReader, QImageWriter, QPixmap, QTransform
from qt.core import (
QBuffer, QByteArray, QColor, QImage, QImageReader, QImageWriter, QIODevice,
QPixmap, Qt, QTransform
)
from threading import Thread

View File

@ -6,6 +6,8 @@ import importlib
import os
from pprint import pprint
QT_WRAPPER = 'PyQt5'
base = os.path.dirname(os.path.abspath(__file__))
module_lists = {
'core': (
@ -29,8 +31,8 @@ def scan(name):
name_map = {}
types = []
for mod_name in module_names:
mod = importlib.import_module(f'PyQt5.{mod_name}')
full_name = mod.__name__
mod = importlib.import_module(f'{QT_WRAPPER}.{mod_name}')
full_name = name_map[mod_name] = mod.__name__
types.append(f'import {full_name}')
for obj_name in sorted(dir(mod)):
if not obj_name.startswith('_') and obj_name not in name_map:
@ -38,11 +40,19 @@ def scan(name):
types.append(f'{obj_name} = {full_name}.{obj_name}')
with open(f'{base}/{name}.pyi', 'w') as f:
print('# autogenerated by __main__.py do not edit', file=f)
f.write('\n'.join(sorted(types)))
f.write('\n'.join(types))
if name == 'core':
module_names += ('sip',)
mod = importlib.import_module(f'{QT_WRAPPER}.sip')
name_map['sip'] = mod.__name__
name_map['QtWin'] = f'{QT_WRAPPER}.QtWinExtras'
with open(f'{base}/{name}_name_map.py', 'w') as f:
print('# autogenerated by __main__.py do not edit', file=f)
print('name_map =', end=' ', file=f)
pprint(name_map, stream=f)
print('module_names = frozenset(', end='', file=f)
pprint(module_names, stream=f)
print(')', file=f)
for name in ('core', 'webengine'):

View File

@ -4,11 +4,11 @@
from .loader import dynamic_load
from .core_name_map import name_map
from .core_name_map import name_map, module_names
already_imported = {}
qt_modules = {}
def __getattr__(name):
return dynamic_load(name, name_map, already_imported, qt_modules)
return dynamic_load(name, name_map, already_imported, qt_modules, module_names)

File diff suppressed because it is too large Load Diff

View File

@ -605,13 +605,20 @@ name_map = {'PYQT_CONFIGURATION': 'PyQt5.QtCore',
'Q_FLAGS': 'PyQt5.QtCore',
'Q_RETURN_ARG': 'PyQt5.QtCore',
'Qt': 'PyQt5.QtCore',
'QtCore': 'PyQt5.QtCore',
'QtCriticalMsg': 'PyQt5.QtCore',
'QtDebugMsg': 'PyQt5.QtCore',
'QtFatalMsg': 'PyQt5.QtCore',
'QtGui': 'PyQt5.QtGui',
'QtInfoMsg': 'PyQt5.QtCore',
'QtMsgType': 'PyQt5.QtCore',
'QtNetwork': 'PyQt5.QtNetwork',
'QtPrintSupport': 'PyQt5.QtPrintSupport',
'QtSvg': 'PyQt5.QtSvg',
'QtSystemMsg': 'PyQt5.QtCore',
'QtWarningMsg': 'PyQt5.QtCore',
'QtWidgets': 'PyQt5.QtWidgets',
'QtWin': 'PyQt5.QtWinExtras',
'bin_': 'PyQt5.QtCore',
'bom': 'PyQt5.QtCore',
'center': 'PyQt5.QtCore',
@ -705,6 +712,9 @@ name_map = {'PYQT_CONFIGURATION': 'PyQt5.QtCore',
'right': 'PyQt5.QtCore',
'scientific': 'PyQt5.QtCore',
'showbase': 'PyQt5.QtCore',
'sip': 'PyQt5.sip',
'uppercasebase': 'PyQt5.QtCore',
'uppercasedigits': 'PyQt5.QtCore',
'ws': 'PyQt5.QtCore'}
module_names = frozenset(('QtCore', 'QtGui', 'QtWidgets', 'QtNetwork', 'QtSvg', 'QtPrintSupport', 'sip')
)

View File

@ -6,7 +6,7 @@ from importlib import import_module
import sys
def dynamic_load(name, name_map, already_imported, qt_modules):
def dynamic_load(name, name_map, already_imported, qt_modules, module_names=()):
ans = already_imported.get(name, already_imported)
if ans is not already_imported:
return ans
@ -26,7 +26,10 @@ def dynamic_load(name, name_map, already_imported, qt_modules):
file=sys.stderr
)
if mod is not False:
q = getattr(mod, name, qt_modules)
if name in module_names:
q = mod
else:
q = getattr(mod, name, qt_modules)
if q is not qt_modules:
already_imported[name] = q
return q

View File

@ -4,11 +4,11 @@
from .loader import dynamic_load
from .webengine_name_map import name_map
from .webengine_name_map import name_map, module_names
already_imported = {}
qt_modules = {}
def __getattr__(name):
return dynamic_load(name, name_map, already_imported, qt_modules)
return dynamic_load(name, name_map, already_imported, qt_modules, module_names)

View File

@ -1,35 +1,33 @@
# autogenerated by __main__.py do not edit
import PyQt5.QtWebEngine
PYQT_WEBENGINE_VERSION = PyQt5.QtWebEngine.PYQT_WEBENGINE_VERSION
PYQT_WEBENGINE_VERSION_STR = PyQt5.QtWebEngine.PYQT_WEBENGINE_VERSION_STR
QQuickWebEngineProfile = PyQt5.QtWebEngine.QQuickWebEngineProfile
QQuickWebEngineScript = PyQt5.QtWebEngine.QQuickWebEngineScript
QWebEngineCertificateError = PyQt5.QtWebEngineWidgets.QWebEngineCertificateError
QWebEngineClientCertificateSelection = PyQt5.QtWebEngineWidgets.QWebEngineClientCertificateSelection
import PyQt5.QtWebEngineCore
QWebEngineClientCertificateStore = PyQt5.QtWebEngineCore.QWebEngineClientCertificateStore
QWebEngineContextMenuData = PyQt5.QtWebEngineWidgets.QWebEngineContextMenuData
QWebEngineCookieStore = PyQt5.QtWebEngineCore.QWebEngineCookieStore
QWebEngineDownloadItem = PyQt5.QtWebEngineWidgets.QWebEngineDownloadItem
QWebEngineFindTextResult = PyQt5.QtWebEngineCore.QWebEngineFindTextResult
QWebEngineFullScreenRequest = PyQt5.QtWebEngineWidgets.QWebEngineFullScreenRequest
QWebEngineHistory = PyQt5.QtWebEngineWidgets.QWebEngineHistory
QWebEngineHistoryItem = PyQt5.QtWebEngineWidgets.QWebEngineHistoryItem
QWebEngineHttpRequest = PyQt5.QtWebEngineCore.QWebEngineHttpRequest
QWebEngineNotification = PyQt5.QtWebEngineCore.QWebEngineNotification
QWebEnginePage = PyQt5.QtWebEngineWidgets.QWebEnginePage
QWebEngineProfile = PyQt5.QtWebEngineWidgets.QWebEngineProfile
QWebEngineQuotaRequest = PyQt5.QtWebEngineCore.QWebEngineQuotaRequest
QWebEngineRegisterProtocolHandlerRequest = PyQt5.QtWebEngineCore.QWebEngineRegisterProtocolHandlerRequest
QWebEngineScript = PyQt5.QtWebEngineWidgets.QWebEngineScript
QWebEngineScriptCollection = PyQt5.QtWebEngineWidgets.QWebEngineScriptCollection
QWebEngineSettings = PyQt5.QtWebEngineWidgets.QWebEngineSettings
QWebEngineUrlRequestInfo = PyQt5.QtWebEngineCore.QWebEngineUrlRequestInfo
QWebEngineUrlRequestInterceptor = PyQt5.QtWebEngineCore.QWebEngineUrlRequestInterceptor
QWebEngineUrlRequestJob = PyQt5.QtWebEngineCore.QWebEngineUrlRequestJob
QWebEngineUrlScheme = PyQt5.QtWebEngineCore.QWebEngineUrlScheme
QWebEngineUrlSchemeHandler = PyQt5.QtWebEngineCore.QWebEngineUrlSchemeHandler
QWebEngineView = PyQt5.QtWebEngineWidgets.QWebEngineView
QtWebEngine = PyQt5.QtWebEngine.QtWebEngine
QtWebEngineCore = PyQt5.QtWebEngineCore.QtWebEngineCore
import PyQt5.QtWebEngine
import PyQt5.QtWebEngineCore
import PyQt5.QtWebEngineWidgets
import PyQt5.QtWebEngineWidgets
QWebEngineCertificateError = PyQt5.QtWebEngineWidgets.QWebEngineCertificateError
QWebEngineClientCertificateSelection = PyQt5.QtWebEngineWidgets.QWebEngineClientCertificateSelection
QWebEngineContextMenuData = PyQt5.QtWebEngineWidgets.QWebEngineContextMenuData
QWebEngineDownloadItem = PyQt5.QtWebEngineWidgets.QWebEngineDownloadItem
QWebEngineFullScreenRequest = PyQt5.QtWebEngineWidgets.QWebEngineFullScreenRequest
QWebEngineHistory = PyQt5.QtWebEngineWidgets.QWebEngineHistory
QWebEngineHistoryItem = PyQt5.QtWebEngineWidgets.QWebEngineHistoryItem
QWebEnginePage = PyQt5.QtWebEngineWidgets.QWebEnginePage
QWebEngineProfile = PyQt5.QtWebEngineWidgets.QWebEngineProfile
QWebEngineScript = PyQt5.QtWebEngineWidgets.QWebEngineScript
QWebEngineScriptCollection = PyQt5.QtWebEngineWidgets.QWebEngineScriptCollection
QWebEngineSettings = PyQt5.QtWebEngineWidgets.QWebEngineSettings
QWebEngineView = PyQt5.QtWebEngineWidgets.QWebEngineView

View File

@ -29,4 +29,7 @@ name_map = {'PYQT_WEBENGINE_VERSION': 'PyQt5.QtWebEngine',
'QWebEngineUrlSchemeHandler': 'PyQt5.QtWebEngineCore',
'QWebEngineView': 'PyQt5.QtWebEngineWidgets',
'QtWebEngine': 'PyQt5.QtWebEngine',
'QtWebEngineCore': 'PyQt5.QtWebEngineCore'}
'QtWebEngineCore': 'PyQt5.QtWebEngineCore',
'QtWebEngineWidgets': 'PyQt5.QtWebEngineWidgets'}
module_names = frozenset(('QtWebEngine', 'QtWebEngineCore', 'QtWebEngineWidgets')
)