Attempt to import Qt, given a preference list of permissible bindings It is safe to call this function multiple times. Parameters ---------- api_options: List of strings The order of APIs to try. Valid items are 'pyside', 'pyside2', 'pyqt', 'pyqt5', 'pyqtv1
(api_options)
| 260 | |
| 261 | |
| 262 | def load_qt(api_options): |
| 263 | """ |
| 264 | Attempt to import Qt, given a preference list |
| 265 | of permissible bindings |
| 266 | |
| 267 | It is safe to call this function multiple times. |
| 268 | |
| 269 | Parameters |
| 270 | ---------- |
| 271 | api_options: List of strings |
| 272 | The order of APIs to try. Valid items are 'pyside', 'pyside2', |
| 273 | 'pyqt', 'pyqt5', 'pyqtv1' and 'pyqtdefault' |
| 274 | |
| 275 | Returns |
| 276 | ------- |
| 277 | |
| 278 | A tuple of QtCore, QtGui, QtSvg, QT_API |
| 279 | The first three are the Qt modules. The last is the |
| 280 | string indicating which module was loaded. |
| 281 | |
| 282 | Raises |
| 283 | ------ |
| 284 | ImportError, if it isn't possible to import any requested |
| 285 | bindings (either because they aren't installed, or because |
| 286 | an incompatible library has already been installed) |
| 287 | """ |
| 288 | loaders = { |
| 289 | QT_API_PYSIDE2: import_pyside2, |
| 290 | QT_API_PYSIDE: import_pyside, |
| 291 | QT_API_PYQT: import_pyqt4, |
| 292 | QT_API_PYQT5: import_pyqt5, |
| 293 | QT_API_PYQTv1: partial(import_pyqt4, version=1), |
| 294 | QT_API_PYQT_DEFAULT: partial(import_pyqt4, version=None) |
| 295 | } |
| 296 | |
| 297 | for api in api_options: |
| 298 | |
| 299 | if api not in loaders: |
| 300 | raise RuntimeError( |
| 301 | "Invalid Qt API %r, valid values are: %s" % |
| 302 | (api, ", ".join(["%r" % k for k in loaders.keys()]))) |
| 303 | |
| 304 | if not can_import(api): |
| 305 | continue |
| 306 | |
| 307 | #cannot safely recover from an ImportError during this |
| 308 | result = loaders[api]() |
| 309 | api = result[-1] # changed if api = QT_API_PYQT_DEFAULT |
| 310 | commit_api(api) |
| 311 | return result |
| 312 | else: |
| 313 | raise ImportError(""" |
| 314 | Could not load requested Qt binding. Please ensure that |
| 315 | PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available, |
| 316 | and only one is imported per session. |
| 317 | |
| 318 | Currently-imported Qt library: %r |
| 319 | PyQt4 available (requires QtCore, QtGui, QtSvg): %s |
no test coverage detected