##// END OF EJS Templates
Clarify Qt import logic
Zachary Pincus -
Show More
@@ -13,18 +13,13 b" if matplotlib has been imported and doesn't support v2 (<= 1.0.1):"
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 via rcParams['backend.qt4']
16 ask matplotlib what it's using. If Qt4Agg or Qt5Agg, then use the
17 if it said PyQt:
17 version matplotlib is configured with
18 use PyQt4 @v1
19 elif it said PySide:
20 use PySide
21
18
22 else: (matplotlib said nothing)
19 else: (matplotlib said nothing)
23 # this is the default path - nobody told us anything
20 # this is the default path - nobody told us anything
24 try:
21 try in this order:
25 PyQt @v1
22 PyQt default version, PySide
26 except:
27 fallback on PySide
28 else:
23 else:
29 use what QT_API says
24 use what QT_API says
30
25
@@ -45,22 +40,30 b' _qt_apis = (QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQT5, QT_API_PYQTv1,'
45 QT_API_PYQT_DEFAULT)
40 QT_API_PYQT_DEFAULT)
46
41
47 #Constraints placed on an imported matplotlib
42 #Constraints placed on an imported matplotlib
48 # TODO: Make sure this logic is still in sync with matplotlib's requirements.
49 # In particular, matplotlib can also now support a qt5 backend, and so this will
50 # break if matplotlib is imported and running happily with qt5, because
51 # it only queries for the preferred qt4 option.
52 def matplotlib_options(mpl):
43 def matplotlib_options(mpl):
53 if mpl is None:
44 if mpl is None:
54 return
45 return
55 mpqt = mpl.rcParams.get('backend.qt4', None)
46 backend = mpl.rcParams.get('backend', None)
56 if mpqt is None:
47 if backend == 'Qt4Agg':
57 return None
48 mpqt = mpl.rcParams.get('backend.qt4', None)
58 if mpqt.lower() == 'pyside':
49 if mpqt is None:
59 return [QT_API_PYSIDE]
50 return None
60 elif mpqt.lower() == 'pyqt4':
51 if mpqt.lower() == 'pyside':
61 return [QT_API_PYQT_DEFAULT]
52 return [QT_API_PYSIDE]
62 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
53 elif mpqt.lower() == 'pyqt4':
63 mpqt)
54 return [QT_API_PYQT_DEFAULT]
55 elif mpqt.lower() == 'pyqtv2':
56 return [QT_API_PYQT]
57 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
58 mpqt)
59 elif backend == 'Qt5Agg':
60 mpqt = mpl.rcParams.get('backend.qt5', None)
61 if mpqt is None:
62 return None
63 if mpqt.lower() == 'pyqt5':
64 return [QT_API_PYQT5]
65 raise ImportError("unhandled value for backend.qt5 from matplotlib: %r" %
66 mpqt)
64
67
65 def get_options():
68 def get_options():
66 """Return a list of acceptable QT APIs, in decreasing order of
69 """Return a list of acceptable QT APIs, in decreasing order of
@@ -79,7 +82,8 b' def get_options():'
79
82
80 qt_api = os.environ.get('QT_API', None)
83 qt_api = os.environ.get('QT_API', None)
81 if qt_api is None:
84 if qt_api is None:
82 #no ETS variable. Ask mpl, then use either
85 #no ETS variable. Ask mpl, then use default fallback path
86 # TODO: should Qt5 be on the fallback path if there is no Qt4 API?
83 return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
87 return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
84 elif qt_api not in _qt_apis:
88 elif qt_api not in _qt_apis:
85 raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
89 raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
@@ -15,10 +15,10 b' from functools import partial'
15 from IPython.utils.version import check_version
15 from IPython.utils.version import check_version
16
16
17 # Available APIs.
17 # Available APIs.
18 QT_API_PYQT = 'pyqt'
18 QT_API_PYQT = 'pyqt' # Force version 2
19 QT_API_PYQT5 = 'pyqt5'
19 QT_API_PYQT5 = 'pyqt5'
20 QT_API_PYQTv1 = 'pyqtv1'
20 QT_API_PYQTv1 = 'pyqtv1' # Force version 2
21 QT_API_PYQT_DEFAULT = 'pyqtdefault' # don't set SIP explicitly
21 QT_API_PYQT_DEFAULT = 'pyqtdefault' # use system default for version 1 vs. 2
22 QT_API_PYSIDE = 'pyside'
22 QT_API_PYSIDE = 'pyside'
23
23
24
24
@@ -73,7 +73,7 b' def loaded_api():'
73
73
74 Returns
74 Returns
75 -------
75 -------
76 None, 'pyside', 'pyqt', or 'pyqtv1'
76 None, 'pyside', 'pyqt', 'pyqt5', or 'pyqtv1'
77 """
77 """
78 if 'PyQt4.QtCore' in sys.modules:
78 if 'PyQt4.QtCore' in sys.modules:
79 if qtapi_version() == 2:
79 if qtapi_version() == 2:
General Comments 0
You need to be logged in to leave comments. Login now