##// END OF EJS Templates
Shaperilio/qtgui fixes (#13957)...
Shaperilio/qtgui fixes (#13957) I started using the released version of my `PySide6`-enabling changes and noted some problems. In this PR, I fix those, and also overall improve the feedback to the user when a GUI event loop is hooked in: - Report which event loop is running when using `%gui <some GUI>`; e.g. `%gui qt` will show `Installed qt6 event loop hook.` - Report when the event loop is disabled; i.e. `%gui` will show `GUI event loop hook disabled.` if an event loop hook was installed, or `No event loop hook running.` if nothing was installed. - Requesting a second event loop will give the message `Shell is already running a gui event loop for <some GUI>. Call with no arguments to disable current loop.` - Requesting a different version of Qt, i.e. `%gui qt6` followed by `%gui` followed by `%gui qt5` will show `Cannot switch Qt versions for this session; will use qt6.` followed by `Installed qt6 event loop hook.` (Fixes / improves #13864)

File last commit:

r27495:1a9d9554
r28163:88d1fedc merge
Show More
autogen_magics.py
66 lines | 2.0 KiB | text/x-python | PythonLexer
from pathlib import Path
from IPython.core.alias import Alias
from IPython.core.interactiveshell import InteractiveShell
from IPython.core.magic import MagicAlias
from IPython.utils.text import dedent, indent
shell = InteractiveShell.instance()
magics = shell.magics_manager.magics
def _strip_underline(line):
chars = set(line.strip())
if len(chars) == 1 and ("-" in chars or "=" in chars):
return ""
else:
return line
def format_docstring(func):
docstring = (func.__doc__ or "Undocumented").rstrip()
docstring = indent(dedent(docstring))
# Sphinx complains if indented bits have rst headings in, so strip out
# any underlines in the docstring.
lines = [_strip_underline(l) for l in docstring.splitlines()]
return "\n".join(lines)
output = [
"Line magics",
"===========",
"",
]
# Case insensitive sort by name
def sortkey(s): return s[0].lower()
for name, func in sorted(magics["line"].items(), key=sortkey):
if isinstance(func, Alias) or isinstance(func, MagicAlias):
# Aliases are magics, but shouldn't be documented here
# Also skip aliases to other magics
continue
output.extend([".. magic:: {}".format(name),
"",
format_docstring(func),
""])
output.extend([
"Cell magics",
"===========",
"",
])
for name, func in sorted(magics["cell"].items(), key=sortkey):
if name == "!":
# Special case - don't encourage people to use %%!
continue
if func == magics["line"].get(name, "QQQP"):
# Don't redocument line magics that double as cell magics
continue
if isinstance(func, MagicAlias):
continue
output.extend([".. cellmagic:: {}".format(name),
"",
format_docstring(func),
""])
src_path = Path(__file__).parent
dest = src_path.joinpath("source", "interactive", "magics-generated.txt")
dest.write_text("\n".join(output), encoding="utf-8")