Add float implementation of range widget

Gordon Ball 12 years ago
parent 3178a184c0
commit 945a840674

@ -3,7 +3,7 @@ from .widget import Widget, DOMWidget, CallbackDispatcher
from .widget_bool import CheckboxWidget, ToggleButtonWidget
from .widget_button import ButtonWidget
from .widget_container import ContainerWidget, PopupWidget
from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget, FloatRangeSliderWidget
from .widget_image import ImageWidget
from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget, IntRangeSliderWidget
from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, SelectWidget

@ -1,4 +1,4 @@
"""FloatWidget class.
"""FloatWidget class.
Represents an unbounded float using a widget.
"""
@ -14,13 +14,13 @@ Represents an unbounded float using a widget.
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget
from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum
from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum, Tuple
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
class _FloatWidget(DOMWidget):
value = CFloat(0.0, help="Float value", sync=True)
value = CFloat(0.0, help="Float value", sync=True)
disabled = Bool(False, help="Enable or disable user changes", sync=True)
description = Unicode(help="Description of the value this widget represents", sync=True)
@ -52,10 +52,40 @@ class BoundedFloatTextWidget(_BoundedFloatWidget):
class FloatSliderWidget(_BoundedFloatWidget):
_view_name = Unicode('FloatSliderView', sync=True)
orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
help="Vertical or horizontal.", sync=True)
range = Bool(False, help="Display a range selector", sync=True)
readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)
class FloatProgressWidget(_BoundedFloatWidget):
_view_name = Unicode('ProgressView', sync=True)
class _FloatRangeWidget(_FloatWidget):
value = Tuple(CFloat, CFloat, default_value=(0.0, 1.0), help="Low and high float values", sync=True)
class _BoundedFloatRangeWidget(_FloatRangeWidget):
step = CFloat(1.0, help="Minimum step that the value can take (ignored by some views)", sync=True)
max = CFloat(100.0, help="Max value", sync=True)
min = CFloat(0.0, help="Min value", sync=True)
def __init__(self, *pargs, **kwargs):
"""Constructor"""
DOMWidget.__init__(self, *pargs, **kwargs)
self.on_trait_change(self._validate, ['value', 'min', 'max'])
def _validate(self, name, old, new):
"""Validate min <= low <= high <= max"""
if name == "value":
low, high = new
low = max(low, self.min)
high = min(high, self.max)
self.value = (min(low, high), max(low, high))
class FloatRangeSliderWidget(_BoundedFloatRangeWidget):
_view_name = Unicode('FloatSliderView', sync=True)
orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
help="Vertical or horizontal.", sync=True)
range = Bool(True, help="Display a range selector", sync=True)
readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)

Loading…
Cancel
Save