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