diff --git a/src/bitmessageqt/support.py b/src/bitmessageqt/support.py index 92a5d112..08125446 100644 --- a/src/bitmessageqt/support.py +++ b/src/bitmessageqt/support.py @@ -145,7 +145,7 @@ def createSupportMessage(myapp): opensslversion = "%s (Python internal), %s (external for PyElliptic)" % ( ssl.OPENSSL_VERSION, OpenSSL._version) - qtapi = os.environ['QT_API'] + qtapi = os.environ.get('QT_API', 'fallback') frozen = "N/A" if paths.frozen: diff --git a/src/depends.py b/src/depends.py index 9cff1b22..113c8895 100755 --- a/src/depends.py +++ b/src/depends.py @@ -383,9 +383,13 @@ def check_pyqt(): PyQt 4.8 or later. """ # pylint: disable=no-member - qtpy = try_import( - 'qtpy', - 'PyBitmessage requires qtpy, PyQt 4.8 or later and Qt 4.7 or later.') + try: + from fallback import qtpy + except ImportError: + logger.error( + 'PyBitmessage requires qtpy, PyQt 4.8 or later and Qt 4.7 or later.' + ) + qtpy = None if not qtpy: return False diff --git a/src/fallback/__init__.py b/src/fallback/__init__.py index 9a8d646f..bd1f51b9 100644 --- a/src/fallback/__init__.py +++ b/src/fallback/__init__.py @@ -30,3 +30,36 @@ else: if data: hasher.update(data) return hasher + +try: + import qtpy +except ImportError: + try: + from PyQt5 import QtCore, QtGui, QtWidgets, QtNetwork, uic + except ImportError: + qtpy = 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 + qtpy = types.ModuleType( + 'qtpy', 'PyQt5 based dynamic fallback for qtpy') + qtpy.__dict__.update(context) + sys.modules['qtpy'] = qtpy