From 9a1424c189b82d6a8b1f7312d63c708def1768a1 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Thu, 7 Oct 2021 18:31:51 +0300 Subject: [PATCH] qtpy based fallback for PyQt5 --- src/depends.py | 18 +++++------ src/fallback/__init__.py | 64 +++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/depends.py b/src/depends.py index f4a5157c..5774c1ac 100755 --- a/src/depends.py +++ b/src/depends.py @@ -384,25 +384,25 @@ def check_pyqt(): """ # pylint: disable=no-member try: - from fallback import qtpy + from fallback import PyQt5 except ImportError: logger.error( - 'PyBitmessage requires qtpy, PyQt 4.8 or later and Qt 4.7 or later.' - ) - qtpy = None + 'PyBitmessage requires PyQt5 or qtpy, PyQt 4.8 or later' + ' and Qt 4.7 or later.') + PyQt5 = None - if not qtpy: + if not PyQt5: return False - logger.info('PyQt Version: %s', qtpy.PYQT_VERSION) - logger.info('Qt Version: %s', qtpy.QT_VERSION) + logger.info('PyQt Version: %s', PyQt5.PYQT_VERSION) + logger.info('Qt Version: %s', PyQt5.QT_VERSION) passed = True - if version.LooseVersion(qtpy.PYQT_VERSION) < '4.8': + if version.LooseVersion(PyQt5.PYQT_VERSION) < '4.8': logger.error( 'This version of PyQt is too old. PyBitmessage requries' ' PyQt 4.8 or later.') passed = False - if version.LooseVersion(qtpy.QT_VERSION) < '4.7': + if version.LooseVersion(PyQt5.QT_VERSION) < '4.7': logger.error( 'This version of Qt is too old. PyBitmessage requries' ' Qt 4.7 or later.') diff --git a/src/fallback/__init__.py b/src/fallback/__init__.py index bd1f51b9..06998e2a 100644 --- a/src/fallback/__init__.py +++ b/src/fallback/__init__.py @@ -32,34 +32,44 @@ else: return hasher try: - import qtpy + import PyQt5 except ImportError: try: - from PyQt5 import QtCore, QtGui, QtWidgets, QtNetwork, uic + import qtpy as PyQt5 except ImportError: - qtpy = None - else: - import sys - import types + pass +else: + from PyQt5 import QtCore - QtCore.Signal = QtCore.pyqtSignal - context = { - 'API': 'pyqt5', # for tr - 'PYQT_VERSION': QtCore.PYQT_VERSION_STR, - 'QT_VERSION': QtCore.QT_VERSION_STR, - 'QtCore': QtCore, - 'QtGui': QtGui, - 'QtWidgets': QtWidgets, - 'QtNetwork': QtNetwork, - 'uic': uic - } - try: - from PyQt5 import QtTest - except ImportError: - pass - else: - context['QtTest'] = QtTest - qtpy = types.ModuleType( - 'qtpy', 'PyQt5 based dynamic fallback for qtpy') - qtpy.__dict__.update(context) - sys.modules['qtpy'] = qtpy + QtCore.Signal = QtCore.pyqtSignal + PyQt5.PYQT_VERSION = QtCore.PYQT_VERSION_STR + PyQt5.QT_VERSION = QtCore.QT_VERSION_STR + # try: + # from qtpy import QtCore, QtGui, QtWidgets, QtNetwork, uic + # except ImportError: + # PyQt5 = None + # else: + # import sys + # import types + + # QtCore.Signal = QtCore.pyqtSignal + # context = { + # 'API': 'pyqt5', # for tr + # 'PYQT_VERSION': QtCore.PYQT_VERSION_STR, + # 'QT_VERSION': QtCore.QT_VERSION_STR, + # 'QtCore': QtCore, + # 'QtGui': QtGui, + # 'QtWidgets': QtWidgets, + # 'QtNetwork': QtNetwork, + # 'uic': uic + # } + # try: + # from PyQt5 import QtTest + # except ImportError: + # pass + # else: + # context['QtTest'] = QtTest + # PyQt5 = types.ModuleType( + # 'PyQt5', 'qtpy based dynamic fallback for PyQt5') + # PyQt5.__dict__.update(context) + # sys.modules['PyQt5'] = PyQt5