Show More
@@ -2,56 +2,51 b'' | |||
|
2 | 2 | |
|
3 | 3 | This is the import used for the `gui=qt` or `pylab=qt` initialization. |
|
4 | 4 | |
|
5 | Priority: | |
|
5 | Import Priority: | |
|
6 | 6 | |
|
7 | if matplotlib has been imported: | |
|
8 | # get here with pylab=qt | |
|
9 | if matplotlib doesn't support v2 (<= 1.0.1): | |
|
7 | if matplotlib has been imported and doesn't support v2 (<= 1.0.1): | |
|
10 | 8 |
|
|
11 | else: | |
|
12 | ask matplotlib which Qt it's using | |
|
9 | ||
|
10 | Next, ask ETS' QT_API env variable | |
|
11 | ||
|
12 | if QT_API not set: | |
|
13 | ask matplotlib via rcParams['backend.qt4'] | |
|
13 | 14 |
|
|
14 | 15 |
|
|
15 | 16 |
|
|
16 | 17 |
|
|
17 | 18 | |
|
18 | if matplotlib had nothing to say, or matplotlib not imported: | |
|
19 | # get here with gui=qt, or if matplotlib didn't tell us anything | |
|
20 | ask ETS' QT_API env variable | |
|
21 | ||
|
22 | if QT_API not set: | |
|
23 | # this is the *default* path - no information was given | |
|
19 | else: (matplotlib said nothing) | |
|
20 | # this is the default path - nobody told us anything | |
|
24 | 21 | try: |
|
25 | 22 | PyQt @v1 |
|
26 | 23 | except: |
|
27 | 24 | fallback on PySide |
|
28 | 25 |
|
|
29 | 26 |
|
|
30 |
|
|
|
27 | because ETS doesn't work with PyQt @v1. | |
|
28 | ||
|
31 | 29 | """ |
|
32 | 30 | |
|
33 | 31 | import os |
|
34 | 32 | import sys |
|
35 | 33 | |
|
36 | 34 | matplotlib = sys.modules.get('matplotlib') |
|
37 | if matplotlib: | |
|
38 | # ask matplotlib first (get here with pylab=qt) | |
|
39 | if matplotlib.__version__ <= '1.0.1': | |
|
40 | # 1.0.1 doesn't support pyside or v2, so force PyQt @v1 | |
|
41 | mod = 'PyQt4' | |
|
42 | else: | |
|
43 | # this rc option has been proposed, but is yet not in matplotlib master | |
|
44 | # as of writing. | |
|
45 | mod = matplotlib.rcParams.get('backend.qt4', None) | |
|
35 | if matplotlib and matplotlib.__version__ <= '1.0.1': | |
|
36 | # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1, | |
|
37 | # and ignore everything else | |
|
38 | from PyQt4 import QtCore, QtGui | |
|
46 | 39 | else: |
|
47 | # get here with `gui=qt` | |
|
48 | mod = None | |
|
49 | ||
|
50 | if mod is None: | |
|
51 | # matplotlib not imported or had nothing to say. | |
|
52 | # ask QT_API ETS variable | |
|
40 | # ask QT_API ETS variable *first* | |
|
53 | 41 | QT_API = os.environ.get('QT_API', None) |
|
54 | 42 | if QT_API is None: |
|
43 | # QT_API not set, ask matplotlib if it was imported (e.g. `pylab=qt`) | |
|
44 | if matplotlib: | |
|
45 | mpqt = matplotlib.rcParams.get('backend.qt4', None) | |
|
46 | else: | |
|
47 | mpqt = None | |
|
48 | if mpqt is None: | |
|
49 | # matplotlib not imported or had nothing to say. | |
|
55 | 50 | try: |
|
56 | 51 | # default to unconfigured PyQt4 |
|
57 | 52 | from PyQt4 import QtCore, QtGui |
@@ -61,15 +56,27 b' if mod is None:' | |||
|
61 | 56 | from PySide import QtCore, QtGui |
|
62 | 57 | except ImportError: |
|
63 | 58 | raise ImportError('Cannot import PySide or PyQt4') |
|
59 | elif mpqt.lower() == 'pyqt4': | |
|
60 | # import PyQt4 unconfigured | |
|
61 | from PyQt4 import QtCore, QtGui | |
|
62 | elif mpqt.lower() == 'pyside': | |
|
63 | from PySide import QtCore, QtGui | |
|
64 | else: | |
|
65 | raise ImportError("unhandled value for backend.qt4 from matplotlib: %r"%mpqt) | |
|
64 | 66 | else: |
|
65 | 67 | # QT_API specified, use PySide or PyQt+v2 API from external.qt |
|
66 | 68 | # this means ETS is likely to be used, which requires v2 |
|
69 | try: | |
|
67 | 70 | from IPython.external.qt import QtCore, QtGui |
|
68 | ||
|
69 | elif mod.lower() == 'pyqt4': | |
|
70 | # import PyQt4 unconfigured | |
|
71 | from PyQt4 import QtCore, QtGui | |
|
72 | elif mod.lower() == 'pyside': | |
|
73 | from PySide import QtCore, QtGui | |
|
71 | except ValueError as e: | |
|
72 | if 'API' in str(e): | |
|
73 | # API mismatch, give more meaningful message | |
|
74 | raise ImportError(""" | |
|
75 | Assigning the ETS variable `QT_API=pyqt` implies PyQt's v2 API for | |
|
76 | QString and QVariant, but PyQt has already been imported | |
|
77 | with v1 APIs. You must unset QT_API to work with PyQt4 | |
|
78 | in its default mode. | |
|
79 | """) | |
|
74 | 80 | else: |
|
75 | raise ImportError("unhandled value for backend.qt4 from matplotlib: %r"%mod) No newline at end of file | |
|
81 | raise | |
|
82 |
@@ -1269,29 +1269,29 b" v2 is also the default for PyQt4 on Python 3. IPython's code for the QtConsole" | |||
|
1269 | 1269 | uses v2, but you can still use any interface in your code, since the |
|
1270 | 1270 | Qt frontend is in a different process. |
|
1271 | 1271 | |
|
1272 | If you launch IPython in pylab mode with ``ipython pylab=qt``, then IPython | |
|
1273 | will ask matplotlib which Qt library to use, via the 'backend.qt4' rcParam. | |
|
1274 | If matplotlib is version 1.0.1 or older, then IPython will always use PyQt4 | |
|
1275 | without setting the v2 APIs. | |
|
1276 | ||
|
1277 | If you just integrate the Qt event loop with ``ipython gui=qt``, then IPython | |
|
1278 | has a few more possibilities. The default will be to import PyQt4 without | |
|
1279 | configuration of the APIs, thus matching what most applications would expect. | |
|
1280 | It will fall back of PySide if PyQt4 is unavailable. | |
|
1272 | The default will be to import PyQt4 without configuration of the APIs, thus | |
|
1273 | matching what most applications would expect. It will fall back of PySide if | |
|
1274 | PyQt4 is unavailable. | |
|
1281 | 1275 | |
|
1282 | 1276 | If specified, IPython will respect the environment variable ``QT_API`` used |
|
1283 | 1277 | by ETS. ETS 4.0 also works with both PyQt4 and PySide, but it requires |
|
1284 |
PyQt4 to use |
|
|
1285 |
and if ``QT_API=pyqt`` then PyQt4 will be used with the v2 API for |
|
|
1278 | PyQt4 to use its v2 API. So if ``QT_API=pyside`` PySide will be used, | |
|
1279 | and if ``QT_API=pyqt`` then PyQt4 will be used *with the v2 API* for | |
|
1286 | 1280 | QString and QVariant, so ETS codes like MayaVi will also work with IPython. |
|
1287 | 1281 | |
|
1282 | If you launch IPython in pylab mode with ``ipython pylab=qt``, then IPython | |
|
1283 | will ask matplotlib which Qt library to use (only if QT_API is *not set*), | |
|
1284 | via the 'backend.qt4' rcParam. | |
|
1285 | If matplotlib is version 1.0.1 or older, then IPython will always use PyQt4 | |
|
1286 | without setting the v2 APIs, since neither v2 PyQt nor PySide work. | |
|
1287 | ||
|
1288 | 1288 | .. warning:: |
|
1289 | 1289 | |
|
1290 | Note that this means for ETS to work with PyQt4, ``QT_API`` *must* be set to | |
|
1290 | Note that this means for ETS 4 to work with PyQt4, ``QT_API`` *must* be set to | |
|
1291 | 1291 | work with IPython's qt integration, because otherwise PyQt4 will be loaded in |
|
1292 | 1292 | an incompatible mode. |
|
1293 | 1293 | |
|
1294 | It also means that you must not have ``QT_API`` set if you want to | |
|
1294 | It also means that you must *not* have ``QT_API`` set if you want to | |
|
1295 | 1295 | use ``gui=qt`` with code that requires PyQt4 API v1. |
|
1296 | 1296 | |
|
1297 | 1297 |
General Comments 0
You need to be logged in to leave comments.
Login now