##// END OF EJS Templates
Use existing constants
Emilio Graff -
Show More
@@ -40,33 +40,41 b' class UnknownBackend(KeyError):'
40 40 ', '.join(backends + sorted(registered)))
41 41
42 42
43 last_qt_version = None
44 """Stores which version (i.e. `gui`) was requested the first time."""
45
46
47 43 def set_qt_api(gui):
48 44 """Sets the `QT_API` environment variable if it isn't already set."""
49 45
50 global last_qt_version
46 qt_api = os.environ.get("QT_API", None)
51 47
52 if gui != "qt" and last_qt_version is not None:
53 if last_qt_version != gui:
54 raise ValueError(
55 "Cannot switch Qt versions for this session; "
56 f"must use {last_qt_version}."
48 from IPython.external.qt_loaders import (
49 QT_API_PYQT,
50 QT_API_PYQT5,
51 QT_API_PYQT6,
52 QT_API_PYSIDE,
53 QT_API_PYSIDE2,
54 QT_API_PYSIDE6,
55 QT_API_PYQTv1,
56 loaded_api,
57 57 )
58 58
59 qt_api = os.environ.get("QT_API", None)
60 if qt_api is not None and gui != "qt":
61 env2gui = {
62 "pyside": "qt4",
63 "pyqt": "qt4",
64 "pyside2": "qt5",
65 "pyqt5": "qt5",
66 "pyside6": "qt6",
67 "pyqt6": "qt6",
59 loaded = loaded_api()
60
61 qt_env2gui = {
62 QT_API_PYSIDE: 'qt4',
63 QT_API_PYQTv1: 'qt4',
64 QT_API_PYQT: 'qt4',
65 QT_API_PYSIDE2: 'qt5',
66 QT_API_PYQT5: 'qt5',
67 QT_API_PYSIDE6: 'qt6',
68 QT_API_PYQT6: 'qt6',
68 69 }
69 if env2gui[qt_api] != gui:
70 if loaded is not None and gui != 'qt':
71 if qt_env2gui[loaded] != gui:
72 raise ImportError(
73 f'Cannot switch Qt versions for this session; must use {qt_env2gui[loaded]}.'
74 )
75
76 if qt_api is not None and gui != 'qt':
77 if qt_env2gui[qt_api] != gui:
70 78 print(
71 79 f'Request for "{gui}" will be ignored because `QT_API` '
72 80 f'environment variable is set to "{qt_api}"'
@@ -119,9 +127,6 b' def set_qt_api(gui):'
119 127 f'Unrecognized Qt version: {gui}. Should be "qt4", "qt5", "qt6", or "qt".'
120 128 )
121 129
122 # Due to the import mechanism, we can't change Qt versions once we've chosen one. So we tag the
123 # version so we can check for this and give an error.
124 last_qt_version = gui
125 130
126 131 def get_inputhook_name_and_func(gui):
127 132 print(f"`get_inputhook_name_and_func` called with {gui=}")
General Comments 0
You need to be logged in to leave comments. Login now