diff --git a/IPython/external/qt_for_kernel.py b/IPython/external/qt_for_kernel.py index b3168f6..f883a85 100644 --- a/IPython/external/qt_for_kernel.py +++ b/IPython/external/qt_for_kernel.py @@ -23,6 +23,9 @@ if QT_API not set: else: use what QT_API says + Note that %gui's implementation will always set a `QT_API`, see + `IPython.terminal.pt_inputhooks.get_inputhook_name_and_func` + """ # NOTE: This is no longer an external, third-party module, and should be # considered part of IPython. For compatibility however, it is being kept in @@ -99,6 +102,7 @@ def get_options(): return [loaded] mpl = sys.modules.get('matplotlib', None) + print(f'{mpl=}') # will be None of matplotlib has not yet been imported if mpl is not None and tuple(mpl.__version__.split(".")) < ("1", "0", "2"): # 1.0.1 only supports PyQt4 v1 @@ -120,6 +124,7 @@ def get_options(): raise RuntimeError("Invalid Qt API %r, valid values are: %r" % (qt_api, ', '.join(_qt_apis))) else: + print(f'{qt_api=}') return [qt_api] diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index c867b55..31ef868 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -712,6 +712,7 @@ class TerminalInteractiveShell(InteractiveShell): active_eventloop = None def enable_gui(self, gui=None): if gui and (gui not in {"inline", "webagg"}): + # This hook runs with each cycle of the `prompt_toolkit`'s event loop. self.active_eventloop, self._inputhook = get_inputhook_name_and_func(gui) else: self.active_eventloop = self._inputhook = None diff --git a/IPython/terminal/pt_inputhooks/__init__.py b/IPython/terminal/pt_inputhooks/__init__.py index 69ff0ba..3095e99 100644 --- a/IPython/terminal/pt_inputhooks/__init__.py +++ b/IPython/terminal/pt_inputhooks/__init__.py @@ -55,8 +55,13 @@ def get_inputhook_name_and_func(gui): os.environ["QT_API"] = "pyqt5" gui_mod = "qt" elif gui == "qt6": + # XXX: this locks us into pyqt6 even if pyside6 is installed. os.environ["QT_API"] = "pyqt6" gui_mod = "qt" + print(f'{gui_mod=}') + # Note: `IPython.terminal.pt_inputhooks.qt` imports `IPython.external.qt_for_kernel` and that's + # where the environment variable locks us into `pyqt6`, despite the fact that it seems `PySide6` + # is supported. mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod) return gui, mod.inputhook diff --git a/IPython/terminal/pt_inputhooks/qt.py b/IPython/terminal/pt_inputhooks/qt.py index f1e710a..bed1e62 100644 --- a/IPython/terminal/pt_inputhooks/qt.py +++ b/IPython/terminal/pt_inputhooks/qt.py @@ -1,5 +1,6 @@ import sys import os +#`qt_for_kernel` will import the "best" qt version from IPython.external.qt_for_kernel import QtCore, QtGui, enum_helper from IPython import get_ipython @@ -63,6 +64,7 @@ def inputhook(context): timer = QtCore.QTimer() timer.timeout.connect(event_loop.quit) while not context.input_is_ready(): + # NOTE: run the event loop, and after 50 ms, call `quit` to exit it. timer.start(50) # 50 ms _exec(event_loop) timer.stop()