Show More
@@ -23,6 +23,9 b' if QT_API not set:' | |||||
23 | else: |
|
23 | else: | |
24 | use what QT_API says |
|
24 | use what QT_API says | |
25 |
|
25 | |||
|
26 | Note that %gui's implementation will always set a `QT_API`, see | |||
|
27 | `IPython.terminal.pt_inputhooks.get_inputhook_name_and_func` | |||
|
28 | ||||
26 | """ |
|
29 | """ | |
27 | # NOTE: This is no longer an external, third-party module, and should be |
|
30 | # NOTE: This is no longer an external, third-party module, and should be | |
28 | # considered part of IPython. For compatibility however, it is being kept in |
|
31 | # considered part of IPython. For compatibility however, it is being kept in | |
@@ -99,6 +102,7 b' def get_options():' | |||||
99 | return [loaded] |
|
102 | return [loaded] | |
100 |
|
103 | |||
101 | mpl = sys.modules.get('matplotlib', None) |
|
104 | mpl = sys.modules.get('matplotlib', None) | |
|
105 | print(f'{mpl=}') # will be None of matplotlib has not yet been imported | |||
102 |
|
106 | |||
103 | if mpl is not None and tuple(mpl.__version__.split(".")) < ("1", "0", "2"): |
|
107 | if mpl is not None and tuple(mpl.__version__.split(".")) < ("1", "0", "2"): | |
104 | # 1.0.1 only supports PyQt4 v1 |
|
108 | # 1.0.1 only supports PyQt4 v1 | |
@@ -120,6 +124,7 b' def get_options():' | |||||
120 | raise RuntimeError("Invalid Qt API %r, valid values are: %r" % |
|
124 | raise RuntimeError("Invalid Qt API %r, valid values are: %r" % | |
121 | (qt_api, ', '.join(_qt_apis))) |
|
125 | (qt_api, ', '.join(_qt_apis))) | |
122 | else: |
|
126 | else: | |
|
127 | print(f'{qt_api=}') | |||
123 | return [qt_api] |
|
128 | return [qt_api] | |
124 |
|
129 | |||
125 |
|
130 |
@@ -712,6 +712,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
712 | active_eventloop = None |
|
712 | active_eventloop = None | |
713 | def enable_gui(self, gui=None): |
|
713 | def enable_gui(self, gui=None): | |
714 | if gui and (gui not in {"inline", "webagg"}): |
|
714 | if gui and (gui not in {"inline", "webagg"}): | |
|
715 | # This hook runs with each cycle of the `prompt_toolkit`'s event loop. | |||
715 | self.active_eventloop, self._inputhook = get_inputhook_name_and_func(gui) |
|
716 | self.active_eventloop, self._inputhook = get_inputhook_name_and_func(gui) | |
716 | else: |
|
717 | else: | |
717 | self.active_eventloop = self._inputhook = None |
|
718 | self.active_eventloop = self._inputhook = None |
@@ -55,8 +55,13 b' def get_inputhook_name_and_func(gui):' | |||||
55 | os.environ["QT_API"] = "pyqt5" |
|
55 | os.environ["QT_API"] = "pyqt5" | |
56 | gui_mod = "qt" |
|
56 | gui_mod = "qt" | |
57 | elif gui == "qt6": |
|
57 | elif gui == "qt6": | |
|
58 | # XXX: this locks us into pyqt6 even if pyside6 is installed. | |||
58 | os.environ["QT_API"] = "pyqt6" |
|
59 | os.environ["QT_API"] = "pyqt6" | |
59 | gui_mod = "qt" |
|
60 | gui_mod = "qt" | |
60 |
|
61 | |||
|
62 | print(f'{gui_mod=}') | |||
|
63 | # Note: `IPython.terminal.pt_inputhooks.qt` imports `IPython.external.qt_for_kernel` and that's | |||
|
64 | # where the environment variable locks us into `pyqt6`, despite the fact that it seems `PySide6` | |||
|
65 | # is supported. | |||
61 | mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod) |
|
66 | mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod) | |
62 | return gui, mod.inputhook |
|
67 | return gui, mod.inputhook |
@@ -1,5 +1,6 b'' | |||||
1 | import sys |
|
1 | import sys | |
2 | import os |
|
2 | import os | |
|
3 | #`qt_for_kernel` will import the "best" qt version | |||
3 | from IPython.external.qt_for_kernel import QtCore, QtGui, enum_helper |
|
4 | from IPython.external.qt_for_kernel import QtCore, QtGui, enum_helper | |
4 | from IPython import get_ipython |
|
5 | from IPython import get_ipython | |
5 |
|
6 | |||
@@ -63,6 +64,7 b' def inputhook(context):' | |||||
63 | timer = QtCore.QTimer() |
|
64 | timer = QtCore.QTimer() | |
64 | timer.timeout.connect(event_loop.quit) |
|
65 | timer.timeout.connect(event_loop.quit) | |
65 | while not context.input_is_ready(): |
|
66 | while not context.input_is_ready(): | |
|
67 | # NOTE: run the event loop, and after 50 ms, call `quit` to exit it. | |||
66 | timer.start(50) # 50 ms |
|
68 | timer.start(50) # 50 ms | |
67 | _exec(event_loop) |
|
69 | _exec(event_loop) | |
68 | timer.stop() |
|
70 | timer.stop() |
General Comments 0
You need to be logged in to leave comments.
Login now