##// END OF EJS Templates
Revert "add shim for external/qt_for_kernel.py"...
Zachary Pincus -
Show More
@@ -1,86 +1,85 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 Qt4 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 ETS' QT_API env variable
14
14
15 if QT_API not set:
15 if QT_API not set:
16 ask matplotlib via rcParams['backend.qt4']
16 ask matplotlib via rcParams['backend.qt4']
17 if it said PyQt:
17 if it said PyQt:
18 use PyQt4 @v1
18 use PyQt4 @v1
19 elif it said PySide:
19 elif it said PySide:
20 use PySide
20 use PySide
21
21
22 else: (matplotlib said nothing)
22 else: (matplotlib said nothing)
23 # this is the default path - nobody told us anything
23 # this is the default path - nobody told us anything
24 try:
24 try:
25 PyQt @v1
25 PyQt @v1
26 except:
26 except:
27 fallback on PySide
27 fallback on PySide
28 else:
28 else:
29 use what QT_API says
29 use PyQt @v2 or PySide, depending on QT_API
30 because ETS doesn't work with PyQt @v1.
30
31
31 """
32 """
32
33
33 import os
34 import os
34 import sys
35 import sys
35
36
36 from IPython.utils.version import check_version
37 from IPython.utils.version import check_version
37 from IPython.external.qt_loaders import (load_qt, loaded_api, QT_API_PYSIDE,
38 from IPython.external.qt_loaders import (load_qt, loaded_api, QT_API_PYSIDE,
38 QT_API_PYQT, QT_API_PYQT5,
39 QT_API_PYQT, QT_API_PYQT5,
39 QT_API_PYQTv1, QT_API_PYQT_DEFAULT)
40 QT_API_PYQTv1, QT_API_PYQT_DEFAULT)
40
41
41 _qt_apis = (QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5, QT_API_PYQTv1,
42 _qt_apis = (QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5, QT_API_PYQTv1,
42 QT_API_PYQT_DEFAULT)
43 QT_API_PYQT_DEFAULT)
43
44
44 # Constraints placed on an imported matplotlib
45 #Constraints placed on an imported matplotlib
45 # TODO: check that this is still consistent with what matplotlib supports,
46 # in particular with regard to qt5.
47 def matplotlib_options(mpl):
46 def matplotlib_options(mpl):
48 if mpl is None:
47 if mpl is None:
49 return
48 return
50 mpqt = mpl.rcParams.get('backend.qt4', None)
49 mpqt = mpl.rcParams.get('backend.qt4', None)
51 if mpqt is None:
50 if mpqt is None:
52 return None
51 return None
53 if mpqt.lower() == 'pyside':
52 if mpqt.lower() == 'pyside':
54 return [QT_API_PYSIDE]
53 return [QT_API_PYSIDE]
55 elif mpqt.lower() == 'pyqt4':
54 elif mpqt.lower() == 'pyqt4':
56 return [QT_API_PYQT_DEFAULT]
55 return [QT_API_PYQT_DEFAULT]
57 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
56 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
58 mpqt)
57 mpqt)
59
58
60 def get_options():
59 def get_options():
61 """Return a list of acceptable QT APIs, in decreasing order of
60 """Return a list of acceptable QT APIs, in decreasing order of
62 preference
61 preference
63 """
62 """
64 #already imported Qt somewhere. Use that
63 #already imported Qt somewhere. Use that
65 loaded = loaded_api()
64 loaded = loaded_api()
66 if loaded is not None:
65 if loaded is not None:
67 return [loaded]
66 return [loaded]
68
67
69 mpl = sys.modules.get('matplotlib', None)
68 mpl = sys.modules.get('matplotlib', None)
70
69
71 if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
70 if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
72 #1.0.1 only supports PyQt4 v1
71 #1.0.1 only supports PyQt4 v1
73 return [QT_API_PYQT_DEFAULT]
72 return [QT_API_PYQT_DEFAULT]
74
73
75 qt_api = os.environ.get('QT_API', None)
74 qt_api = os.environ.get('QT_API', None)
76 if qt_api is None:
75 if qt_api is None:
77 #no ETS variable. Ask mpl, then use either
76 #no ETS variable. Ask mpl, then use either
78 return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
77 return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
79 elif qt_api not in _qt_apis:
78 elif qt_api not in _qt_apis:
80 raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
79 raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
81 (qt_api, ', '.join(_qt_apis)))
80 (qt_api, ', '.join(_qt_apis)))
82 else:
81 else:
83 return [qt_api]
82 return [qt_api]
84
83
85 api_opts = get_options()
84 api_opts = get_options()
86 QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
85 QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now