Widgets to be used for the Sage Jupyter notebook

These are all based on widgets from ipywidgets, changing or combining existing widgets.

class sage.repl.ipython_kernel.widgets.EvalText(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.EvalWidget, ipywidgets.widgets.widget_string.Text

A ipywidgets.Text widget which evaluates (using sage_eval()) its contents and applies an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import EvalText
sage: w = EvalText(value="pi", transform=lambda x: x^2)
sage: w
EvalText(value=u'pi')
sage: w.get_interact_value()
pi^2
class sage.repl.ipython_kernel.widgets.EvalTextarea(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.EvalWidget, ipywidgets.widgets.widget_string.Textarea

A ipywidgets.Textarea widget which evaluates (using sage_eval()) its contents and applies an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import EvalTextarea
sage: w = EvalTextarea(value="pi", transform=lambda x: x^2)
sage: w
EvalTextarea(value=u'pi')
sage: w.get_interact_value()
pi^2
class sage.repl.ipython_kernel.widgets.EvalWidget(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget

A mixin class for a widget to evaluate (using sage_eval()) the widget value and possibly transform it like TransformWidget.

EXAMPLES:

sage: from ipywidgets import ToggleButtons
sage: from sage.repl.ipython_kernel.widgets import EvalWidget
sage: class EvalToggleButtons(EvalWidget, ToggleButtons): pass
sage: w = EvalToggleButtons(options=["pi", "e"], transform=lambda x: x+x)
sage: w
EvalToggleButtons(options=('pi', 'e'), value='pi')
sage: w.get_interact_value()
2*pi
get_value()

Evaluate the bare widget value using sage_eval().

EXAMPLES:

sage: from ipywidgets import Dropdown
sage: from sage.repl.ipython_kernel.widgets import EvalWidget
sage: class EvalDropdown(EvalWidget, Dropdown): pass
sage: w = EvalDropdown(options=["the_answer"], transform=RR)
sage: w
EvalDropdown(options=('the_answer',), value='the_answer')
sage: the_answer = 42
sage: w.get_value()
42
sage: w.get_interact_value()
42.0000000000000
class sage.repl.ipython_kernel.widgets.Grid(nrows, ncols, make_widget, description='', transform=None)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_box.HBox, ipywidgets.widgets.valuewidget.ValueWidget

A square grid of widgets whose value is a list of lists of the values of the individual widgets.

This is usually created using the input_grid() function.

EXAMPLES:

sage: from ipywidgets import Text
sage: from sage.repl.ipython_kernel.widgets import Grid
sage: w = Grid(2, 2, lambda i,j: Text(value="%s,%s"%(i,j)))
sage: w
Grid(value=[[u'0,0', u'0,1'], [u'1,0', u'1,1']], children=(Label(value=u''), VBox(children=(Text(value=u'0,0'), Text(value=u'1,0'))), VBox(children=(Text(value=u'0,1'), Text(value=u'1,1')))))
sage: w.get_interact_value()
[[u'0,0', u'0,1'], [u'1,0', u'1,1']]
description

A trait for unicode strings.

value

An instance of a Python list.

class sage.repl.ipython_kernel.widgets.HTMLText(value=None, **kwargs)

Bases: ipywidgets.widgets.widget_string.HTMLMath

An HTML widget whose description is always empty.

This is used to display arbitrary HTML text in interacts without a label. The text_control() function from SageNB is an alias of HTMLText.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import HTMLText
sage: w = HTMLText("Hello")
sage: w.description
u''
sage: w.description = "text"
sage: w.description
u''
description

Always return empty string.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import HTMLText
sage: w = HTMLText("Hello")
sage: w.description
u''
class sage.repl.ipython_kernel.widgets.SageColorPicker(**kwargs)

Bases: ipywidgets.widgets.widget_color.ColorPicker

A color picker widget returning a Sage Color.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import SageColorPicker
sage: SageColorPicker()
SageColorPicker(value='black')
get_interact_value()

Return a Sage Color corresponding to the value of this widget.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import SageColorPicker
sage: SageColorPicker().get_interact_value()
RGB color (0.0, 0.0, 0.0)
class sage.repl.ipython_kernel.widgets.TransformFloatRangeSlider(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_float.FloatRangeSlider

An ipywidgets.FloatRangeSlider widget with an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import TransformFloatRangeSlider
sage: w = TransformFloatRangeSlider(min=0, max=100, value=(7,9), transform=lambda x: x[1]-x[0])
sage: w
TransformFloatRangeSlider(value=(7.0, 9.0))
sage: w.get_interact_value()
2.0
class sage.repl.ipython_kernel.widgets.TransformFloatSlider(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_float.FloatSlider

A ipywidgets.FloatSlider widget with an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import TransformFloatSlider
sage: w = TransformFloatSlider(min=0, max=100, value=7, transform=lambda x: sqrt(x))
sage: w
TransformFloatSlider(value=7.0)
sage: w.get_interact_value()
2.6457513110645907
class sage.repl.ipython_kernel.widgets.TransformIntRangeSlider(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_int.IntRangeSlider

An ipywidgets.IntRangeSlider widget with an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import TransformIntRangeSlider
sage: w = TransformIntRangeSlider(min=0, max=100, value=(7,9), transform=lambda x: x[1]-x[0])
sage: w
TransformIntRangeSlider(value=(7, 9))
sage: w.get_interact_value()
2
class sage.repl.ipython_kernel.widgets.TransformIntSlider(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_int.IntSlider

An ipywidgets.IntSlider widget with an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import TransformIntSlider
sage: w = TransformIntSlider(min=0, max=100, value=7, transform=lambda x: x^2)
sage: w
TransformIntSlider(value=7)
sage: w.get_interact_value()
49
class sage.repl.ipython_kernel.widgets.TransformText(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_string.Text

A ipywidgets.Text widget with an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import TransformText
sage: w = TransformText(value="hello", transform=lambda x: x+x)
sage: w
TransformText(value=u'hello')
sage: w.get_interact_value()
u'hellohello'
class sage.repl.ipython_kernel.widgets.TransformTextarea(*args, **kwds)

Bases: sage.repl.ipython_kernel.widgets.TransformWidget, ipywidgets.widgets.widget_string.Textarea

A ipywidgets.Textarea widget with an optional transformation.

EXAMPLES:

sage: from sage.repl.ipython_kernel.widgets import TransformTextarea
sage: w = TransformTextarea(value="hello", transform=lambda x: x+x)
sage: w
TransformTextarea(value=u'hello')
sage: w.get_interact_value()
u'hellohello'
class sage.repl.ipython_kernel.widgets.TransformWidget(*args, **kwds)

Bases: object

A mixin class for a widget to transform the bare widget value for use in interactive functions.

INPUT:

  • transform – a one-argument function which transforms the value of the widget for use by an interactive function.
  • other arguments are passed to the base class

EXAMPLES:

sage: from ipywidgets import ToggleButtons
sage: from sage.repl.ipython_kernel.widgets import TransformWidget
sage: class TransformToggleButtons(TransformWidget, ToggleButtons): pass
sage: w = TransformToggleButtons(options=["pi", "e"], transform=lambda x: x+x)
sage: w
TransformToggleButtons(options=('pi', 'e'), value='pi')
sage: w.get_interact_value()
'pipi'
get_interact_value()

Return the transformed value of this widget, by calling the transform function.

EXAMPLES:

sage: from ipywidgets import Checkbox
sage: from sage.repl.ipython_kernel.widgets import TransformWidget
sage: class TransformCheckbox(TransformWidget, Checkbox): pass
sage: w = TransformCheckbox(value=True, transform=int); w
TransformCheckbox(value=True)
sage: w.get_interact_value()
1
get_value()

Return self.value.

This is meant to be overridden by sub-classes to change the input of the transform function.

EXAMPLES:

sage: from ipywidgets import ColorPicker
sage: from sage.repl.ipython_kernel.widgets import TransformWidget
sage: class TransformColorPicker(TransformWidget, ColorPicker): pass
sage: TransformColorPicker(value="red").get_value()
'red'