Skip to content

Commit 30a8f3d

Browse files
committed
Updated qt compatibility package to the latest version
1 parent c66e061 commit 30a8f3d

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

qwt/qt/__init__.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Licensed under the terms of the MIT License
66
# (see LICENSE file for details)
77

8-
"""Transitional package (PyQt4 --> PySide)"""
8+
"""Compatibility package (PyQt4/PyQt5/PySide)"""
99

1010
import os
1111

@@ -15,17 +15,7 @@
1515
API = os.environ['QT_API']
1616
API_NAME = {'pyqt5': 'PyQt5', 'pyqt': 'PyQt4', 'pyside': 'PySide'}[API]
1717

18-
PYQT5 = False
19-
20-
if API == 'pyqt5':
21-
try:
22-
from PyQt5.QtCore import PYQT_VERSION_STR as __version__
23-
is_old_pyqt = False
24-
is_pyqt46 = False
25-
PYQT5 = True
26-
except ImportError:
27-
pass
28-
elif API == 'pyqt':
18+
if API == 'pyqt':
2919
# Spyder 2.3 is compatible with both #1 and #2 PyQt API,
3020
# but to avoid issues with IPython and other Qt plugins
3121
# we choose to support only API #2 for 2.4+
@@ -46,9 +36,16 @@
4636
try:
4737
from PyQt4.QtCore import PYQT_VERSION_STR as __version__ # analysis:ignore
4838
except ImportError:
49-
# Switching to PySide
50-
API = os.environ['QT_API'] = 'pyside'
51-
API_NAME = 'PySide'
39+
# Trying PyQt5 before switching to PySide (at this point, PyQt4 may
40+
# not be installed but PyQt5 or Pyside could still be if the QT_API
41+
# environment variable hasn't been set-up)
42+
try:
43+
import PyQt5 # analysis:ignore
44+
API = os.environ['QT_API'] = 'pyqt5'
45+
API_NAME = 'PyQt5'
46+
except ImportError:
47+
API = os.environ['QT_API'] = 'pyside'
48+
API_NAME = 'PySide'
5249
else:
5350
is_old_pyqt = __version__.startswith(('4.4', '4.5', '4.6', '4.7'))
5451
is_pyqt46 = __version__.startswith('4.6')
@@ -57,8 +54,18 @@
5754
API_NAME += (" (API v%d)" % sip.getapi('QString'))
5855
except AttributeError:
5956
pass
57+
from PyQt4 import uic # analysis:ignore
6058

61-
59+
PYQT5 = False
60+
if API == 'pyqt5':
61+
try:
62+
from PyQt5.QtCore import PYQT_VERSION_STR as __version__
63+
from PyQt5 import uic # analysis:ignore
64+
PYQT5 = True
65+
is_old_pyqt = is_pyqt46 = False
66+
except ImportError:
67+
pass
68+
6269
if API == 'pyside':
6370
try:
6471
from PySide import __version__ # analysis:ignore

0 commit comments

Comments
 (0)