From e97a05c50a49bbb0ad4e1aae98a942dcde96987f Mon Sep 17 00:00:00 2001 From: Joseph Martinot-Lagarde Date: Sat, 11 Jun 2016 01:02:45 +0200 Subject: [PATCH 1/4] Ignore case for QT_API env variable --- qtpy/QtCore.py | 10 ++++------ qtpy/QtDesigner.py | 8 +++----- qtpy/QtGui.py | 10 ++++------ qtpy/QtNetwork.py | 10 ++++------ qtpy/QtPrintSupport.py | 10 ++++------ qtpy/QtSvg.py | 10 ++++------ qtpy/QtTest.py | 10 ++++------ qtpy/QtWebEngineWidgets.py | 10 ++++------ qtpy/QtWidgets.py | 11 +++++------ qtpy/__init__.py | 28 +++++++++++++--------------- qtpy/compat.py | 4 ++-- tests/test_main.py | 4 ++-- 12 files changed, 53 insertions(+), 72 deletions(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index 324d8989..06e14f29 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -10,22 +10,20 @@ Provides QtCore classes and functions. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtCore import * from PyQt5.QtCore import pyqtSignal as Signal from PyQt5.QtCore import pyqtSlot as Slot from PyQt5.QtCore import pyqtProperty as Property from PyQt5.QtCore import QT_VERSION_STR as __version__ -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtCore import * from PyQt4.QtCore import QCoreApplication from PyQt4.QtCore import Qt @@ -35,7 +33,7 @@ from PyQt4.QtGui import (QItemSelection, QItemSelectionModel, QItemSelectionRange, QSortFilterProxyModel) from PyQt4.QtCore import QT_VERSION_STR as __version__ -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtCore import * from PySide.QtGui import (QItemSelection, QItemSelectionModel, QItemSelectionRange, QSortFilterProxyModel) diff --git a/qtpy/QtDesigner.py b/qtpy/QtDesigner.py index fc7bd8c6..7d224f32 100644 --- a/qtpy/QtDesigner.py +++ b/qtpy/QtDesigner.py @@ -9,17 +9,15 @@ Provides QtDesigner classes and functions. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtDesigner import * -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtDesigner import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 213901d2..d400aa09 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -13,18 +13,16 @@ the ``PyQt5.QtGui`` module. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtGui import * -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.Qt import QKeySequence, QTextCursor from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard, QCloseEvent, QColor, @@ -65,7 +63,7 @@ QWindowStateChangeEvent, qAlpha, qBlue, qFuzzyCompare, qGray, qGreen, qIsGray, qRed, qRgb, qRgba, QIntValidator) -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard, QCloseEvent, QColor, QConicalGradient, QContextMenuEvent, QCursor, diff --git a/qtpy/QtNetwork.py b/qtpy/QtNetwork.py index d9056389..06eba160 100644 --- a/qtpy/QtNetwork.py +++ b/qtpy/QtNetwork.py @@ -10,20 +10,18 @@ Provides QtNetwork classes and functions. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtNetwork import * -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtNetwork import * -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtNetwork import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py index d728b61f..da5e8aef 100644 --- a/qtpy/QtPrintSupport.py +++ b/qtpy/QtPrintSupport.py @@ -9,22 +9,20 @@ Provides QtPrintSupport classes and functions. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtPrintSupport import * -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtGui import (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine, QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo) -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtGui import (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine, QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo) diff --git a/qtpy/QtSvg.py b/qtpy/QtSvg.py index 4aca0186..11272dac 100644 --- a/qtpy/QtSvg.py +++ b/qtpy/QtSvg.py @@ -8,20 +8,18 @@ Provides QtSvg classes and functions. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtSvg import * -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtSvg import * -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtSvg import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtTest.py b/qtpy/QtTest.py index 0f911602..630d41d4 100644 --- a/qtpy/QtTest.py +++ b/qtpy/QtTest.py @@ -12,25 +12,23 @@ running with PySide. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: from PyQt5.QtTest import QTest -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtTest import QTest as OldQTest class QTest(OldQTest): @staticmethod def qWaitForWindowActive(QWidget): OldQTest.qWaitForWindowShown(QWidget) -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: raise ImportError('QtTest support is incomplete for PySide') else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtWebEngineWidgets.py b/qtpy/QtWebEngineWidgets.py index c1a6b779..8df87871 100644 --- a/qtpy/QtWebEngineWidgets.py +++ b/qtpy/QtWebEngineWidgets.py @@ -10,9 +10,7 @@ Provides QtWebEngineWidgets classes and functions. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API @@ -23,7 +21,7 @@ WEBENGINE = True -if os.environ[QT_API] in PYQT5_API: +if API in PYQT5_API: try: from PyQt5.QtWebEngineWidgets import QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEngineView @@ -33,12 +31,12 @@ from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings WEBENGINE = False -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtWebKit import QWebPage as QWebEnginePage from PyQt4.QtWebKit import QWebView as QWebEngineView from PyQt4.QtWebKit import QWebSettings as QWebEngineSettings WEBENGINE = False -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtWebKit import QWebPage as QWebEnginePage from PySide.QtWebKit import QWebView as QWebEngineView from PySide.QtWebKit import QWebSettings as QWebEngineSettings diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index 2e150456..6f2fa8c7 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -13,18 +13,17 @@ were the ``PyQt5.QtWidgets`` module. """ -import os - -from qtpy import QT_API +from qtpy import API from qtpy import PYQT5_API from qtpy import PYQT4_API from qtpy import PYSIDE_API from qtpy import PythonQtError from qtpy._patch.qcombobox import patch_qcombobox -if os.environ[QT_API] in PYQT5_API: + +if API in PYQT5_API: from PyQt5.QtWidgets import * -elif os.environ[QT_API] in PYQT4_API: +elif API in PYQT4_API: from PyQt4.QtGui import * QStyleOptionViewItem = QStyleOptionViewItemV4 @@ -69,7 +68,7 @@ # Patch QComboBox to allow Python objects to be passed to userData patch_qcombobox(QComboBox) -elif os.environ[QT_API] in PYSIDE_API: +elif API in PYSIDE_API: from PySide.QtGui import * QStyleOptionViewItem = QStyleOptionViewItemV4 diff --git a/qtpy/__init__.py b/qtpy/__init__.py index 8ab8a204..d5f0e25c 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -64,12 +64,8 @@ #: names of the expected PySide api PYSIDE_API = ['pyside'] -os.environ.setdefault(QT_API, 'pyqt5') -assert os.environ[QT_API] in (PYQT5_API + PYQT4_API + PYSIDE_API) - -API = os.environ[QT_API] -API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4', - 'pyside': 'PySide'}[API] +API = os.environ.get(QT_API, 'pyqt5').lower() +assert API in (PYQT5_API + PYQT4_API + PYSIDE_API) is_old_pyqt = is_pyqt46 = False PYQT5 = True @@ -86,8 +82,7 @@ class PythonQtError(Exception): from PyQt5.QtCore import PYQT_VERSION_STR as __version__ from PyQt5 import uic # analysis:ignore except ImportError: - API = os.environ['QT_API'] = 'pyqt' - API_NAME = 'PyQt4' + API = 'pyqt' if API in PYQT4_API: try: @@ -109,16 +104,10 @@ class PythonQtError(Exception): PYQT5 = False PYQT4 = True except ImportError: - API = os.environ['QT_API'] = 'pyside' - API_NAME = 'PySide' + API = 'pyside' else: is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7')) is_pyqt46 = __version__.startswith('4.6') - import sip - try: - API_NAME += (" (API v{0})".format(sip.getapi('QString'))) - except AttributeError: - pass if API in PYSIDE_API: try: @@ -127,3 +116,12 @@ class PythonQtError(Exception): PYSIDE = True except ImportError: raise PythonQtError('No Qt bindings could be found') + +API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4', + 'pyside': 'PySide'}[API] +if API in PYQT4_API: + import sip + try: + API_NAME += (" (API v{0})".format(sip.getapi('QString'))) + except AttributeError: + pass diff --git a/qtpy/compat.py b/qtpy/compat.py index e15beef4..5bbbd67f 100644 --- a/qtpy/compat.py +++ b/qtpy/compat.py @@ -8,10 +8,10 @@ """ from __future__ import print_function -import os import sys import collections +from qtpy import API, PYQT4_API from qtpy.QtWidgets import QFileDialog from qtpy.py3compat import is_text_string, to_text_string, TEXT_TYPES @@ -20,7 +20,7 @@ # QVariant conversion utilities # ============================================================================= PYQT_API_1 = False -if os.environ['QT_API'] == 'pyqt': +if API in PYQT4_API: import sip try: PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1 diff --git a/tests/test_main.py b/tests/test_main.py index cfa578ab..63d1439e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,6 +2,7 @@ from qtpy import QtCore, QtGui, QtWidgets, QtWebEngineWidgets + def assert_pyside(): """ Make sure that we are using PySide @@ -38,13 +39,12 @@ def assert_pyqt5(): assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebKitWidgets.QWebPage - def test_qt_api(): """ If QT_API is specified, we check that the correct Qt wrapper was used """ - QT_API = os.environ.get('QT_API') + QT_API = os.environ.get('QT_API', '').lower() if QT_API == 'pyside': assert_pyside() From 0798484c03dc5aa9565f0c5bed8fd5ef5c4f58de Mon Sep 17 00:00:00 2001 From: Joseph Martinot-Lagarde Date: Sat, 11 Jun 2016 01:17:30 +0200 Subject: [PATCH 2/4] Use the already defined constants to differentiate between Qt apis. --- qtpy/QtCore.py | 13 ++++++------- qtpy/QtDesigner.py | 9 ++++----- qtpy/QtGui.py | 13 ++++++------- qtpy/QtNetwork.py | 13 ++++++------- qtpy/QtPrintSupport.py | 13 ++++++------- qtpy/QtSvg.py | 13 ++++++------- qtpy/QtTest.py | 13 ++++++------- qtpy/QtWebEngineWidgets.py | 13 ++++++------- qtpy/QtWidgets.py | 13 ++++++------- qtpy/compat.py | 4 ++-- 10 files changed, 54 insertions(+), 63 deletions(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index 06e14f29..c99b5a11 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -10,20 +10,19 @@ Provides QtCore classes and functions. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtCore import * from PyQt5.QtCore import pyqtSignal as Signal from PyQt5.QtCore import pyqtSlot as Slot from PyQt5.QtCore import pyqtProperty as Property from PyQt5.QtCore import QT_VERSION_STR as __version__ -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtCore import * from PyQt4.QtCore import QCoreApplication from PyQt4.QtCore import Qt @@ -33,7 +32,7 @@ from PyQt4.QtGui import (QItemSelection, QItemSelectionModel, QItemSelectionRange, QSortFilterProxyModel) from PyQt4.QtCore import QT_VERSION_STR as __version__ -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtCore import * from PySide.QtGui import (QItemSelection, QItemSelectionModel, QItemSelectionRange, QSortFilterProxyModel) diff --git a/qtpy/QtDesigner.py b/qtpy/QtDesigner.py index 7d224f32..980bd578 100644 --- a/qtpy/QtDesigner.py +++ b/qtpy/QtDesigner.py @@ -9,15 +9,14 @@ Provides QtDesigner classes and functions. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API +from qtpy import PYQT5 +from qtpy import PYQT4 from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtDesigner import * -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtDesigner import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index d400aa09..728571a9 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -13,16 +13,15 @@ the ``PyQt5.QtGui`` module. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtGui import * -elif API in PYQT4_API: +elif PYQT4: from PyQt4.Qt import QKeySequence, QTextCursor from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard, QCloseEvent, QColor, @@ -63,7 +62,7 @@ QWindowStateChangeEvent, qAlpha, qBlue, qFuzzyCompare, qGray, qGreen, qIsGray, qRed, qRgb, qRgba, QIntValidator) -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap, QBrush, QClipboard, QCloseEvent, QColor, QConicalGradient, QContextMenuEvent, QCursor, diff --git a/qtpy/QtNetwork.py b/qtpy/QtNetwork.py index 06eba160..d7d24d5a 100644 --- a/qtpy/QtNetwork.py +++ b/qtpy/QtNetwork.py @@ -10,18 +10,17 @@ Provides QtNetwork classes and functions. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtNetwork import * -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtNetwork import * -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtNetwork import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py index da5e8aef..95f9a531 100644 --- a/qtpy/QtPrintSupport.py +++ b/qtpy/QtPrintSupport.py @@ -9,20 +9,19 @@ Provides QtPrintSupport classes and functions. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtPrintSupport import * -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtGui import (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine, QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo) -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtGui import (QAbstractPrintDialog, QPageSetupDialog, QPrintDialog, QPrintEngine, QPrintPreviewDialog, QPrintPreviewWidget, QPrinter, QPrinterInfo) diff --git a/qtpy/QtSvg.py b/qtpy/QtSvg.py index 11272dac..46f07803 100644 --- a/qtpy/QtSvg.py +++ b/qtpy/QtSvg.py @@ -8,18 +8,17 @@ Provides QtSvg classes and functions. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtSvg import * -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtSvg import * -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtSvg import * else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtTest.py b/qtpy/QtTest.py index 630d41d4..17b03780 100644 --- a/qtpy/QtTest.py +++ b/qtpy/QtTest.py @@ -12,23 +12,22 @@ running with PySide. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError -if API in PYQT5_API: +if PYQT5: from PyQt5.QtTest import QTest -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtTest import QTest as OldQTest class QTest(OldQTest): @staticmethod def qWaitForWindowActive(QWidget): OldQTest.qWaitForWindowShown(QWidget) -elif API in PYSIDE_API: +elif PYSIDE: raise ImportError('QtTest support is incomplete for PySide') else: raise PythonQtError('No Qt bindings could be found') diff --git a/qtpy/QtWebEngineWidgets.py b/qtpy/QtWebEngineWidgets.py index 8df87871..e2ecdfe4 100644 --- a/qtpy/QtWebEngineWidgets.py +++ b/qtpy/QtWebEngineWidgets.py @@ -10,10 +10,9 @@ Provides QtWebEngineWidgets classes and functions. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError @@ -21,7 +20,7 @@ WEBENGINE = True -if API in PYQT5_API: +if PYQT5: try: from PyQt5.QtWebEngineWidgets import QWebEnginePage from PyQt5.QtWebEngineWidgets import QWebEngineView @@ -31,12 +30,12 @@ from PyQt5.QtWebKitWidgets import QWebView as QWebEngineView from PyQt5.QtWebKit import QWebSettings as QWebEngineSettings WEBENGINE = False -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtWebKit import QWebPage as QWebEnginePage from PyQt4.QtWebKit import QWebView as QWebEngineView from PyQt4.QtWebKit import QWebSettings as QWebEngineSettings WEBENGINE = False -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtWebKit import QWebPage as QWebEnginePage from PySide.QtWebKit import QWebView as QWebEngineView from PySide.QtWebKit import QWebSettings as QWebEngineSettings diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index 6f2fa8c7..c3753e93 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -13,17 +13,16 @@ were the ``PyQt5.QtWidgets`` module. """ -from qtpy import API -from qtpy import PYQT5_API -from qtpy import PYQT4_API -from qtpy import PYSIDE_API +from qtpy import PYQT5 +from qtpy import PYQT4 +from qtpy import PYSIDE from qtpy import PythonQtError from qtpy._patch.qcombobox import patch_qcombobox -if API in PYQT5_API: +if PYQT5: from PyQt5.QtWidgets import * -elif API in PYQT4_API: +elif PYQT4: from PyQt4.QtGui import * QStyleOptionViewItem = QStyleOptionViewItemV4 @@ -68,7 +67,7 @@ # Patch QComboBox to allow Python objects to be passed to userData patch_qcombobox(QComboBox) -elif API in PYSIDE_API: +elif PYSIDE: from PySide.QtGui import * QStyleOptionViewItem = QStyleOptionViewItemV4 diff --git a/qtpy/compat.py b/qtpy/compat.py index 5bbbd67f..ae38090e 100644 --- a/qtpy/compat.py +++ b/qtpy/compat.py @@ -11,7 +11,7 @@ import sys import collections -from qtpy import API, PYQT4_API +from qtpy import PYQT4 from qtpy.QtWidgets import QFileDialog from qtpy.py3compat import is_text_string, to_text_string, TEXT_TYPES @@ -20,7 +20,7 @@ # QVariant conversion utilities # ============================================================================= PYQT_API_1 = False -if API in PYQT4_API: +if PYQT4: import sip try: PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1 From 5eb32b7c2113048dfd96c2dd5904292d083e2244 Mon Sep 17 00:00:00 2001 From: Joseph Martinot-Lagarde Date: Sat, 11 Jun 2016 22:43:05 +0200 Subject: [PATCH 3/4] Merge imports into a single line --- qtpy/QtCore.py | 5 +---- qtpy/QtDesigner.py | 4 +--- qtpy/QtGui.py | 5 +---- qtpy/QtNetwork.py | 5 +---- qtpy/QtPrintSupport.py | 5 +---- qtpy/QtSvg.py | 5 +---- qtpy/QtTest.py | 5 +---- qtpy/QtWebEngineWidgets.py | 5 +---- qtpy/QtWidgets.py | 5 +---- 9 files changed, 9 insertions(+), 35 deletions(-) diff --git a/qtpy/QtCore.py b/qtpy/QtCore.py index c99b5a11..0ca69d3f 100644 --- a/qtpy/QtCore.py +++ b/qtpy/QtCore.py @@ -10,10 +10,7 @@ Provides QtCore classes and functions. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError if PYQT5: diff --git a/qtpy/QtDesigner.py b/qtpy/QtDesigner.py index 980bd578..8b2ddedb 100644 --- a/qtpy/QtDesigner.py +++ b/qtpy/QtDesigner.py @@ -9,9 +9,7 @@ Provides QtDesigner classes and functions. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PythonQtError if PYQT5: diff --git a/qtpy/QtGui.py b/qtpy/QtGui.py index 728571a9..84049e57 100644 --- a/qtpy/QtGui.py +++ b/qtpy/QtGui.py @@ -13,10 +13,7 @@ the ``PyQt5.QtGui`` module. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError if PYQT5: diff --git a/qtpy/QtNetwork.py b/qtpy/QtNetwork.py index d7d24d5a..aca335bd 100644 --- a/qtpy/QtNetwork.py +++ b/qtpy/QtNetwork.py @@ -10,10 +10,7 @@ Provides QtNetwork classes and functions. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError if PYQT5: diff --git a/qtpy/QtPrintSupport.py b/qtpy/QtPrintSupport.py index 95f9a531..b272174b 100644 --- a/qtpy/QtPrintSupport.py +++ b/qtpy/QtPrintSupport.py @@ -9,10 +9,7 @@ Provides QtPrintSupport classes and functions. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError if PYQT5: diff --git a/qtpy/QtSvg.py b/qtpy/QtSvg.py index 46f07803..10e41831 100644 --- a/qtpy/QtSvg.py +++ b/qtpy/QtSvg.py @@ -8,10 +8,7 @@ Provides QtSvg classes and functions. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError if PYQT5: diff --git a/qtpy/QtTest.py b/qtpy/QtTest.py index 17b03780..06ad073b 100644 --- a/qtpy/QtTest.py +++ b/qtpy/QtTest.py @@ -12,10 +12,7 @@ running with PySide. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError if PYQT5: diff --git a/qtpy/QtWebEngineWidgets.py b/qtpy/QtWebEngineWidgets.py index e2ecdfe4..bd073691 100644 --- a/qtpy/QtWebEngineWidgets.py +++ b/qtpy/QtWebEngineWidgets.py @@ -10,10 +10,7 @@ Provides QtWebEngineWidgets classes and functions. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError # To test if we are using WebEngine or WebKit diff --git a/qtpy/QtWidgets.py b/qtpy/QtWidgets.py index c3753e93..e1656ab8 100644 --- a/qtpy/QtWidgets.py +++ b/qtpy/QtWidgets.py @@ -13,10 +13,7 @@ were the ``PyQt5.QtWidgets`` module. """ -from qtpy import PYQT5 -from qtpy import PYQT4 -from qtpy import PYSIDE -from qtpy import PythonQtError +from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError from qtpy._patch.qcombobox import patch_qcombobox From 11873d50fc995db708c0266ac2c4ed17c350dc21 Mon Sep 17 00:00:00 2001 From: Joseph Martinot-Lagarde Date: Sat, 11 Jun 2016 22:45:48 +0200 Subject: [PATCH 4/4] Use PYQT4 constant in __init__.py --- qtpy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtpy/__init__.py b/qtpy/__init__.py index d5f0e25c..cf22d1e1 100644 --- a/qtpy/__init__.py +++ b/qtpy/__init__.py @@ -119,7 +119,7 @@ class PythonQtError(Exception): API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyqt4': 'PyQt4', 'pyside': 'PySide'}[API] -if API in PYQT4_API: +if PYQT4: import sip try: API_NAME += (" (API v{0})".format(sip.getapi('QString')))