Skip to content

Commit

Permalink
Merge pull request #2691 from spyder-ide/PyQt5_detection_issue
Browse files Browse the repository at this point in the history
Fixed PyQt5 detection without QT_API env var
  • Loading branch information
ccordoba12 committed Sep 14, 2015
2 parents c65a4ea + b2324e0 commit b1d9780
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions spyderlib/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@
API = os.environ['QT_API']
API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyside': 'PySide'}[API]

PYQT5 = False

if API == 'pyqt5':
try:
from PyQt5.QtCore import PYQT_VERSION_STR as __version__
is_old_pyqt = False
is_pyqt46 = False
PYQT5 = True
except ImportError:
pass
elif API == 'pyqt':
if API == 'pyqt':
# Spyder 2.3 is compatible with both #1 and #2 PyQt API,
# but to avoid issues with IPython and other Qt plugins
# we choose to support only API #2 for 2.4+
Expand All @@ -46,9 +36,16 @@

from PyQt4.QtCore import PYQT_VERSION_STR as __version__ # analysis:ignore
except ImportError:
# Switching to PySide
API = os.environ['QT_API'] = 'pyside'
API_NAME = 'PySide'
# Trying PyQt5 before switching to PySide (at this point, PyQt4 may
# not be installed but PyQt5 or Pyside could still be if the QT_API
# environment variable hasn't been set-up)
try:
import PyQt5 # analysis:ignore
API = os.environ['QT_API'] = 'pyqt5'
API_NAME = 'PyQt5'
except ImportError:
API = os.environ['QT_API'] = 'pyside'
API_NAME = 'PySide'
else:
is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7'))
is_pyqt46 = __version__.startswith('4.6')
Expand All @@ -57,6 +54,17 @@
API_NAME += (" (API v%d)" % sip.getapi('QString'))
except AttributeError:
pass
from PyQt4 import uic # analysis:ignore

PYQT5 = False
if API == 'pyqt5':
try:
from PyQt5.QtCore import PYQT_VERSION_STR as __version__
from PyQt5 import uic # analysis:ignore
PYQT5 = True
is_old_pyqt = is_pyqt46 = False
except ImportError:
pass

if API == 'pyside':
try:
Expand Down

0 comments on commit b1d9780

Please sign in to comment.