Show More
@@ -1,60 +1,61 b'' | |||||
1 | """FloatWidget class. |
|
1 | """FloatWidget class. | |
2 |
|
2 | |||
3 | Represents an unbounded float using a widget. |
|
3 | Represents an unbounded float using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import DOMWidget |
|
16 | from .widget import DOMWidget | |
17 | from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum |
|
17 | from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class _FloatWidget(DOMWidget): |
|
22 | class _FloatWidget(DOMWidget): | |
23 | value = CFloat(0.0, help="Float value", sync=True) |
|
23 | value = CFloat(0.0, help="Float value", sync=True) | |
24 | disabled = Bool(False, help="Enable or disable user changes", sync=True) |
|
24 | disabled = Bool(False, help="Enable or disable user changes", sync=True) | |
25 | description = Unicode(help="Description of the value this widget represents", sync=True) |
|
25 | description = Unicode(help="Description of the value this widget represents", sync=True) | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | class _BoundedFloatWidget(_FloatWidget): |
|
28 | class _BoundedFloatWidget(_FloatWidget): | |
29 | max = CFloat(100.0, help="Max value", sync=True) |
|
29 | max = CFloat(100.0, help="Max value", sync=True) | |
30 | min = CFloat(0.0, help="Min value", sync=True) |
|
30 | min = CFloat(0.0, help="Min value", sync=True) | |
31 | step = CFloat(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True) |
|
31 | step = CFloat(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True) | |
32 |
|
32 | |||
33 | def __init__(self, *pargs, **kwargs): |
|
33 | def __init__(self, *pargs, **kwargs): | |
34 | """Constructor""" |
|
34 | """Constructor""" | |
35 | DOMWidget.__init__(self, *pargs, **kwargs) |
|
35 | DOMWidget.__init__(self, *pargs, **kwargs) | |
|
36 | self._validate('value', None, self.value) | |||
36 | self.on_trait_change(self._validate, ['value', 'min', 'max']) |
|
37 | self.on_trait_change(self._validate, ['value', 'min', 'max']) | |
37 |
|
38 | |||
38 | def _validate(self, name, old, new): |
|
39 | def _validate(self, name, old, new): | |
39 | """Validate value, max, min.""" |
|
40 | """Validate value, max, min.""" | |
40 | if self.min > new or new > self.max: |
|
41 | if self.min > new or new > self.max: | |
41 | self.value = min(max(new, self.min), self.max) |
|
42 | self.value = min(max(new, self.min), self.max) | |
42 |
|
43 | |||
43 |
|
44 | |||
44 | class FloatTextWidget(_FloatWidget): |
|
45 | class FloatTextWidget(_FloatWidget): | |
45 | _view_name = Unicode('FloatTextView', sync=True) |
|
46 | _view_name = Unicode('FloatTextView', sync=True) | |
46 |
|
47 | |||
47 |
|
48 | |||
48 | class BoundedFloatTextWidget(_BoundedFloatWidget): |
|
49 | class BoundedFloatTextWidget(_BoundedFloatWidget): | |
49 | _view_name = Unicode('FloatTextView', sync=True) |
|
50 | _view_name = Unicode('FloatTextView', sync=True) | |
50 |
|
51 | |||
51 |
|
52 | |||
52 | class FloatSliderWidget(_BoundedFloatWidget): |
|
53 | class FloatSliderWidget(_BoundedFloatWidget): | |
53 | _view_name = Unicode('FloatSliderView', sync=True) |
|
54 | _view_name = Unicode('FloatSliderView', sync=True) | |
54 | orientation = Enum([u'horizontal', u'vertical'], u'horizontal', |
|
55 | orientation = Enum([u'horizontal', u'vertical'], u'horizontal', | |
55 | help="Vertical or horizontal.", sync=True) |
|
56 | help="Vertical or horizontal.", sync=True) | |
56 | readout = Bool(True, help="Display the current value of the slider next to it.", sync=True) |
|
57 | readout = Bool(True, help="Display the current value of the slider next to it.", sync=True) | |
57 |
|
58 | |||
58 |
|
59 | |||
59 | class FloatProgressWidget(_BoundedFloatWidget): |
|
60 | class FloatProgressWidget(_BoundedFloatWidget): | |
60 | _view_name = Unicode('ProgressView', sync=True) |
|
61 | _view_name = Unicode('ProgressView', sync=True) |
General Comments 0
You need to be logged in to leave comments.
Login now