Interacts for the Sage Jupyter notebook

This is mostly the same as the stock ipywidgets.interact, but with some customizations for Sage.

EXAMPLES:

sage: from sage.repl.ipython_kernel.interact import interact
sage: @interact
....: def f(x=(0,10)):
....:     pass
Interactive function <function f at ...> with 1 widget
  x: IntSlider(value=5, description=u'x', max=10)
sage: f.widget.children
(IntSlider(value=5, description=u'x', max=10), Output())
class sage.repl.ipython_kernel.interact.sage_interactive(*args, **kwds)

Bases: ipywidgets.widgets.interaction.interactive

Wrapper around the ipywidgets interactive which handles some SageNB specifics.

EXAMPLES:

sage: from sage.repl.ipython_kernel.interact import sage_interactive
sage: def myfunc(x=10, y="hello", z=None): pass
sage: sage_interactive(myfunc, x=(0,100), z=["one", "two", "three"])
Interactive function <function myfunc at ...> with 3 widgets
  x: IntSlider(value=10, description=u'x')
  y: Text(value=u'hello', description=u'y')
  z: Dropdown(description=u'z', options=('one', 'two', 'three'), value=None)
signature()

Return the fixed signature of the interactive function (after a possible auto_update parameter was removed).

EXAMPLES:

sage: from sage.repl.ipython_kernel.interact import sage_interactive
sage: def myfunc(x=[1,2,3], auto_update=False): pass
sage: sage_interactive(myfunc).signature().parameters  # py2
OrderedDict([('x', <Parameter ... 'x'>)])
sage: sage_interactive(myfunc).signature().parameters  # py3
mappingproxy({'x': <Parameter "x=[1, 2, 3]">})
classmethod widget_from_iterable(abbrev, *args, **kwds)

Convert an unspecified iterable to a widget.

This behaves like in ipywidgets, except that an iterator (like a generator object) becomes a SelectionSlider.

EXAMPLES:

sage: from sage.repl.ipython_kernel.interact import sage_interactive
sage: sage_interactive.widget_from_iterable([1..5])
Dropdown(options=(1, 2, 3, 4, 5), value=1)
sage: sage_interactive.widget_from_iterable(iter([1..5]))
SelectionSlider(options=(1, 2, 3, 4, 5), value=1)
sage: sage_interactive.widget_from_iterable((1..5))
SelectionSlider(options=(1, 2, 3, 4, 5), value=1)
sage: sage_interactive.widget_from_iterable(x for x in [1..5])
SelectionSlider(options=(1, 2, 3, 4, 5), value=1)
sage: def gen():
....:     yield 1; yield 2; yield 3; yield 4; yield 5
sage: sage_interactive.widget_from_iterable(gen())
SelectionSlider(options=(1, 2, 3, 4, 5), value=1)
classmethod widget_from_single_value(abbrev, *args, **kwds)

Convert a single value (i.e. a non-iterable) to a widget.

This supports the Sage Color class. Any unknown type is changed to a string for evaluating. This is meant to support symbolic expressions like sin(x).

EXAMPLES:

sage: from sage.repl.ipython_kernel.interact import sage_interactive
sage: sage_interactive.widget_from_single_value("sin(x)")
Text(value=u'sin(x)')
sage: sage_interactive.widget_from_single_value(sin(x))
EvalText(value=u'sin(x)')
sage: from sage.plot.colors import Color
sage: sage_interactive.widget_from_single_value(Color('cornflowerblue'))
SageColorPicker(value='#6495ed')
classmethod widget_from_tuple(abbrev, *args, **kwds)

Convert a tuple to a widget.

This supports two SageNB extensions: (description, abbrev) if description is a string and (default, abbrev) if abbrev is not a single value.

Symbolic expressions are changed to a floating-point number.

EXAMPLES:

sage: from sage.repl.ipython_kernel.interact import sage_interactive
sage: sage_interactive.widget_from_tuple( (0, 10) )
IntSlider(value=5, max=10)
sage: sage_interactive.widget_from_tuple( ("number", (0, 10)) )
IntSlider(value=5, description=u'number', max=10)
sage: sage_interactive.widget_from_tuple( (3, (0, 10)) )
IntSlider(value=3, max=10)
sage: sage_interactive.widget_from_tuple((2, dict(one=1, two=2, three=3))) # py2
Dropdown(index=1, options={'three': 3, 'two': 2, 'one': 1}, value=2)
sage: sage_interactive.widget_from_tuple((2, dict(one=1, two=2, three=3))) # py3
Dropdown(index=1, options={'one': 1, 'two': 2, 'three': 3}, value=2)
sage: sage_interactive.widget_from_tuple( (sqrt(2), pi) )
FloatSlider(value=2.277903107981444, max=3.141592653589793, min=1.4142135623730951)