##// END OF EJS Templates
s/pyqtv2/pyqt4v2/
Zachary Pincus -
Show More
@@ -1,94 +1,94 b''
1 1 """ Import Qt in a manner suitable for an IPython kernel.
2 2
3 3 This is the import used for the `gui=qt` or `matplotlib=qt` initialization.
4 4
5 5 Import Priority:
6 6
7 7 if Qt has been imported anywhere else:
8 8 use that
9 9
10 10 if matplotlib has been imported and doesn't support v2 (<= 1.0.1):
11 11 use PyQt4 @v1
12 12
13 13 Next, ask QT_API env variable
14 14
15 15 if QT_API not set:
16 16 ask matplotlib what it's using. If Qt4Agg or Qt5Agg, then use the
17 17 version matplotlib is configured with
18 18
19 19 else: (matplotlib said nothing)
20 20 # this is the default path - nobody told us anything
21 21 try in this order:
22 22 PyQt default version, PySide, PyQt5
23 23 else:
24 24 use what QT_API says
25 25
26 26 """
27 27 # NOTE: This is no longer an external, third-party module, and should be
28 28 # considered part of IPython. For compatibility however, it is being kept in
29 29 # IPython/external.
30 30
31 31 import os
32 32 import sys
33 33
34 34 from IPython.utils.version import check_version
35 35 from IPython.external.qt_loaders import (load_qt, loaded_api, QT_API_PYSIDE,
36 36 QT_API_PYQT, QT_API_PYQT5,
37 37 QT_API_PYQTv1, QT_API_PYQT_DEFAULT)
38 38
39 39 _qt_apis = (QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5, QT_API_PYQTv1,
40 40 QT_API_PYQT_DEFAULT)
41 41
42 42 #Constraints placed on an imported matplotlib
43 43 def matplotlib_options(mpl):
44 44 if mpl is None:
45 45 return
46 46 backend = mpl.rcParams.get('backend', None)
47 47 if backend == 'Qt4Agg':
48 48 mpqt = mpl.rcParams.get('backend.qt4', None)
49 49 if mpqt is None:
50 50 return None
51 51 if mpqt.lower() == 'pyside':
52 52 return [QT_API_PYSIDE]
53 53 elif mpqt.lower() == 'pyqt4':
54 54 return [QT_API_PYQT_DEFAULT]
55 elif mpqt.lower() == 'pyqtv2':
55 elif mpqt.lower() == 'pyqt4v2':
56 56 return [QT_API_PYQT]
57 57 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
58 58 mpqt)
59 59 elif backend == 'Qt5Agg':
60 60 mpqt = mpl.rcParams.get('backend.qt5', None)
61 61 if mpqt is None:
62 62 return None
63 63 if mpqt.lower() == 'pyqt5':
64 64 return [QT_API_PYQT5]
65 65 raise ImportError("unhandled value for backend.qt5 from matplotlib: %r" %
66 66 mpqt)
67 67
68 68 def get_options():
69 69 """Return a list of acceptable QT APIs, in decreasing order of
70 70 preference
71 71 """
72 72 #already imported Qt somewhere. Use that
73 73 loaded = loaded_api()
74 74 if loaded is not None:
75 75 return [loaded]
76 76
77 77 mpl = sys.modules.get('matplotlib', None)
78 78
79 79 if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
80 80 #1.0.1 only supports PyQt4 v1
81 81 return [QT_API_PYQT_DEFAULT]
82 82
83 83 qt_api = os.environ.get('QT_API', None)
84 84 if qt_api is None:
85 85 #no ETS variable. Ask mpl, then use default fallback path
86 86 return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE, QT_API_PYQT5]
87 87 elif qt_api not in _qt_apis:
88 88 raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
89 89 (qt_api, ', '.join(_qt_apis)))
90 90 else:
91 91 return [qt_api]
92 92
93 93 api_opts = get_options()
94 94 QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
General Comments 0
You need to be logged in to leave comments. Login now