python: add a show= keyword to display_inline()
* python/spot/jupyter.py: Here. * tests/python/alternation.ipynb: Use it. * NEWS: Mention the above notebook as usage example.
This commit is contained in:
parent
60898b6d22
commit
9361bd9401
3 changed files with 15 additions and 10 deletions
4
NEWS
4
NEWS
|
|
@ -72,7 +72,9 @@ New in spot 2.5.3.dev (not yet released)
|
|||
Python:
|
||||
|
||||
- New spot.jupyter package. This currently contains a function for
|
||||
displaying several argument side by side in a Jupyter notebook.
|
||||
displaying several arguments side by side in a Jupyter notebook.
|
||||
See https://spot.lrde.epita.fr/ipynb/alternation.html for some
|
||||
examples.
|
||||
|
||||
Bugs fixed:
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ Auxiliary functions for Spot's Python bindings.
|
|||
|
||||
from IPython.display import display, HTML
|
||||
|
||||
def display_inline(*args, per_row=None):
|
||||
def display_inline(*args, per_row=None, show=None):
|
||||
"""
|
||||
This is a wrapper around IPython's `display()` to display multiple
|
||||
elements in a row, without forced line break between them.
|
||||
|
|
@ -36,7 +36,9 @@ def display_inline(*args, per_row=None):
|
|||
width = 'width:{}%;'.format(100//per_row)
|
||||
for arg in args:
|
||||
dpy = 'inline-block'
|
||||
if hasattr(arg, '_repr_svg_'):
|
||||
if show is not None and hasattr(arg, 'show'):
|
||||
rep = arg.show(show)._repr_svg_()
|
||||
elif hasattr(arg, '_repr_svg_'):
|
||||
rep = arg._repr_svg_()
|
||||
elif hasattr(arg, '_repr_html_'):
|
||||
rep = arg._repr_html_()
|
||||
|
|
|
|||
|
|
@ -715,7 +715,9 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If the state labels take too much space, you can reduce the size of the automaton by forcing states to be numbered with option `1`. The original label is still displayed as a tooltip when the mouse is over the state."
|
||||
"If the state labels take too much space, you can reduce the size of the automaton by forcing states to be numbered with option `1`. The original label is still displayed as a tooltip when the mouse is over the state.\n",
|
||||
"\n",
|
||||
"Note that passing option `show=...` to `display_inline` is similar to calling `aut.show(...)` on each argument."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -1359,7 +1361,7 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"display_inline(aut1.show('.bav1'), aut2.show('.bav1'), aut3.show('.bav1'), aut4.show('.bav1'), aut5.show('.bav1'))"
|
||||
"display_inline(aut1, aut2, aut3, aut4, aut5, show='.bav1')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -1371,7 +1373,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
|
@ -1947,7 +1949,7 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"display_inline(aut1.show('.bav1u'), aut2.show('.bav1u'), aut3.show('.bav1u'), aut4.show('.bav1u'), aut5.show('.bav1u'))"
|
||||
"display_inline(aut1, aut2, aut3, aut4, aut5, show='.bav1u')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -1959,7 +1961,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
|
@ -2579,8 +2581,7 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"display_inline(aut1.show('.bav1us'), aut2.show('.bav1us'), aut3.show('.bav1us'), \n",
|
||||
" aut4.show('.bav1us'), aut5.show('.bav1us'))"
|
||||
"display_inline(aut1, aut2, aut3, aut4, aut5, show='.bav1us')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue