##// END OF EJS Templates
Create base widget classes
Jonathan Frederic -
Show More
@@ -3,11 +3,9 b' from .widget import Widget, DOMWidget'
3 from .widget_bool import CheckBoxWidget, ToggleButtonWidget
3 from .widget_bool import CheckBoxWidget, ToggleButtonWidget
4 from .widget_button import ButtonWidget
4 from .widget_button import ButtonWidget
5 from .widget_container import ContainerWidget, ModalWidget
5 from .widget_container import ContainerWidget, ModalWidget
6 from .widget_float import FloatTextWidget
6 from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
7 from .widget_float_range import BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
8 from .widget_image import ImageWidget
7 from .widget_image import ImageWidget
9 from .widget_int import IntTextWidget
8 from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget
10 from .widget_int_range import BoundedIntTextWidget, IntSliderWidget, IntProgressWidget
11 from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, ListBoxWidget
9 from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, ListBoxWidget
12 from .widget_selectioncontainer import TabWidget, AccordionWidget
10 from .widget_selectioncontainer import TabWidget, AccordionWidget
13 from .widget_string import HTMLWidget, LatexWidget, TextBoxWidget, TextAreaWidget
11 from .widget_string import HTMLWidget, LatexWidget, TextBoxWidget, TextAreaWidget
@@ -19,15 +19,16 b' from IPython.utils.traitlets import Unicode, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class CheckBoxWidget(DOMWidget):
22 class _BoolWidget(DOMWidget):
23 view_name = Unicode('CheckBoxView', sync=True)
24
25 # Model Keys
26 value = Bool(False, help="Bool value", sync=True)
23 value = Bool(False, help="Bool value", sync=True)
27 description = Unicode('', help="Description of the boolean (label).", sync=True)
24 description = Unicode('', help="Description of the boolean (label).", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
25 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
29
26
30
27
31 class ToggleButtonWidget(CheckBoxWidget):
28 class CheckBoxWidget(_BoolWidget):
29 view_name = Unicode('CheckBoxView', sync=True)
30
31
32 class ToggleButtonWidget(_BoolWidget):
32 view_name = Unicode('ToggleButtonView', sync=True)
33 view_name = Unicode('ToggleButtonView', sync=True)
33 No newline at end of file
34
@@ -14,15 +14,46 b' Represents an unbounded float using a widget.'
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, List
17 from IPython.utils.traitlets import Unicode, CFloat, Bool, List, Enum
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class FloatTextWidget(DOMWidget):
22 class _FloatWidget(DOMWidget):
23 view_name = Unicode('FloatTextView', sync=True)
24
25 # Keys
26 value = CFloat(0.0, help="Float value", sync=True)
23 value = CFloat(0.0, help="Float value", sync=True)
27 disabled = Bool(False, help="Enable or disable user changes", sync=True)
24 disabled = Bool(False, help="Enable or disable user changes", sync=True)
28 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
27
28 class _BoundedFloatWidget(_FloatWidget):
29 max = CFloat(100.0, help="Max 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)
32
33 def __init__(self, *pargs, **kwargs):
34 """Constructor"""
35 DOMWidget.__init__(self, *pargs, **kwargs)
36 self.on_trait_change(self._validate, ['value', 'min', 'max'])
37
38 def _validate(self, name, old, new):
39 """Validate value, max, min."""
40 if self.min > new or new > self.max:
41 self.value = min(max(new, self.min), self.max)
42
43
44 class FloatTextWidget(_FloatWidget):
45 view_name = Unicode('FloatTextView', sync=True)
46
47
48 class BoundedFloatTextWidget(_BoundedFloatWidget):
49 view_name = Unicode('FloatTextView', sync=True)
50
51
52 class FloatSliderWidget(_BoundedFloatWidget):
53 view_name = Unicode('FloatSliderView', sync=True)
54 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
55 help="Vertical or horizontal.", sync=True)
56
57
58 class FloatProgressWidget(_BoundedFloatWidget):
59 view_name = Unicode('ProgressView', sync=True)
@@ -1,49 +0,0 b''
1 """FloatRangeWidget class.
2
3 Represents a bounded float using a widget.
4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, CFloat, Bool, List, Enum
18
19 #-----------------------------------------------------------------------------
20 # Classes
21 #-----------------------------------------------------------------------------
22 class BoundedFloatTextWidget(DOMWidget):
23 view_name = Unicode('FloatTextView', sync=True)
24 value = CFloat(0.0, help="Float value", sync=True)
25 max = CFloat(100.0, help="Max value", sync=True)
26 min = CFloat(0.0, help="Min value", sync=True)
27 disabled = Bool(False, help="Enable or disable user changes", sync=True)
28 step = CFloat(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
29 description = Unicode(help="Description of the value this widget represents", sync=True)
30
31 def __init__(self, *pargs, **kwargs):
32 """Constructor"""
33 DOMWidget.__init__(self, *pargs, **kwargs)
34 self.on_trait_change(self._validate, ['value', 'min', 'max'])
35
36 def _validate(self, name, old, new):
37 """Validate value, max, min."""
38 if self.min > new or new > self.max:
39 self.value = min(max(new, self.min), self.max)
40
41
42 class FloatSliderWidget(BoundedFloatTextWidget):
43 view_name = Unicode('FloatSliderView', sync=True)
44 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
45 help="Vertical or horizontal.", sync=True)
46
47
48 class FloatProgressWidget(BoundedFloatTextWidget):
49 view_name = Unicode('ProgressView', sync=True)
@@ -14,15 +14,46 b' Represents an unbounded int using a widget.'
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, CInt, Bool, List
17 from IPython.utils.traitlets import Unicode, CInt, Bool, List, Enum
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class IntTextWidget(DOMWidget):
22 class _IntWidget(DOMWidget):
23 view_name = Unicode('IntTextView', sync=True)
24
25 # Keys
26 value = CInt(0, help="Int value", sync=True)
23 value = CInt(0, help="Int value", sync=True)
27 disabled = Bool(False, help="Enable or disable user changes", sync=True)
24 disabled = Bool(False, help="Enable or disable user changes", sync=True)
28 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
27
28 class _BoundedIntWidget(_IntWidget):
29 step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
30 max = CInt(100, help="Max value", sync=True)
31 min = CInt(0, help="Min value", sync=True)
32
33 def __init__(self, *pargs, **kwargs):
34 """Constructor"""
35 DOMWidget.__init__(self, *pargs, **kwargs)
36 self.on_trait_change(self._validate, ['value', 'min', 'max'])
37
38 def _validate(self, name, old, new):
39 """Validate value, max, min."""
40 if self.min > new or new > self.max:
41 self.value = min(max(new, self.min), self.max)
42
43
44 class IntTextWidget(_IntWidget):
45 view_name = Unicode('IntTextView', sync=True)
46
47
48 class BoundedIntTextWidget(_BoundedIntWidget):
49 view_name = Unicode('IntTextView', sync=True)
50
51
52 class IntSliderWidget(_BoundedIntWidget):
53 view_name = Unicode('IntSliderView', sync=True)
54 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
55 help="Vertical or horizontal.", sync=True)
56
57
58 class IntProgressWidget(_BoundedIntWidget):
59 view_name = Unicode('ProgressView', sync=True)
@@ -1,51 +0,0 b''
1 """IntRangeWidget class.
2
3 Represents a bounded int using a widget.
4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
8 # Distributed under the terms of the Modified BSD License.
9 #
10 # The full license is in the file COPYING.txt, distributed with this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, CInt, Bool, List, Enum
18
19 #-----------------------------------------------------------------------------
20 # Classes
21 #-----------------------------------------------------------------------------
22 class BoundedIntTextWidget(DOMWidget):
23 view_name = Unicode('IntTextView', sync=True)
24
25 # Keys
26 value = CInt(0, help="Int value", sync=True)
27 max = CInt(100, help="Max value", sync=True)
28 min = CInt(0, help="Min value", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes", sync=True)
30 step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
31 description = Unicode(help="Description of the value this widget represents", sync=True)
32
33 def __init__(self, *pargs, **kwargs):
34 """Constructor"""
35 DOMWidget.__init__(self, *pargs, **kwargs)
36 self.on_trait_change(self._validate, ['value', 'min', 'max'])
37
38 def _validate(self, name, old, new):
39 """Validate value, max, min."""
40 if self.min > new or new > self.max:
41 self.value = min(max(new, self.min), self.max)
42
43
44 class IntSliderWidget(BoundedIntTextWidget):
45 view_name = Unicode('IntSliderView', sync=True)
46 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
47 help="Vertical or horizontal.", sync=True)
48
49
50 class IntProgressWidget(BoundedIntTextWidget):
51 view_name = Unicode('ProgressView', sync=True)
@@ -19,23 +19,24 b' from IPython.utils.traitlets import Unicode, List, Bool'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # SelectionWidget
20 # SelectionWidget
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class ToggleButtonsWidget(DOMWidget):
22 class _SelectionWidget(DOMWidget):
23 view_name = Unicode('ToggleButtonsView', sync=True)
24
25 # Keys
26 value = Unicode(help="Selected value", sync=True) # TODO: Any support
23 value = Unicode(help="Selected value", sync=True) # TODO: Any support
27 values = List(help="List of values the user can select", sync=True)
24 values = List(help="List of values the user can select", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 disabled = Bool(False, help="Enable or disable user changes", sync=True)
29 description = Unicode(help="Description of the value this widget represents", sync=True)
26 description = Unicode(help="Description of the value this widget represents", sync=True)
30
27
31
28
32 class DropdownWidget(ToggleButtonsWidget):
29 class ToggleButtonsWidget(_SelectionWidget):
30 view_name = Unicode('ToggleButtonsView', sync=True)
31
32
33 class DropdownWidget(_SelectionWidget):
33 view_name = Unicode('DropdownView', sync=True)
34 view_name = Unicode('DropdownView', sync=True)
34
35
35
36
36 class RadioButtonsWidget(ToggleButtonsWidget):
37 class RadioButtonsWidget(_SelectionWidget):
37 view_name = Unicode('RadioButtonsView', sync=True)
38 view_name = Unicode('RadioButtonsView', sync=True)
38
39
39
40
40 class ListBoxWidget(ToggleButtonsWidget):
41 class ListBoxWidget(_SelectionWidget):
41 view_name = Unicode('ListBoxView', sync=True)
42 view_name = Unicode('ListBoxView', sync=True)
@@ -20,10 +20,7 b' from IPython.utils.traitlets import Unicode, Dict, CInt, List, Instance'
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # Classes
21 # Classes
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 class AccordionWidget(ContainerWidget):
23 class _SelectionContainerWidget(ContainerWidget):
24 view_name = Unicode('AccordionView', sync=True)
25
26 # Keys
27 _titles = Dict(help="Titles of the pages", sync=True)
24 _titles = Dict(help="Titles of the pages", sync=True)
28 selected_index = CInt(0, sync=True)
25 selected_index = CInt(0, sync=True)
29
26
@@ -53,5 +50,9 b' class AccordionWidget(ContainerWidget):'
53 return None
50 return None
54
51
55
52
56 class TabWidget(AccordionWidget):
53 class AccordionWidget(_SelectionContainerWidget):
54 view_name = Unicode('AccordionView', sync=True)
55
56
57 class TabWidget(_SelectionContainerWidget):
57 view_name = Unicode('TabView', sync=True)
58 view_name = Unicode('TabView', sync=True)
@@ -19,27 +19,28 b' from IPython.utils.traitlets import Unicode, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class HTMLWidget(DOMWidget):
22 class _StringWidget(DOMWidget):
23 view_name = Unicode('HTMLView', sync=True)
24
25 # Keys
26 value = Unicode(help="String value", sync=True)
23 value = Unicode(help="String value", sync=True)
27 disabled = Bool(False, help="Enable or disable user changes", sync=True)
24 disabled = Bool(False, help="Enable or disable user changes", sync=True)
28 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)
29
26
30
27
31 class LatexWidget(HTMLWidget):
28 class HTMLWidget(_StringWidget):
29 view_name = Unicode('HTMLView', sync=True)
30
31
32 class LatexWidget(_StringWidget):
32 view_name = Unicode('LatexView', sync=True)
33 view_name = Unicode('LatexView', sync=True)
33
34
34
35
35 class TextAreaWidget(HTMLWidget):
36 class TextAreaWidget(_StringWidget):
36 view_name = Unicode('TextAreaView', sync=True)
37 view_name = Unicode('TextAreaView', sync=True)
37
38
38 def scroll_to_bottom(self):
39 def scroll_to_bottom(self):
39 self.send({"method": "scroll_to_bottom"})
40 self.send({"method": "scroll_to_bottom"})
40
41
41
42
42 class TextBoxWidget(HTMLWidget):
43 class TextBoxWidget(_StringWidget):
43 view_name = Unicode('TextBoxView', sync=True)
44 view_name = Unicode('TextBoxView', sync=True)
44
45
45 def __init__(self, **kwargs):
46 def __init__(self, **kwargs):
General Comments 0
You need to be logged in to leave comments. Login now