##// END OF EJS Templates
added QT_API_DEFAULT Qt option. Fixed reversed MPL qt logic test.
Chris Beaumont -
Show More
@@ -37,7 +37,7 b' import sys'
37 from IPython.utils.warn import warn
37 from IPython.utils.warn import warn
38 from IPython.utils.version import check_version
38 from IPython.utils.version import check_version
39 from IPython.external.qt_loaders import (load_qt, QT_API_PYSIDE,
39 from IPython.external.qt_loaders import (load_qt, QT_API_PYSIDE,
40 QT_API_PYQT, QT_API_PYQTv1,
40 QT_API_PYQT, QT_API_PYQT_DEFAULT,
41 loaded_api)
41 loaded_api)
42
42
43 #Constraints placed on an imported matplotlib
43 #Constraints placed on an imported matplotlib
@@ -50,7 +50,7 b' def matplotlib_options(mpl):'
50 if mpqt.lower() == 'pyside':
50 if mpqt.lower() == 'pyside':
51 return [QT_API_PYSIDE]
51 return [QT_API_PYSIDE]
52 elif mpqt.lower() == 'pyqt4':
52 elif mpqt.lower() == 'pyqt4':
53 return [QT_API_PYQTv1]
53 return [QT_API_PYQT_DEFAULT]
54 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
54 raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
55 mpqt)
55 mpqt)
56
56
@@ -65,13 +65,13 b' def get_options():'
65
65
66 mpl = sys.modules.get('matplotlib', None)
66 mpl = sys.modules.get('matplotlib', None)
67
67
68 if mpl is not None and check_version(mpl.__version__, '1.0.2'):
68 if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
69 #1.0.1 only supports PyQt4 v1
69 #1.0.1 only supports PyQt4 v1
70 return [QT_API_PYQTv1]
70 return [QT_API_PYQT_DEFAULT]
71
71
72 if os.environ.get('QT_API', None) is None:
72 if os.environ.get('QT_API', None) is None:
73 #no ETS variable. Ask mpl, then use either
73 #no ETS variable. Ask mpl, then use either
74 return matplotlib_options(mpl) or [QT_API_PYQTv1, QT_API_PYSIDE]
74 return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
75
75
76 #ETS variable present. Will fallback to external.qt
76 #ETS variable present. Will fallback to external.qt
77 return None
77 return None
@@ -16,6 +16,7 b' from IPython.utils.version import check_version'
16 # Available APIs.
16 # Available APIs.
17 QT_API_PYQT = 'pyqt'
17 QT_API_PYQT = 'pyqt'
18 QT_API_PYQTv1 = 'pyqtv1'
18 QT_API_PYQTv1 = 'pyqtv1'
19 QT_API_PYQT_DEFAULT = 'pyqtdefault' # don't set SIP explicitly
19 QT_API_PYSIDE = 'pyside'
20 QT_API_PYSIDE = 'pyside'
20
21
21
22
@@ -23,7 +24,6 b' class ImportDenier(object):'
23 """Import Hook that will guard against bad Qt imports
24 """Import Hook that will guard against bad Qt imports
24 once IPython commits to a specific binding
25 once IPython commits to a specific binding
25 """
26 """
26 __forbidden = set()
27
27
28 def __init__(self):
28 def __init__(self):
29 self.__forbidden = None
29 self.__forbidden = None
@@ -84,7 +84,7 b' def has_binding(api):'
84
84
85 Parameters
85 Parameters
86 ----------
86 ----------
87 api : str [ 'pyqtv1' | 'pyqt' | 'pyside']
87 api : str [ 'pyqtv1' | 'pyqt' | 'pyside' | 'pyqtdefault']
88 Which module to check for
88 Which module to check for
89
89
90 Returns
90 Returns
@@ -96,7 +96,8 b' def has_binding(api):'
96 # check for complete presence before importing
96 # check for complete presence before importing
97 module_name = {QT_API_PYSIDE: 'PySide',
97 module_name = {QT_API_PYSIDE: 'PySide',
98 QT_API_PYQT: 'PyQt4',
98 QT_API_PYQT: 'PyQt4',
99 QT_API_PYQTv1: 'PyQt4'}
99 QT_API_PYQTv1: 'PyQt4',
100 QT_API_PYQT_DEFAULT: 'PyQt4'}
100 module_name = module_name[api]
101 module_name = module_name[api]
101
102
102 import imp
103 import imp
@@ -136,22 +137,36 b' def qtapi_version():'
136
137
137 def can_import(api):
138 def can_import(api):
138 """Safely query whether an API is importable, without importing it"""
139 """Safely query whether an API is importable, without importing it"""
140 if not has_binding(api):
141 return False
142
139 current = loaded_api()
143 current = loaded_api()
140 return has_binding(api) and current in [api, None]
144 if api == QT_API_PYQT_DEFAULT:
145 return current in [QT_API_PYQT, QT_API_PYQTv1, None]
146 else:
147 return current in [api, None]
141
148
142
149
143 def import_pyqt4(version=2):
150 def import_pyqt4(version=2):
144 """
151 """
145 Import PyQt4
152 Import PyQt4
146
153
154 Parameters
155 ----------
156 version : 1, 2, or None
157 Which QString/QVariant API to use. Set to None to use the system
158 default
159
147 ImportErrors rasied within this function are non-recoverable
160 ImportErrors rasied within this function are non-recoverable
148 """
161 """
149 # The new-style string API (version=2) automatically
162 # The new-style string API (version=2) automatically
150 # converts QStrings to Unicode Python strings. Also, automatically unpacks
163 # converts QStrings to Unicode Python strings. Also, automatically unpacks
151 # QVariants to their underlying objects.
164 # QVariants to their underlying objects.
152 import sip
165 import sip
153 sip.setapi('QString', version)
166
154 sip.setapi('QVariant', version)
167 if version is not None:
168 sip.setapi('QString', version)
169 sip.setapi('QVariant', version)
155
170
156 from PyQt4 import QtGui, QtCore, QtSvg
171 from PyQt4 import QtGui, QtCore, QtSvg
157
172
@@ -163,6 +178,8 b' def import_pyqt4(version=2):'
163 QtCore.Signal = QtCore.pyqtSignal
178 QtCore.Signal = QtCore.pyqtSignal
164 QtCore.Slot = QtCore.pyqtSlot
179 QtCore.Slot = QtCore.pyqtSlot
165
180
181 # query for the API version (in case version == None)
182 version = sip.getapi('QString')
166 api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
183 api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
167 return QtCore, QtGui, QtSvg, api
184 return QtCore, QtGui, QtSvg, api
168
185
@@ -205,21 +222,24 b' def load_qt(api_options):'
205 """
222 """
206 loaders = {QT_API_PYSIDE: import_pyside,
223 loaders = {QT_API_PYSIDE: import_pyside,
207 QT_API_PYQT: import_pyqt4,
224 QT_API_PYQT: import_pyqt4,
208 QT_API_PYQTv1: partial(import_pyqt4, version=1)
225 QT_API_PYQTv1: partial(import_pyqt4, version=1),
226 QT_API_PYQT_DEFAULT: partial(import_pyqt4, version=None)
209 }
227 }
210
228
211 for api in api_options:
229 for api in api_options:
212
230
213 if api not in loaders:
231 if api not in loaders:
214 raise RuntimeError(
232 raise RuntimeError(
215 "Invalid Qt API %r, valid values are: %r, %r, %r" %
233 "Invalid Qt API %r, valid values are: %r, %r, %r, %r" %
216 (api, QT_API_PYSIDE, QT_API_PYQT, QT_API_PYQTv1))
234 (api, QT_API_PYSIDE, QT_API_PYQT,
235 QT_API_PYQTv1, QT_API_PYQT_DEFAULT))
217
236
218 if not can_import(api):
237 if not can_import(api):
219 continue
238 continue
220
239
221 #cannot safely recover from an ImportError during this
240 #cannot safely recover from an ImportError during this
222 result = loaders[api]()
241 result = loaders[api]()
242 api = result[-1] # changed if api = QT_API_PYQT_DEFAULT
223 commit_api(api)
243 commit_api(api)
224 return result
244 return result
225 else:
245 else:
General Comments 0
You need to be logged in to leave comments. Login now