From 1ff31108b0f2ab1708bbf5b7e2a4ce14bb6644a3 2014-06-25 16:10:59 From: Gordon Ball Date: 2014-06-25 16:10:59 Subject: [PATCH] Add an extended range abbreviation including a step value --- diff --git a/IPython/html/widgets/interaction.py b/IPython/html/widgets/interaction.py index 6378682..4bb7cbc 100644 --- a/IPython/html/widgets/interaction.py +++ b/IPython/html/widgets/interaction.py @@ -23,7 +23,7 @@ from inspect import getcallargs from IPython.core.getipython import get_ipython from IPython.html.widgets import (Widget, TextWidget, FloatSliderWidget, IntSliderWidget, CheckboxWidget, DropdownWidget, - ContainerWidget, DOMWidget, IntRangeSliderWidget) + ContainerWidget, DOMWidget, IntRangeSliderWidget, FloatRangeSliderWidget) from IPython.display import display, clear_output from IPython.utils.py3compat import string_types, unicode_type from IPython.utils.traitlets import HasTraits, Any, Unicode @@ -116,6 +116,17 @@ def _widget_abbrev(o): else: cls = FloatRangeSliderWidget return cls(value=(low, high), min=min, max=max) + elif _matches(o, [float_or_int]*5): + min, low, high, max, step = o + if not min <= low <= high <= max: + raise ValueError("Range input expects min <= low <= high <= max, got %r" % o) + if step <= 0: + raise ValueError("step must be >= 0, not %r" % step) + if all(isinstance(_, int) for _ in o): + cls = IntRangeSliderWidget + else: + cls = FloatRangeSliderWidget + return cls(value=(low, high), min=min, max=max, step=step) else: return _widget_abbrev_single_value(o)