__init__.py
62 lines
| 1.2 KiB
| text/x-python
|
PythonLexer
Thomas Kluyver
|
r21934 | import importlib | ||
import os | ||||
aliases = { | ||||
Thomas Kluyver
|
r21941 | 'qt4': 'qt', | ||
Thomas Kluyver
|
r22118 | 'gtk2': 'gtk', | ||
Thomas Kluyver
|
r21934 | } | ||
Thomas Kluyver
|
r22118 | backends = [ | ||
Thomas A Caswell
|
r26684 | "qt", | ||
"qt4", | ||||
"qt5", | ||||
"qt6", | ||||
"gtk", | ||||
"gtk2", | ||||
"gtk3", | ||||
Elliott Sales de Andrade
|
r26726 | "gtk4", | ||
Thomas A Caswell
|
r26684 | "tk", | ||
"wx", | ||||
"pyglet", | ||||
"glut", | ||||
"osx", | ||||
"asyncio", | ||||
Thomas Kluyver
|
r22118 | ] | ||
Thomas Kluyver
|
r22613 | registered = {} | ||
def register(name, inputhook): | ||||
"""Register the function *inputhook* as an event loop integration.""" | ||||
registered[name] = inputhook | ||||
Thomas A Caswell
|
r26683 | |||
Thomas Kluyver
|
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
|
r22613 | ', '.join(backends + sorted(registered))) | ||
Thomas Kluyver
|
r22118 | |||
Thomas A Caswell
|
r26683 | |||
Thomas Kluyver
|
r22913 | def get_inputhook_name_and_func(gui): | ||
Thomas Kluyver
|
r22613 | if gui in registered: | ||
Thomas Kluyver
|
r22913 | return gui, registered[gui] | ||
Thomas Kluyver
|
r22613 | |||
Thomas Kluyver
|
r22118 | if gui not in backends: | ||
raise UnknownBackend(gui) | ||||
Thomas Kluyver
|
r21934 | if gui in aliases: | ||
Thomas Kluyver
|
r22913 | return get_inputhook_name_and_func(aliases[gui]) | ||
Thomas Kluyver
|
r21934 | |||
Thomas Kluyver
|
r22913 | gui_mod = gui | ||
Thomas A Caswell
|
r26684 | if gui == "qt5": | ||
os.environ["QT_API"] = "pyqt5" | ||||
gui_mod = "qt" | ||||
elif gui == "qt6": | ||||
os.environ["QT_API"] = "pyqt6" | ||||
gui_mod = "qt" | ||||
Thomas Kluyver
|
r21934 | |||
Thomas Kluyver
|
r22913 | mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod) | ||
return gui, mod.inputhook | ||||