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