diff --git a/NEWS b/NEWS index 599fcbe74..d3e21ebb2 100644 --- a/NEWS +++ b/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: diff --git a/python/spot/jupyter.py b/python/spot/jupyter.py index 0c4dc5a76..7b933db9f 100644 --- a/python/spot/jupyter.py +++ b/python/spot/jupyter.py @@ -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_() diff --git a/tests/python/alternation.ipynb b/tests/python/alternation.ipynb index 20d543ba7..c96896f59 100644 --- a/tests/python/alternation.ipynb +++ b/tests/python/alternation.ipynb @@ -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')" ] }, {