[Pkg-bitcoin-commits] [python-quamash] 105/269: Support PyQt4
Jonas Smedegaard
dr at jones.dk
Fri Nov 24 11:26:21 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository python-quamash.
commit 0f8dd57ec4b28ec340fe16ad16ec6b91f6c8331e
Author: Mark Harviston <mark.harviston at gmail.com>
Date: Sun Jul 20 21:17:51 2014 -0700
Support PyQt4
---
quamash/__init__.py | 46 ++++++++++++++++++++++++++++------------------
quamash/_common.py | 5 -----
quamash/_unix.py | 2 +-
quamash/_windows.py | 3 ++-
tests/test_qeventloop.py | 13 ++++---------
5 files changed, 35 insertions(+), 34 deletions(-)
diff --git a/quamash/__init__.py b/quamash/__init__.py
index f9831b1..f88f9f0 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -16,23 +16,29 @@ from functools import wraps
from queue import Queue
from concurrent.futures import Future
+for QtModuleName in ('PyQt5', 'PyQt4', 'PySide'):
+ try:
+ QtModule = __import__(QtModuleName)
+ except ImportError:
+ continue
+ else:
+ break
+else:
+ raise ImportError('No Qt implementations found')
+
+QtCore = __import__(QtModuleName + '.QtCore', fromlist=(QtModuleName,))
+
try:
- from PyQt5 import QtCore
- QtCore.Signal = QtCore.pyqtSignal
+ QtGui = __import__(QtModuleName + '.QtGui', fromlist=(QtModuleName,))
except ImportError:
- from PySide import QtCore
+ QtGui = __import__(QtModuleName + '.QtWidgets', fromlist=(QtModuleName,))
-from ._common import with_logger
+if not hasattr(QtCore, 'Signal'):
+ QtCore.Signal = QtCore.pyqtSignal
-def _get_test_app():
- """Helper function to get an app instance."""
- try:
- from PyQt5.QtWidgets import QApplication
- except ImportError:
- from PySide.QtGui import QApplication
- return QtCore.QCoreApplication.instance() or QApplication([])
+from ._common import with_logger
@with_logger
@@ -148,12 +154,13 @@ def _easycallback(fn):
Remember: only objects that inherit from QObject can support signals/slots
- >>> try: from PyQt5.QtCore import QThread, QObject
- ... except ImportError: from PySide.QtCore import QThread, QObject
+ >>> import asyncio
>>>
>>> import quamash
- >>> from quamash import QEventLoop, _easycallback
- >>> import asyncio
+ >>> from quamash import QEventLoop, QtCore, QtGui
+ >>> QThread, QObject = quamash.QtCore.QThread, quamash.QtCore.QObject
+ >>>
+ >>> app = QtCore.QCoreApplication.instance() or QtGui.QApplication([])
>>>
>>> global_thread = QThread.currentThread()
>>> class MyObject(QObject):
@@ -173,7 +180,7 @@ def _easycallback(fn):
... def mycoroutine():
... myobject.mycallback()
>>>
- >>> loop = QEventLoop(quamash._get_test_app())
+ >>> loop = QEventLoop(app)
>>> with loop:
... loop.run_until_complete(mycoroutine())
"""
@@ -201,7 +208,10 @@ else:
class QEventLoop(_baseclass):
"""
Implementation of asyncio event loop that uses the Qt Event loop
+
>>> import quamash, asyncio
+ >>> from quamash import QtCore, QtGui
+ >>> app = QtCore.QCoreApplication.instance() or QtGui.QApplication([])
>>>
>>> @asyncio.coroutine
... def xplusy(x, y):
@@ -209,8 +219,8 @@ class QEventLoop(_baseclass):
... assert x + y == 4
... yield from asyncio.sleep(.1)
>>>
- >>> with QEventLoop(quamash._get_test_app()) as loop:
- ... loop.run_until_complete(xplusy(2,2))
+ >>> with QEventLoop(app) as loop:
+ ... loop.run_until_complete(xplusy(2, 2))
"""
def __init__(self, app=None):
self.__timers = []
diff --git a/quamash/_common.py b/quamash/_common.py
index 5a91a1a..16c9090 100644
--- a/quamash/_common.py
+++ b/quamash/_common.py
@@ -2,11 +2,6 @@
# © 2014 Arve Knudsen <arve.knudsen at gmail.com>
# BSD License
import logging
-try:
- from PySide import QtCore
-except ImportError:
- from PyQt5 import QtCore
- QtCore.Signal = QtCore.pyqtSignal
def with_logger(cls):
diff --git a/quamash/_unix.py b/quamash/_unix.py
index 23825d2..dbf6985 100644
--- a/quamash/_unix.py
+++ b/quamash/_unix.py
@@ -5,7 +5,7 @@ import asyncio
from asyncio import selectors
import collections
-from ._common import QtCore, with_logger
+from . import QtCore, with_logger
EVENT_READ = (1 << 0)
diff --git a/quamash/_windows.py b/quamash/_windows.py
index 5e11abf..95f49fc 100644
--- a/quamash/_windows.py
+++ b/quamash/_windows.py
@@ -11,7 +11,8 @@ except ImportError: # noqa
import math
-from ._common import with_logger, QtCore
+from . import QtCore
+from ._common import with_logger
class _ProactorEventLoop(QtCore.QObject, asyncio.ProactorEventLoop):
diff --git a/tests/test_qeventloop.py b/tests/test_qeventloop.py
index 1b7eb5b..d1c1c5f 100644
--- a/tests/test_qeventloop.py
+++ b/tests/test_qeventloop.py
@@ -9,16 +9,12 @@ import ctypes
import multiprocessing
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
-try:
- from PyQt5.QtWidgets import QApplication
- from PyQt5.QtCore import QCoreApplication
-except ImportError:
- from PySide.QtGui import QApplication
- from PySide.QtCore import QCoreApplication
-import pytest
+from quamash import QtCore, QtGui
import quamash
+import pytest
+
class _SubprocessProtocol(asyncio.SubprocessProtocol):
def __init__(self, *args, **kwds):
@@ -36,8 +32,7 @@ class _SubprocessProtocol(asyncio.SubprocessProtocol):
@pytest.fixture(scope='session')
def application():
- app = QCoreApplication.instance() or QApplication([])
- return app
+ return QtCore.QCoreApplication.instance() or QtGui.QApplication([])
@pytest.fixture
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git
More information about the Pkg-bitcoin-commits
mailing list