|
|
|
|
@ -22,7 +22,7 @@ from IPython.utils.warn import DeprecatedClass
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
class _Int(DOMWidget):
|
|
|
|
|
"""Base class used to create widgets that represent an int."""
|
|
|
|
|
value = CInt(0, help="Int value", sync=True)
|
|
|
|
|
value = CInt(0, help="Int 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)
|
|
|
|
|
|
|
|
|
|
@ -41,23 +41,26 @@ class _BoundedInt(_Int):
|
|
|
|
|
def __init__(self, *pargs, **kwargs):
|
|
|
|
|
"""Constructor"""
|
|
|
|
|
super(_BoundedInt, self).__init__(*pargs, **kwargs)
|
|
|
|
|
self._value_changed('value', None, self.value)
|
|
|
|
|
self._min_changed('min', None, self.min)
|
|
|
|
|
self._max_changed('max', None, self.max)
|
|
|
|
|
|
|
|
|
|
def _value_changed(self, name, old, new):
|
|
|
|
|
self._handle_value_changed('value', None, self.value)
|
|
|
|
|
self._handle_max_changed('max', None, self.max)
|
|
|
|
|
self._handle_min_changed('min', None, self.min)
|
|
|
|
|
self.on_trait_change(self._handle_value_changed, 'value')
|
|
|
|
|
self.on_trait_change(self._handle_max_changed, 'max')
|
|
|
|
|
self.on_trait_change(self._handle_min_changed, 'min')
|
|
|
|
|
|
|
|
|
|
def _handle_value_changed(self, name, old, new):
|
|
|
|
|
"""Validate value."""
|
|
|
|
|
if self.min > new or new > self.max:
|
|
|
|
|
self.value = min(max(new, self.min), self.max)
|
|
|
|
|
|
|
|
|
|
def _max_changed(self, name, old, new):
|
|
|
|
|
def _handle_max_changed(self, name, old, new):
|
|
|
|
|
"""Make sure the min is always <= the max."""
|
|
|
|
|
if new < self.min:
|
|
|
|
|
raise ValueError("setting max < min")
|
|
|
|
|
if new < self.value:
|
|
|
|
|
self.value = new
|
|
|
|
|
|
|
|
|
|
def _min_changed(self, name, old, new):
|
|
|
|
|
def _handle_min_changed(self, name, old, new):
|
|
|
|
|
"""Make sure the max is always >= the min."""
|
|
|
|
|
if new > self.max:
|
|
|
|
|
raise ValueError("setting min > max")
|
|
|
|
|
|