##// END OF EJS Templates
demote sip API failure to warning from ImportError
MinRK -
Show More
@@ -1,82 +1,87 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 `pylab=qt` initialization.
4 4
5 5 Import Priority:
6 6
7 7 if matplotlib has been imported and doesn't support v2 (<= 1.0.1):
8 8 use PyQt4 @v1
9 9
10 10 Next, ask ETS' QT_API env variable
11 11
12 12 if QT_API not set:
13 13 ask matplotlib via rcParams['backend.qt4']
14 14 if it said PyQt:
15 15 use PyQt4 @v1
16 16 elif it said PySide:
17 17 use PySide
18 18
19 19 else: (matplotlib said nothing)
20 20 # this is the default path - nobody told us anything
21 21 try:
22 22 PyQt @v1
23 23 except:
24 24 fallback on PySide
25 25 else:
26 26 use PyQt @v2 or PySide, depending on QT_API
27 27 because ETS doesn't work with PyQt @v1.
28 28
29 29 """
30 30
31 31 import os
32 32 import sys
33 33
34 from IPython.utils.warn import warn
35
34 36 matplotlib = sys.modules.get('matplotlib')
35 37 if matplotlib and matplotlib.__version__ <= '1.0.1':
36 38 # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1,
37 39 # and ignore everything else
38 40 from PyQt4 import QtCore, QtGui
39 41 else:
40 42 # ask QT_API ETS variable *first*
41 43 QT_API = os.environ.get('QT_API', None)
42 44 if QT_API is None:
43 45 # QT_API not set, ask matplotlib if it was imported (e.g. `pylab=qt`)
44 46 if matplotlib:
45 47 mpqt = matplotlib.rcParams.get('backend.qt4', None)
46 48 else:
47 49 mpqt = None
48 50 if mpqt is None:
49 51 # matplotlib not imported or had nothing to say.
50 52 try:
51 53 # default to unconfigured PyQt4
52 54 from PyQt4 import QtCore, QtGui
53 55 except ImportError:
54 56 # fallback on PySide
55 57 try:
56 58 from PySide import QtCore, QtGui
57 59 except ImportError:
58 60 raise ImportError('Cannot import PySide or PyQt4')
59 61 elif mpqt.lower() == 'pyqt4':
60 62 # import PyQt4 unconfigured
61 63 from PyQt4 import QtCore, QtGui
62 64 elif mpqt.lower() == 'pyside':
63 65 from PySide import QtCore, QtGui
64 66 else:
65 67 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r"%mpqt)
66 68 else:
67 69 # QT_API specified, use PySide or PyQt+v2 API from external.qt
68 70 # this means ETS is likely to be used, which requires v2
69 71 try:
70 72 from IPython.external.qt import QtCore, QtGui
71 73 except ValueError as e:
72 74 if 'API' in str(e):
73 # API mismatch, give more meaningful message
74 raise ImportError("""
75 # PyQt4 already imported, and APIv2 couldn't be set
76 # Give more meaningful message, and warn instead of raising
77 warn("""
75 78 Assigning the ETS variable `QT_API=pyqt` implies PyQt's v2 API for
76 79 QString and QVariant, but PyQt has already been imported
77 with v1 APIs. You must unset QT_API to work with PyQt4
80 with v1 APIs. You should unset QT_API to work with PyQt4
78 81 in its default mode.
79 82 """)
83 # allow it to still work
84 from PyQt4 import QtCore, QtGui
80 85 else:
81 86 raise
82 87
General Comments 0
You need to be logged in to leave comments. Login now