MCPcopy Index your code
hub / github.com/ipython/ipython / set_qt_api

Function set_qt_api

IPython/terminal/pt_inputhooks/__init__.py:44–121  ·  view source on GitHub ↗

Sets the `QT_API` environment variable if it isn't already set.

(gui)

Source from the content-addressed store, hash-verified

42
43
44def set_qt_api(gui):
45 """Sets the `QT_API` environment variable if it isn't already set."""
46
47 qt_api = os.environ.get("QT_API", None)
48
49 from IPython.external.qt_loaders import (
50 QT_API_PYQT,
51 QT_API_PYQT5,
52 QT_API_PYQT6,
53 QT_API_PYSIDE,
54 QT_API_PYSIDE2,
55 QT_API_PYSIDE6,
56 QT_API_PYQTv1,
57 loaded_api,
58 )
59
60 loaded = loaded_api()
61
62 qt_env2gui = {
63 QT_API_PYSIDE: "qt4",
64 QT_API_PYQTv1: "qt4",
65 QT_API_PYQT: "qt4",
66 QT_API_PYSIDE2: "qt5",
67 QT_API_PYQT5: "qt5",
68 QT_API_PYSIDE6: "qt6",
69 QT_API_PYQT6: "qt6",
70 }
71 if loaded is not None and gui != "qt":
72 if qt_env2gui[loaded] != gui:
73 print(
74 f"Cannot switch Qt versions for this session; will use {qt_env2gui[loaded]}."
75 )
76 return qt_env2gui[loaded]
77
78 if qt_api is not None and gui != "qt":
79 if qt_env2gui[qt_api] != gui:
80 print(
81 f'Request for "{gui}" will be ignored because `QT_API` '
82 f'environment variable is set to "{qt_api}"'
83 )
84 return qt_env2gui[qt_api]
85 else:
86 if gui == "qt5":
87 try:
88 import PyQt5 # noqa
89
90 os.environ["QT_API"] = "pyqt5"
91 except ImportError:
92 try:
93 import PySide2 # noqa
94
95 os.environ["QT_API"] = "pyside2"
96 except ImportError:
97 os.environ["QT_API"] = "pyqt5"
98 elif gui == "qt6":
99 try:
100 import PyQt6 # noqa
101

Callers 2

_get_qt_versFunction · 0.90

Calls 3

loaded_apiFunction · 0.90
getMethod · 0.80
keysMethod · 0.80

Tested by 1

_get_qt_versFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…