##// END OF EJS Templates
Use existing constants
Emilio Graff -
Show More
@@ -40,33 +40,41 b' class UnknownBackend(KeyError):'
40 ', '.join(backends + sorted(registered)))
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 def set_qt_api(gui):
43 def set_qt_api(gui):
48 """Sets the `QT_API` environment variable if it isn't already set."""
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:
48 from IPython.external.qt_loaders import (
53 if last_qt_version != gui:
49 QT_API_PYQT,
54 raise ValueError(
50 QT_API_PYQT5,
55 "Cannot switch Qt versions for this session; "
51 QT_API_PYQT6,
56 f"must use {last_qt_version}."
52 QT_API_PYSIDE,
53 QT_API_PYSIDE2,
54 QT_API_PYSIDE6,
55 QT_API_PYQTv1,
56 loaded_api,
57 )
58
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',
69 }
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]}.'
57 )
74 )
58
75
59 qt_api = os.environ.get("QT_API", None)
76 if qt_api is not None and gui != 'qt':
60 if qt_api is not None and gui != "qt":
77 if qt_env2gui[qt_api] != gui:
61 env2gui = {
62 "pyside": "qt4",
63 "pyqt": "qt4",
64 "pyside2": "qt5",
65 "pyqt5": "qt5",
66 "pyside6": "qt6",
67 "pyqt6": "qt6",
68 }
69 if env2gui[qt_api] != gui:
70 print(
78 print(
71 f'Request for "{gui}" will be ignored because `QT_API` '
79 f'Request for "{gui}" will be ignored because `QT_API` '
72 f'environment variable is set to "{qt_api}"'
80 f'environment variable is set to "{qt_api}"'
@@ -119,9 +127,6 b' def set_qt_api(gui):'
119 f'Unrecognized Qt version: {gui}. Should be "qt4", "qt5", "qt6", or "qt".'
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 def get_inputhook_name_and_func(gui):
131 def get_inputhook_name_and_func(gui):
127 print(f"`get_inputhook_name_and_func` called with {gui=}")
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