Attempt to import Qt, given a preference list of permissible bindings It is safe to call this function multiple times. :param api_options: List of strings The order of APIs to try. Valid items are 'pyside', 'pyqt', and 'pyqtv1' Returns ------- A tuple
(api_options)
| 323 | |
| 324 | |
| 325 | def load_qt(api_options): |
| 326 | """ |
| 327 | Attempt to import Qt, given a preference list |
| 328 | of permissible bindings |
| 329 | |
| 330 | It is safe to call this function multiple times. |
| 331 | |
| 332 | :param api_options: List of strings |
| 333 | The order of APIs to try. Valid items are 'pyside', |
| 334 | 'pyqt', and 'pyqtv1' |
| 335 | |
| 336 | Returns |
| 337 | ------- |
| 338 | |
| 339 | A tuple of QtCore, QtGui, QtSvg, QT_API |
| 340 | The first three are the Qt modules. The last is the |
| 341 | string indicating which module was loaded. |
| 342 | |
| 343 | Raises |
| 344 | ------ |
| 345 | ImportError, if it isn't possible to import any requested |
| 346 | bindings (either becaues they aren't installed, or because |
| 347 | an incompatible library has already been installed) |
| 348 | """ |
| 349 | loaders = {QT_API_PYSIDE: import_pyside, |
| 350 | QT_API_PYQT: import_pyqt4, |
| 351 | QT_API_PYQTv1: partial(import_pyqt4, version=1), |
| 352 | QT_API_PYQT_DEFAULT: partial(import_pyqt4, version=None), |
| 353 | QT_MOCK: import_qtmock |
| 354 | } |
| 355 | |
| 356 | for api in api_options: |
| 357 | |
| 358 | if api not in loaders: |
| 359 | raise RuntimeError( |
| 360 | "Invalid Qt API %r, valid values are: %r, %r, %r, %r, %r" % |
| 361 | (api, QT_API_PYSIDE, QT_API_PYQT, |
| 362 | QT_API_PYQTv1, QT_API_PYQT_DEFAULT, QT_MOCK)) |
| 363 | |
| 364 | if not can_import(api): |
| 365 | continue |
| 366 | |
| 367 | #cannot safely recover from an ImportError during this |
| 368 | result = loaders[api]() |
| 369 | api = result[-1] # changed if api = QT_API_PYQT_DEFAULT |
| 370 | commit_api(api) |
| 371 | return result |
| 372 | else: |
| 373 | raise ImportError(""" |
| 374 | Could not load requested Qt binding. Please ensure that |
| 375 | PyQt4 >= 4.7 or PySide >= 1.0.3 is available, |
| 376 | and only one is imported per session. |
| 377 | |
| 378 | Currently-imported Qt library: %r |
| 379 | PyQt4 installed: %s |
| 380 | PySide >= 1.0.3 installed: %s |
| 381 | Tried to load: %r |
| 382 | """ % (loaded_api(), |
no test coverage detected