##// END OF EJS Templates
Read each from stream until separator found or buffer is full
Read each from stream until separator found or buffer is full

File last commit:

r28149:45f33f31
r28217:a2b2dea9
Show More
__init__.py
138 lines | 3.5 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 = [
Thomas A Caswell
STY: apply darker
r26684 "qt",
"qt5",
"qt6",
"gtk",
"gtk2",
"gtk3",
Elliott Sales de Andrade
Add input hooks for GTK4.
r26726 "gtk4",
Thomas A Caswell
STY: apply darker
r26684 "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
Thomas A Caswell
ENH: add support for Qt6 input hooks...
r26683
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
Thomas A Caswell
ENH: add support for Qt6 input hooks...
r26683
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990 def set_qt_api(gui):
"""Sets the `QT_API` environment variable if it isn't already set."""
Emilio Graff
Use existing constants
r27998 qt_api = os.environ.get("QT_API", None)
Emilio Graff
Keep track of Qt version since it can't change
r27992
Emilio Graff
Use existing constants
r27998 from IPython.external.qt_loaders import (
QT_API_PYQT,
QT_API_PYQT5,
QT_API_PYQT6,
QT_API_PYSIDE,
QT_API_PYSIDE2,
QT_API_PYSIDE6,
QT_API_PYQTv1,
loaded_api,
)
loaded = loaded_api()
qt_env2gui = {
Emilio Graff
Formatting
r28001 QT_API_PYSIDE: "qt4",
QT_API_PYQTv1: "qt4",
QT_API_PYQT: "qt4",
QT_API_PYSIDE2: "qt5",
QT_API_PYQT5: "qt5",
QT_API_PYSIDE6: "qt6",
QT_API_PYQT6: "qt6",
Emilio Graff
Use existing constants
r27998 }
Emilio Graff
Formatting
r28001 if loaded is not None and gui != "qt":
Emilio Graff
Use existing constants
r27998 if qt_env2gui[loaded] != gui:
Emilio Graff
Address @ccordoba12's comments
r28046 print(
Emilio Graff
Improve error message....
r28142 f"Cannot switch Qt versions for this session; will use {qt_env2gui[loaded]}."
Emilio Graff
Keep track of Qt version since it can't change
r27992 )
Emilio Graff
Explictly return which Qt gui has been enabled.
r28145 return qt_env2gui[loaded]
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990
Emilio Graff
Formatting
r28001 if qt_api is not None and gui != "qt":
Emilio Graff
Use existing constants
r27998 if qt_env2gui[qt_api] != gui:
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990 print(
f'Request for "{gui}" will be ignored because `QT_API` '
f'environment variable is set to "{qt_api}"'
)
Emilio Graff
Explictly return which Qt gui has been enabled.
r28145 return qt_env2gui[qt_api]
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990 else:
Emilio Graff
Remove direct support for Qt4...
r28021 if gui == "qt5":
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990 try:
import PyQt5 # noqa
os.environ["QT_API"] = "pyqt5"
except ImportError:
try:
import PySide2 # noqa
os.environ["QT_API"] = "pyside2"
except ImportError:
os.environ["QT_API"] = "pyqt5"
elif gui == "qt6":
try:
import PyQt6 # noqa
os.environ["QT_API"] = "pyqt6"
except ImportError:
try:
import PySide6 # noqa
os.environ["QT_API"] = "pyside6"
except ImportError:
os.environ["QT_API"] = "pyqt6"
elif gui == "qt":
# Don't set QT_API; let IPython logic choose the version.
if "QT_API" in os.environ.keys():
del os.environ["QT_API"]
else:
Emilio Graff
Formatting
r28049 print(f'Unrecognized Qt version: {gui}. Should be "qt5", "qt6", or "qt".')
Emilio Graff
@ccordoba12's suggestions
r28149 return
Emilio Graff
Explictly return which Qt gui has been enabled.
r28145 # Import it now so we can figure out which version it is.
from IPython.external.qt_for_kernel import QT_API
Emilio Graff
Formatting
r28148
Emilio Graff
Explictly return which Qt gui has been enabled.
r28145 return qt_env2gui[QT_API]
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990
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
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990 if gui.startswith("qt"):
Emilio Graff
Explictly return which Qt gui has been enabled.
r28145 gui = set_qt_api(gui)
Thomas A Caswell
STY: apply darker
r26684 gui_mod = "qt"
Thomas Kluyver
Write & borrow some inputhooks for prompt_toolkit
r21934
Emilio Graff
Bring in Qt import logic from `ipykernel`...
r27990 mod = importlib.import_module("IPython.terminal.pt_inputhooks." + gui_mod)
Thomas Kluyver
Let IPython.lib.guisupport detect terminal-integrated event loops...
r22913 return gui, mod.inputhook