##// END OF EJS Templates
Merge pull request #1704 from juliantaylor/ensure-qt-imports...
Min RK -
r6730:c4d651a9 merge
parent child Browse files
Show More
@@ -1,66 +1,67 b''
1 1 """ A Qt API selector that can be used to switch between PyQt and PySide.
2 2
3 3 This uses the ETS 4.0 selection pattern of:
4 4 PySide first, PyQt with API v2. second.
5 5
6 6 Do not use this if you need PyQt with the old QString/QVariant API.
7 7 """
8 8
9 9 import os
10 10
11 11 # Available APIs.
12 12 QT_API_PYQT = 'pyqt'
13 13 QT_API_PYSIDE = 'pyside'
14 14
15 15 def prepare_pyqt4():
16 16 # For PySide compatibility, use the new-style string API that automatically
17 17 # converts QStrings to Unicode Python strings. Also, automatically unpack
18 18 # QVariants to their underlying objects.
19 19 import sip
20 20 sip.setapi('QString', 2)
21 21 sip.setapi('QVariant', 2)
22 22
23 23 # Select Qt binding, using the QT_API environment variable if available.
24 24 QT_API = os.environ.get('QT_API')
25 25 if QT_API is None:
26 26 try:
27 27 import PySide
28 28 if PySide.__version__ < '1.0.3':
29 29 # old PySide, fallback on PyQt
30 30 raise ImportError
31 from PySide import QtCore, QtGui, QtSvg
31 32 QT_API = QT_API_PYSIDE
32 33 except ImportError:
33 34 try:
34 35 prepare_pyqt4()
35 36 import PyQt4
36 from PyQt4 import QtCore
37 from PyQt4 import QtCore, QtGui, QtSvg
37 38 if QtCore.PYQT_VERSION_STR < '4.7':
38 39 # PyQt 4.6 has issues with null strings returning as None
39 40 raise ImportError
40 41 QT_API = QT_API_PYQT
41 42 except ImportError:
42 43 raise ImportError('Cannot import PySide >= 1.0.3 or PyQt4 >= 4.7')
43 44
44 45 elif QT_API == QT_API_PYQT:
45 46 # Note: This must be called *before* PyQt4 is imported.
46 47 prepare_pyqt4()
47 48
48 49 # Now peform the imports.
49 50 if QT_API == QT_API_PYQT:
50 51 from PyQt4 import QtCore, QtGui, QtSvg
51 52 if QtCore.PYQT_VERSION_STR < '4.7':
52 53 raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
53 54
54 55 # Alias PyQt-specific functions for PySide compatibility.
55 56 QtCore.Signal = QtCore.pyqtSignal
56 57 QtCore.Slot = QtCore.pyqtSlot
57 58
58 59 elif QT_API == QT_API_PYSIDE:
59 60 import PySide
60 61 if PySide.__version__ < '1.0.3':
61 62 raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
62 63 from PySide import QtCore, QtGui, QtSvg
63 64
64 65 else:
65 66 raise RuntimeError('Invalid Qt API %r, valid values are: %r or %r' %
66 67 (QT_API, QT_API_PYQT, QT_API_PYSIDE))
General Comments 0
You need to be logged in to leave comments. Login now