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