Show More
@@ -33,26 +33,36 b' import sys' | |||
|
33 | 33 | |
|
34 | 34 | from IPython.utils.version import check_version |
|
35 | 35 | from IPython.external.qt_loaders import ( |
|
36 | load_qt, loaded_api, enum_factory, | |
|
36 | load_qt, | |
|
37 | loaded_api, | |
|
38 | enum_factory, | |
|
37 | 39 | # QT6 |
|
38 |
QT_API_PYQT6, |
|
|
40 | QT_API_PYQT6, | |
|
41 | QT_API_PYSIDE6, | |
|
39 | 42 | # QT5 |
|
40 |
QT_API_PYQT5, |
|
|
43 | QT_API_PYQT5, | |
|
44 | QT_API_PYSIDE2, | |
|
41 | 45 | # QT4 |
|
42 | QT_API_PYQTv1, QT_API_PYQT, QT_API_PYSIDE, | |
|
46 | QT_API_PYQTv1, | |
|
47 | QT_API_PYQT, | |
|
48 | QT_API_PYSIDE, | |
|
43 | 49 | # default |
|
44 | QT_API_PYQT_DEFAULT | |
|
50 | QT_API_PYQT_DEFAULT, | |
|
45 | 51 | ) |
|
46 | 52 | |
|
47 | 53 | _qt_apis = ( |
|
48 | 54 | # QT6 |
|
49 |
QT_API_PYQT6, |
|
|
55 | QT_API_PYQT6, | |
|
56 | QT_API_PYSIDE6, | |
|
50 | 57 | # QT5 |
|
51 |
QT_API_PYQT5, |
|
|
58 | QT_API_PYQT5, | |
|
59 | QT_API_PYSIDE2, | |
|
52 | 60 | # QT4 |
|
53 | QT_API_PYQTv1, QT_API_PYQT, QT_API_PYSIDE, | |
|
61 | QT_API_PYQTv1, | |
|
62 | QT_API_PYQT, | |
|
63 | QT_API_PYSIDE, | |
|
54 | 64 | # default |
|
55 | QT_API_PYQT_DEFAULT | |
|
65 | QT_API_PYQT_DEFAULT, | |
|
56 | 66 | ) |
|
57 | 67 | |
|
58 | 68 | |
@@ -105,7 +115,7 b' def get_options():' | |||
|
105 | 115 | QT_API_PYQT5, |
|
106 | 116 | QT_API_PYSIDE2, |
|
107 | 117 | QT_API_PYQT, |
|
108 | QT_API_PYSIDE | |
|
118 | QT_API_PYSIDE, | |
|
109 | 119 | ] |
|
110 | 120 | elif qt_api not in _qt_apis: |
|
111 | 121 | raise RuntimeError("Invalid Qt API %r, valid values are: %r" % |
@@ -25,25 +25,25 b" QT_API_PYQT5 = 'pyqt5'" | |||
|
25 | 25 | QT_API_PYSIDE2 = 'pyside2' |
|
26 | 26 | |
|
27 | 27 | # Qt4 |
|
28 |
QT_API_PYQT = |
|
|
29 |
QT_API_PYQTv1 = |
|
|
30 |
QT_API_PYSIDE = |
|
|
28 | QT_API_PYQT = "pyqt" # Force version 2 | |
|
29 | QT_API_PYQTv1 = "pyqtv1" # Force version 2 | |
|
30 | QT_API_PYSIDE = "pyside" | |
|
31 | 31 | |
|
32 |
QT_API_PYQT_DEFAULT = |
|
|
32 | QT_API_PYQT_DEFAULT = "pyqtdefault" # use system default for version 1 vs. 2 | |
|
33 | 33 | |
|
34 | 34 | api_to_module = { |
|
35 | 35 | # Qt6 |
|
36 | 36 | QT_API_PYQT6: "PyQt6", |
|
37 | 37 | QT_API_PYSIDE6: "PySide6", |
|
38 | 38 | # Qt5 |
|
39 |
QT_API_PYQT5: |
|
|
40 |
QT_API_PYSIDE2: |
|
|
39 | QT_API_PYQT5: "PyQt5", | |
|
40 | QT_API_PYSIDE2: "PySide2", | |
|
41 | 41 | # Qt4 |
|
42 |
QT_API_PYSIDE: |
|
|
43 |
QT_API_PYQT: |
|
|
44 |
QT_API_PYQTv1: |
|
|
42 | QT_API_PYSIDE: "PySide", | |
|
43 | QT_API_PYQT: "PyQt4", | |
|
44 | QT_API_PYQTv1: "PyQt4", | |
|
45 | 45 | # default |
|
46 |
QT_API_PYQT_DEFAULT: |
|
|
46 | QT_API_PYQT_DEFAULT: "PyQt6", | |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | |
@@ -104,12 +104,12 b' def loaded_api():' | |||
|
104 | 104 | return QT_API_PYQT5 |
|
105 | 105 | elif sys.modules.get("PySide2.QtCore"): |
|
106 | 106 | return QT_API_PYSIDE2 |
|
107 |
elif sys.modules.get( |
|
|
107 | elif sys.modules.get("PyQt4.QtCore"): | |
|
108 | 108 | if qtapi_version() == 2: |
|
109 | 109 | return QT_API_PYQT |
|
110 | 110 | else: |
|
111 | 111 | return QT_API_PYQTv1 |
|
112 |
elif sys.modules.get( |
|
|
112 | elif sys.modules.get("PySide.QtCore"): | |
|
113 | 113 | return QT_API_PYSIDE |
|
114 | 114 | |
|
115 | 115 | return None |
@@ -246,6 +246,7 b' def import_pyqt5():' | |||
|
246 | 246 | api = QT_API_PYQT5 |
|
247 | 247 | return QtCore, QtGuiCompat, QtSvg, api |
|
248 | 248 | |
|
249 | ||
|
249 | 250 | def import_pyqt6(): |
|
250 | 251 | """ |
|
251 | 252 | Import PyQt6 |
@@ -260,7 +261,7 b' def import_pyqt6():' | |||
|
260 | 261 | QtCore.Slot = QtCore.pyqtSlot |
|
261 | 262 | |
|
262 | 263 | # Join QtGui and QtWidgets for Qt4 compatibility. |
|
263 |
QtGuiCompat = types.ModuleType( |
|
|
264 | QtGuiCompat = types.ModuleType("QtGuiCompat") | |
|
264 | 265 | QtGuiCompat.__dict__.update(QtGui.__dict__) |
|
265 | 266 | QtGuiCompat.__dict__.update(QtWidgets.__dict__) |
|
266 | 267 | |
@@ -293,6 +294,7 b' def import_pyside2():' | |||
|
293 | 294 | |
|
294 | 295 | return QtCore, QtGuiCompat, QtSvg, QT_API_PYSIDE2 |
|
295 | 296 | |
|
297 | ||
|
296 | 298 | def import_pyside6(): |
|
297 | 299 | """ |
|
298 | 300 | Import PySide6 |
@@ -302,7 +304,7 b' def import_pyside6():' | |||
|
302 | 304 | from PySide6 import QtGui, QtCore, QtSvg, QtWidgets, QtPrintSupport |
|
303 | 305 | |
|
304 | 306 | # Join QtGui and QtWidgets for Qt4 compatibility. |
|
305 |
QtGuiCompat = types.ModuleType( |
|
|
307 | QtGuiCompat = types.ModuleType("QtGuiCompat") | |
|
306 | 308 | QtGuiCompat.__dict__.update(QtGui.__dict__) |
|
307 | 309 | QtGuiCompat.__dict__.update(QtWidgets.__dict__) |
|
308 | 310 | QtGuiCompat.__dict__.update(QtPrintSupport.__dict__) |
@@ -388,6 +390,7 b' def load_qt(api_options):' | |||
|
388 | 390 | |
|
389 | 391 | def enum_factory(QT_API, QtCore): |
|
390 | 392 | """Construct an enum helper to account for PyQt5 <-> PyQt6 changes.""" |
|
393 | ||
|
391 | 394 | @lru_cache(None) |
|
392 | 395 | def _enum(name): |
|
393 | 396 | # foo.bar.Enum.Entry (PyQt6) <=> foo.bar.Entry (non-PyQt6). |
@@ -7,13 +7,19 b' aliases = {' | |||
|
7 | 7 | } |
|
8 | 8 | |
|
9 | 9 | backends = [ |
|
10 | 'qt', 'qt4', 'qt5', 'qt6', | |
|
11 | 'gtk', 'gtk2', 'gtk3', | |
|
12 |
|
|
|
13 | 'wx', | |
|
14 | 'pyglet', 'glut', | |
|
15 | 'osx', | |
|
16 | 'asyncio' | |
|
10 | "qt", | |
|
11 | "qt4", | |
|
12 | "qt5", | |
|
13 | "qt6", | |
|
14 | "gtk", | |
|
15 | "gtk2", | |
|
16 | "gtk3", | |
|
17 | "tk", | |
|
18 | "wx", | |
|
19 | "pyglet", | |
|
20 | "glut", | |
|
21 | "osx", | |
|
22 | "asyncio", | |
|
17 | 23 | ] |
|
18 | 24 | |
|
19 | 25 | registered = {} |
@@ -44,12 +50,12 b' def get_inputhook_name_and_func(gui):' | |||
|
44 | 50 | return get_inputhook_name_and_func(aliases[gui]) |
|
45 | 51 | |
|
46 | 52 | gui_mod = gui |
|
47 |
if gui == |
|
|
48 |
os.environ[ |
|
|
49 |
gui_mod = |
|
|
50 |
elif gui == |
|
|
51 |
os.environ[ |
|
|
52 |
gui_mod = |
|
|
53 | if gui == "qt5": | |
|
54 | os.environ["QT_API"] = "pyqt5" | |
|
55 | gui_mod = "qt" | |
|
56 | elif gui == "qt6": | |
|
57 | os.environ["QT_API"] = "pyqt6" | |
|
58 | gui_mod = "qt" | |
|
53 | 59 | |
|
54 | 60 | mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod) |
|
55 | 61 | return gui, mod.inputhook |
@@ -38,13 +38,13 b' def inputhook(context):' | |||
|
38 | 38 | ) |
|
39 | 39 | return |
|
40 | 40 | try: |
|
41 | QtCore.QApplication.setAttribute( | |
|
42 | QtCore.Qt.AA_EnableHighDpiScaling) | |
|
41 | QtCore.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) | |
|
43 | 42 | except AttributeError: # Only for Qt>=5.6, <6. |
|
44 | 43 | pass |
|
45 | 44 | try: |
|
46 | 45 | QtCore.QApplication.setHighDpiScaleFactorRoundingPolicy( |
|
47 |
QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough |
|
|
46 | QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough | |
|
47 | ) | |
|
48 | 48 | except AttributeError: # Only for Qt>=5.14. |
|
49 | 49 | pass |
|
50 | 50 | _appref = app = QtGui.QApplication([" "]) |
@@ -70,8 +70,7 b' def inputhook(context):' | |||
|
70 | 70 | # On POSIX platforms, we can use a file descriptor to quit the event |
|
71 | 71 | # loop when there is input ready to read. |
|
72 | 72 | notifier = QtCore.QSocketNotifier( |
|
73 | context.fileno(), | |
|
74 | enum_helper('QtCore.QSocketNotifier.Type').Read | |
|
73 | context.fileno(), enum_helper("QtCore.QSocketNotifier.Type").Read | |
|
75 | 74 | ) |
|
76 | 75 | try: |
|
77 | 76 | # connect the callback we care about before we turn it on |
General Comments 0
You need to be logged in to leave comments.
Login now