##// END OF EJS Templates
Merge pull request #13112 from meeseeksmachine/auto-backport-of-pr-13111-on-7.x...
Merge pull request #13112 from meeseeksmachine/auto-backport-of-pr-13111-on-7.x Backport PR #13111 on branch 7.x (7.27 what's new.)

File last commit:

r26738:21203eaf
r26743:38769273 merge
Show More
__init__.py
62 lines | 1.2 KiB | text/x-python | PythonLexer
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 import importlib
import os
aliases = {
Thomas Kluyver
Add prompt_toolkit input hooks for wx
r21941 'qt4': 'qt',
Thomas Kluyver
Better error message for unknown input hook...
r22118 'gtk2': 'gtk',
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 }
Thomas Kluyver
Better error message for unknown input hook...
r22118 backends = [
Matthias Bussonnier
Backport PR #13085: ENH: add support for Qt6 input hooks
r26711 "qt",
"qt4",
"qt5",
"qt6",
"gtk",
"gtk2",
"gtk3",
Matthias Bussonnier
Backport PR #13101: Add input hooks for GTK4.
r26738 "gtk4",
Matthias Bussonnier
Backport PR #13085: ENH: add support for Qt6 input hooks
r26711 "tk",
"wx",
"pyglet",
"glut",
"osx",
"asyncio",
Thomas Kluyver
Better error message for unknown input hook...
r22118 ]
Thomas Kluyver
Update docs and add registration interface for inputhooks
r22613 registered = {}
def register(name, inputhook):
"""Register the function *inputhook* as an event loop integration."""
registered[name] = inputhook
Matthias Bussonnier
Backport PR #13085: ENH: add support for Qt6 input hooks
r26711
Thomas Kluyver
Better error message for unknown input hook...
r22118 class UnknownBackend(KeyError):
def __init__(self, name):
self.name = name
def __str__(self):
return ("No event loop integration for {!r}. "
"Supported event loops are: {}").format(self.name,
Thomas Kluyver
Update docs and add registration interface for inputhooks
r22613 ', '.join(backends + sorted(registered)))
Thomas Kluyver
Better error message for unknown input hook...
r22118
Matthias Bussonnier
Backport PR #13085: ENH: add support for Qt6 input hooks
r26711
Thomas Kluyver
Let IPython.lib.guisupport detect terminal-integrated event loops...
r22913 def get_inputhook_name_and_func(gui):
Thomas Kluyver
Update docs and add registration interface for inputhooks
r22613 if gui in registered:
Thomas Kluyver
Let IPython.lib.guisupport detect terminal-integrated event loops...
r22913 return gui, registered[gui]
Thomas Kluyver
Update docs and add registration interface for inputhooks
r22613
Thomas Kluyver
Better error message for unknown input hook...
r22118 if gui not in backends:
raise UnknownBackend(gui)
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934 if gui in aliases:
Thomas Kluyver
Let IPython.lib.guisupport detect terminal-integrated event loops...
r22913 return get_inputhook_name_and_func(aliases[gui])
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934
Thomas Kluyver
Let IPython.lib.guisupport detect terminal-integrated event loops...
r22913 gui_mod = gui
Matthias Bussonnier
Backport PR #13085: ENH: add support for Qt6 input hooks
r26711 if gui == "qt5":
os.environ["QT_API"] = "pyqt5"
gui_mod = "qt"
elif gui == "qt6":
os.environ["QT_API"] = "pyqt6"
gui_mod = "qt"
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934
Thomas Kluyver
Let IPython.lib.guisupport detect terminal-integrated event loops...
r22913 mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod)
return gui, mod.inputhook