Commit e3b8ed7b authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

python: add a show_default option to setup()

* wrap/python/spot.py: Here.
* wrap/python/tests/decompose.ipynb: Use it to simplify the code.
parent d23eaec7
...@@ -46,6 +46,7 @@ def _extend(*classes): ...@@ -46,6 +46,7 @@ def _extend(*classes):
return classes[0] return classes[0]
return wrap return wrap
_show_default = None
def setup(**kwargs): def setup(**kwargs):
"""Configure Spot for fancy display. """Configure Spot for fancy display.
...@@ -68,6 +69,8 @@ def setup(**kwargs): ...@@ -68,6 +69,8 @@ def setup(**kwargs):
(default: '10.2,5') (default: '10.2,5')
font : str font : str
the font to use in the GraphViz output (default: 'Lato') the font to use in the GraphViz output (default: 'Lato')
show_default : str
default options for show()
""" """
import os import os
...@@ -78,6 +81,8 @@ def setup(**kwargs): ...@@ -78,6 +81,8 @@ def setup(**kwargs):
bullets = 'B' if kwargs.get('bullets', True) else '' bullets = 'B' if kwargs.get('bullets', True) else ''
d = 'rf({})'.format(kwargs.get('font', 'Lato')) + bullets d = 'rf({})'.format(kwargs.get('font', 'Lato')) + bullets
global _show_default
_show_default = kwargs.get('show_default', None)
os.environ['SPOT_DOTDEFAULT'] = d os.environ['SPOT_DOTDEFAULT'] = d
...@@ -122,11 +127,17 @@ class twa: ...@@ -122,11 +127,17 @@ class twa:
def _repr_svg_(self, opt=None): def _repr_svg_(self, opt=None):
"""Output the automaton as SVG""" """Output the automaton as SVG"""
ostr = ostringstream() ostr = ostringstream()
if opt is None:
global _show_default
opt = _show_default
print_dot(ostr, self, opt) print_dot(ostr, self, opt)
return _ostream_to_svg(ostr) return _ostream_to_svg(ostr)
def show(self, opt=None): def show(self, opt=None):
"""Display the automaton as SVG, in the IPython/Jupyter notebook""" """Display the automaton as SVG, in the IPython/Jupyter notebook"""
if opt is None:
global _show_default
opt = _show_default
# Load the SVG function only if we need it. This way the # Load the SVG function only if we need it. This way the
# bindings can still be used outside of IPython if IPython is # bindings can still be used outside of IPython if IPython is
# not installed. # not installed.
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment