Skip to content

Commit

Permalink
Merge pull request #33 from Nodd/ignore_case
Browse files Browse the repository at this point in the history
Ignore case for QT_API env variable in qtpy submodules
  • Loading branch information
ccordoba12 authored Jun 11, 2016
2 parents 6a5d873 + 11873d5 commit 41fc86b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 107 deletions.
14 changes: 4 additions & 10 deletions qtpy/QtCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
Provides QtCore classes and functions.
"""

import os
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError

from qtpy import QT_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 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 os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.QtCore import *
from PyQt4.QtCore import QCoreApplication
from PyQt4.QtCore import Qt
Expand All @@ -35,7 +29,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 PYSIDE:
from PySide.QtCore import *
from PySide.QtGui import (QItemSelection, QItemSelectionModel,
QItemSelectionRange, QSortFilterProxyModel)
Expand Down
11 changes: 3 additions & 8 deletions qtpy/QtDesigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
Provides QtDesigner classes and functions.
"""

import os
from qtpy import PYQT5, PYQT4, PythonQtError

from qtpy import QT_API
from qtpy import PYQT5_API
from qtpy import PYQT4_API
from qtpy import PythonQtError


if os.environ[QT_API] in PYQT5_API:
if PYQT5:
from PyQt5.QtDesigner import *
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.QtDesigner import *
else:
raise PythonQtError('No Qt bindings could be found')
14 changes: 4 additions & 10 deletions qtpy/QtGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@
the ``PyQt5.QtGui`` module.
"""

import os
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError

from qtpy import QT_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 PYQT5:
from PyQt5.QtGui import *
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.Qt import QKeySequence, QTextCursor
from PyQt4.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
QBrush, QClipboard, QCloseEvent, QColor,
Expand Down Expand Up @@ -65,7 +59,7 @@
QWindowStateChangeEvent, qAlpha, qBlue,
qFuzzyCompare, qGray, qGreen, qIsGray, qRed, qRgb,
qRgba, QIntValidator)
elif os.environ[QT_API] in PYSIDE_API:
elif PYSIDE:
from PySide.QtGui import (QAbstractTextDocumentLayout, QActionEvent, QBitmap,
QBrush, QClipboard, QCloseEvent, QColor,
QConicalGradient, QContextMenuEvent, QCursor,
Expand Down
14 changes: 4 additions & 10 deletions qtpy/QtNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
Provides QtNetwork classes and functions.
"""

import os
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError

from qtpy import QT_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 PYQT5:
from PyQt5.QtNetwork import *
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.QtNetwork import *
elif os.environ[QT_API] in PYSIDE_API:
elif PYSIDE:
from PySide.QtNetwork import *
else:
raise PythonQtError('No Qt bindings could be found')
14 changes: 4 additions & 10 deletions qtpy/QtPrintSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@
Provides QtPrintSupport classes and functions.
"""

import os
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError

from qtpy import QT_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 PYQT5:
from PyQt5.QtPrintSupport import *
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.QtGui import (QAbstractPrintDialog, QPageSetupDialog,
QPrintDialog, QPrintEngine, QPrintPreviewDialog,
QPrintPreviewWidget, QPrinter, QPrinterInfo)
elif os.environ[QT_API] in PYSIDE_API:
elif PYSIDE:
from PySide.QtGui import (QAbstractPrintDialog, QPageSetupDialog,
QPrintDialog, QPrintEngine, QPrintPreviewDialog,
QPrintPreviewWidget, QPrinter, QPrinterInfo)
Expand Down
14 changes: 4 additions & 10 deletions qtpy/QtSvg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@
Provides QtSvg classes and functions.
"""

import os
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError

from qtpy import QT_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 PYQT5:
from PyQt5.QtSvg import *
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.QtSvg import *
elif os.environ[QT_API] in PYSIDE_API:
elif PYSIDE:
from PySide.QtSvg import *
else:
raise PythonQtError('No Qt bindings could be found')
14 changes: 4 additions & 10 deletions qtpy/QtTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@
running with PySide.
"""

import os
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError

from qtpy import QT_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 PYQT5:
from PyQt5.QtTest import QTest
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
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 PYSIDE:
raise ImportError('QtTest support is incomplete for PySide')
else:
raise PythonQtError('No Qt bindings could be found')
14 changes: 4 additions & 10 deletions qtpy/QtWebEngineWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
Provides QtWebEngineWidgets classes and functions.
"""

import os

from qtpy import QT_API
from qtpy import PYQT5_API
from qtpy import PYQT4_API
from qtpy import PYSIDE_API
from qtpy import PythonQtError
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError


# To test if we are using WebEngine or WebKit
WEBENGINE = True


if os.environ[QT_API] in PYQT5_API:
if PYQT5:
try:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWebEngineWidgets import QWebEngineView
Expand All @@ -33,12 +27,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 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 os.environ[QT_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
Expand Down
15 changes: 5 additions & 10 deletions qtpy/QtWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@
were the ``PyQt5.QtWidgets`` module.
"""

import os

from qtpy import QT_API
from qtpy import PYQT5_API
from qtpy import PYQT4_API
from qtpy import PYSIDE_API
from qtpy import PythonQtError
from qtpy import PYQT5, PYQT4, PYSIDE, PythonQtError
from qtpy._patch.qcombobox import patch_qcombobox

if os.environ[QT_API] in PYQT5_API:

if PYQT5:
from PyQt5.QtWidgets import *
elif os.environ[QT_API] in PYQT4_API:
elif PYQT4:
from PyQt4.QtGui import *
QStyleOptionViewItem = QStyleOptionViewItemV4

Expand Down Expand Up @@ -69,7 +64,7 @@
# Patch QComboBox to allow Python objects to be passed to userData
patch_qcombobox(QComboBox)

elif os.environ[QT_API] in PYSIDE_API:
elif PYSIDE:
from PySide.QtGui import *
QStyleOptionViewItem = QStyleOptionViewItemV4

Expand Down
28 changes: 13 additions & 15 deletions qtpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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 PYQT4:
import sip
try:
API_NAME += (" (API v{0})".format(sip.getapi('QString')))
except AttributeError:
pass
4 changes: 2 additions & 2 deletions qtpy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"""

from __future__ import print_function
import os
import sys
import collections

from qtpy import PYQT4
from qtpy.QtWidgets import QFileDialog
from qtpy.py3compat import is_text_string, to_text_string, TEXT_TYPES

Expand All @@ -20,7 +20,7 @@
# QVariant conversion utilities
# =============================================================================
PYQT_API_1 = False
if os.environ['QT_API'] == 'pyqt':
if PYQT4:
import sip
try:
PYQT_API_1 = sip.getapi('QVariant') == 1 # PyQt API #1
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from qtpy import QtCore, QtGui, QtWidgets, QtWebEngineWidgets


def assert_pyside():
"""
Make sure that we are using PySide
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 41fc86b

Please sign in to comment.