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', 'pyqtv
(api_options)
| 327 | |
| 328 | |
| 329 | def load_qt(api_options): |
| 330 | """ |
| 331 | Attempt to import Qt, given a preference list |
| 332 | of permissible bindings |
| 333 | |
| 334 | It is safe to call this function multiple times. |
| 335 | |
| 336 | Parameters |
| 337 | ---------- |
| 338 | api_options : List of strings |
| 339 | The order of APIs to try. Valid items are 'pyside', 'pyside2', |
| 340 | 'pyqt', 'pyqt5', 'pyqtv1' and 'pyqtdefault' |
| 341 | |
| 342 | Returns |
| 343 | ------- |
| 344 | A tuple of QtCore, QtGui, QtSvg, QT_API |
| 345 | The first three are the Qt modules. The last is the |
| 346 | string indicating which module was loaded. |
| 347 | |
| 348 | Raises |
| 349 | ------ |
| 350 | ImportError, if it isn't possible to import any requested |
| 351 | bindings (either because they aren't installed, or because |
| 352 | an incompatible library has already been installed) |
| 353 | """ |
| 354 | loaders = { |
| 355 | # Qt6 |
| 356 | QT_API_PYQT6: import_pyqt6, |
| 357 | QT_API_PYSIDE6: import_pyside6, |
| 358 | # Qt5 |
| 359 | QT_API_PYQT5: import_pyqt5, |
| 360 | QT_API_PYSIDE2: import_pyside2, |
| 361 | # Qt4 |
| 362 | QT_API_PYSIDE: import_pyside, |
| 363 | QT_API_PYQT: import_pyqt4, |
| 364 | QT_API_PYQTv1: partial(import_pyqt4, version=1), |
| 365 | # default |
| 366 | QT_API_PYQT_DEFAULT: import_pyqt6, |
| 367 | } |
| 368 | |
| 369 | for api in api_options: |
| 370 | |
| 371 | if api not in loaders: |
| 372 | raise RuntimeError( |
| 373 | "Invalid Qt API %r, valid values are: %s" % |
| 374 | (api, ", ".join(["%r" % k for k in loaders.keys()]))) |
| 375 | |
| 376 | if not can_import(api): |
| 377 | continue |
| 378 | |
| 379 | #cannot safely recover from an ImportError during this |
| 380 | result = loaders[api]() |
| 381 | api = result[-1] # changed if api = QT_API_PYQT_DEFAULT |
| 382 | commit_api(api) |
| 383 | return result |
| 384 | else: |
| 385 | # Clear the environment variable since it doesn't work. |
| 386 | if "QT_API" in os.environ: |
no test coverage detected
searching dependent graphs…