##// END OF EJS Templates
registering core widgets
Sylvain Corlay -
Show More
@@ -1,4 +1,4 b''
1 from .widget import Widget, DOMWidget, CallbackDispatcher
1 from .widget import Widget, DOMWidget, CallbackDispatcher, register
2
2
3 from .widget_bool import Checkbox, ToggleButton
3 from .widget_bool import Checkbox, ToggleButton
4 from .widget_button import Button
4 from .widget_button import Button
@@ -78,7 +78,7 b' def _show_traceback(method):'
78
78
79 def register(key=None):
79 def register(key=None):
80 def wrap(widget):
80 def wrap(widget):
81 l = key if key is not None else widget._model_name.default_value
81 l = key if key is not None else widget._view_name.default_value
82 Widget.widget_types[l] = widget
82 Widget.widget_types[l] = widget
83 return widget
83 return widget
84 return wrap
84 return wrap
@@ -13,13 +13,14 b' Represents a boolean using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget, register
17 from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
17 from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
18 from IPython.utils.warn import DeprecatedClass
18 from IPython.utils.warn import DeprecatedClass
19
19
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # Classes
21 # Classes
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 @register()
23 class _Bool(DOMWidget):
24 class _Bool(DOMWidget):
24 """A base class for creating widgets that represent booleans."""
25 """A base class for creating widgets that represent booleans."""
25 value = Bool(False, help="Bool value", sync=True)
26 value = Bool(False, help="Bool value", sync=True)
@@ -27,11 +28,13 b' class _Bool(DOMWidget):'
27 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
28
29
29
30
31 @register()
30 class Checkbox(_Bool):
32 class Checkbox(_Bool):
31 """Displays a boolean `value`."""
33 """Displays a boolean `value`."""
32 _view_name = Unicode('CheckboxView', sync=True)
34 _view_name = Unicode('CheckboxView', sync=True)
33
35
34
36
37 @register()
35 class ToggleButton(_Bool):
38 class ToggleButton(_Bool):
36 """Displays a boolean `value`."""
39 """Displays a boolean `value`."""
37
40
@@ -6,10 +6,11 b' Represents a container that can be used to group other widgets.'
6 # Copyright (c) IPython Development Team.
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8
8
9 from .widget import DOMWidget
9 from .widget import DOMWidget, register
10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
11 from IPython.utils.warn import DeprecatedClass
11 from IPython.utils.warn import DeprecatedClass
12
12
13 @register()
13 class Box(DOMWidget):
14 class Box(DOMWidget):
14 """Displays multiple widgets in a group."""
15 """Displays multiple widgets in a group."""
15 _view_name = Unicode('BoxView', sync=True)
16 _view_name = Unicode('BoxView', sync=True)
@@ -44,6 +45,7 b' class Box(DOMWidget):'
44 child._handle_displayed()
45 child._handle_displayed()
45
46
46
47
48 @register()
47 class Popup(Box):
49 class Popup(Box):
48 """Displays multiple widgets in an in page popup div."""
50 """Displays multiple widgets in an in page popup div."""
49 _view_name = Unicode('PopupView', sync=True)
51 _view_name = Unicode('PopupView', sync=True)
@@ -52,6 +54,7 b' class Popup(Box):'
52 button_text = Unicode(sync=True)
54 button_text = Unicode(sync=True)
53
55
54
56
57 @register()
55 class FlexBox(Box):
58 class FlexBox(Box):
56 """Displays multiple widgets using the flexible box model."""
59 """Displays multiple widgets using the flexible box model."""
57 _view_name = Unicode('FlexBoxView', sync=True)
60 _view_name = Unicode('FlexBoxView', sync=True)
@@ -14,13 +14,14 b' click events on the button and trigger backend code when the clicks are fired.'
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from .widget import DOMWidget, CallbackDispatcher
17 from .widget import DOMWidget, CallbackDispatcher, register
18 from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
18 from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
19 from IPython.utils.warn import DeprecatedClass
19 from IPython.utils.warn import DeprecatedClass
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Classes
22 # Classes
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24 @register()
24 class Button(DOMWidget):
25 class Button(DOMWidget):
25 """Button widget.
26 """Button widget.
26
27
@@ -13,7 +13,7 b' Represents an unbounded float using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget, register
17 from IPython.utils.traitlets import Unicode, CFloat, Bool, CaselessStrEnum, Tuple
17 from IPython.utils.traitlets import Unicode, CFloat, Bool, CaselessStrEnum, Tuple
18 from IPython.utils.warn import DeprecatedClass
18 from IPython.utils.warn import DeprecatedClass
19
19
@@ -43,14 +43,17 b' class _BoundedFloat(_Float):'
43 self.value = min(max(new, self.min), self.max)
43 self.value = min(max(new, self.min), self.max)
44
44
45
45
46 @register()
46 class FloatText(_Float):
47 class FloatText(_Float):
47 _view_name = Unicode('FloatTextView', sync=True)
48 _view_name = Unicode('FloatTextView', sync=True)
48
49
49
50
51 @register()
50 class BoundedFloatText(_BoundedFloat):
52 class BoundedFloatText(_BoundedFloat):
51 _view_name = Unicode('FloatTextView', sync=True)
53 _view_name = Unicode('FloatTextView', sync=True)
52
54
53
55
56 @register()
54 class FloatSlider(_BoundedFloat):
57 class FloatSlider(_BoundedFloat):
55 _view_name = Unicode('FloatSliderView', sync=True)
58 _view_name = Unicode('FloatSliderView', sync=True)
56 orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
59 orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
@@ -61,6 +64,7 b' class FloatSlider(_BoundedFloat):'
61 slider_color = Unicode(sync=True)
64 slider_color = Unicode(sync=True)
62
65
63
66
67 @register()
64 class FloatProgress(_BoundedFloat):
68 class FloatProgress(_BoundedFloat):
65 _view_name = Unicode('ProgressView', sync=True)
69 _view_name = Unicode('ProgressView', sync=True)
66
70
@@ -163,6 +167,7 b' class _BoundedFloatRange(_FloatRange):'
163 self.lower = low
167 self.lower = low
164
168
165
169
170 @register()
166 class FloatRangeSlider(_BoundedFloatRange):
171 class FloatRangeSlider(_BoundedFloatRange):
167 _view_name = Unicode('FloatSliderView', sync=True)
172 _view_name = Unicode('FloatSliderView', sync=True)
168 orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
173 orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
@@ -15,13 +15,14 b' Represents an image in the frontend using a widget.'
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 import base64
16 import base64
17
17
18 from .widget import DOMWidget
18 from .widget import DOMWidget, register
19 from IPython.utils.traitlets import Unicode, CUnicode, Bytes
19 from IPython.utils.traitlets import Unicode, CUnicode, Bytes
20 from IPython.utils.warn import DeprecatedClass
20 from IPython.utils.warn import DeprecatedClass
21
21
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Classes
23 # Classes
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 @register()
25 class Image(DOMWidget):
26 class Image(DOMWidget):
26 """Displays an image as a widget.
27 """Displays an image as a widget.
27
28
@@ -13,7 +13,7 b' Represents an unbounded int using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget, register
17 from IPython.utils.traitlets import Unicode, CInt, Bool, CaselessStrEnum, Tuple
17 from IPython.utils.traitlets import Unicode, CInt, Bool, CaselessStrEnum, Tuple
18 from IPython.utils.warn import DeprecatedClass
18 from IPython.utils.warn import DeprecatedClass
19
19
@@ -56,16 +56,19 b' class _BoundedInt(_Int):'
56 if new > self.max:
56 if new > self.max:
57 raise ValueError("setting min > max")
57 raise ValueError("setting min > max")
58
58
59 @register()
59 class IntText(_Int):
60 class IntText(_Int):
60 """Textbox widget that represents a int."""
61 """Textbox widget that represents a int."""
61 _view_name = Unicode('IntTextView', sync=True)
62 _view_name = Unicode('IntTextView', sync=True)
62
63
63
64
65 @register()
64 class BoundedIntText(_BoundedInt):
66 class BoundedIntText(_BoundedInt):
65 """Textbox widget that represents a int bounded by a minimum and maximum value."""
67 """Textbox widget that represents a int bounded by a minimum and maximum value."""
66 _view_name = Unicode('IntTextView', sync=True)
68 _view_name = Unicode('IntTextView', sync=True)
67
69
68
70
71 @register()
69 class IntSlider(_BoundedInt):
72 class IntSlider(_BoundedInt):
70 """Slider widget that represents a int bounded by a minimum and maximum value."""
73 """Slider widget that represents a int bounded by a minimum and maximum value."""
71 _view_name = Unicode('IntSliderView', sync=True)
74 _view_name = Unicode('IntSliderView', sync=True)
@@ -77,6 +80,7 b' class IntSlider(_BoundedInt):'
77 slider_color = Unicode(sync=True)
80 slider_color = Unicode(sync=True)
78
81
79
82
83 @register()
80 class IntProgress(_BoundedInt):
84 class IntProgress(_BoundedInt):
81 """Progress bar that represents a int bounded by a minimum and maximum value."""
85 """Progress bar that represents a int bounded by a minimum and maximum value."""
82 _view_name = Unicode('ProgressView', sync=True)
86 _view_name = Unicode('ProgressView', sync=True)
@@ -176,6 +180,7 b' class _BoundedIntRange(_IntRange):'
176 self.upper = high
180 self.upper = high
177 self.lower = low
181 self.lower = low
178
182
183 @register()
179 class IntRangeSlider(_BoundedIntRange):
184 class IntRangeSlider(_BoundedIntRange):
180 _view_name = Unicode('IntSliderView', sync=True)
185 _view_name = Unicode('IntSliderView', sync=True)
181 orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
186 orientation = CaselessStrEnum(values=['horizontal', 'vertical'],
@@ -17,7 +17,7 b' Represents an enumeration using a widget.'
17 from collections import OrderedDict
17 from collections import OrderedDict
18 from threading import Lock
18 from threading import Lock
19
19
20 from .widget import DOMWidget
20 from .widget import DOMWidget, register
21 from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError, CaselessStrEnum
21 from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError, CaselessStrEnum
22 from IPython.utils.py3compat import unicode_type
22 from IPython.utils.py3compat import unicode_type
23 from IPython.utils.warn import DeprecatedClass
23 from IPython.utils.warn import DeprecatedClass
@@ -114,6 +114,7 b' class _Selection(DOMWidget):'
114 self.value_lock.release()
114 self.value_lock.release()
115
115
116
116
117 @register()
117 class ToggleButtons(_Selection):
118 class ToggleButtons(_Selection):
118 """Group of toggle buttons that represent an enumeration. Only one toggle
119 """Group of toggle buttons that represent an enumeration. Only one toggle
119 button can be toggled at any point in time."""
120 button can be toggled at any point in time."""
@@ -124,7 +125,7 b' class ToggleButtons(_Selection):'
124 default_value='', allow_none=True, sync=True, help="""Use a
125 default_value='', allow_none=True, sync=True, help="""Use a
125 predefined styling for the buttons.""")
126 predefined styling for the buttons.""")
126
127
127
128 @register()
128 class Dropdown(_Selection):
129 class Dropdown(_Selection):
129 """Allows you to select a single item from a dropdown."""
130 """Allows you to select a single item from a dropdown."""
130 _view_name = Unicode('DropdownView', sync=True)
131 _view_name = Unicode('DropdownView', sync=True)
@@ -134,13 +135,15 b' class Dropdown(_Selection):'
134 default_value='', allow_none=True, sync=True, help="""Use a
135 default_value='', allow_none=True, sync=True, help="""Use a
135 predefined styling for the buttons.""")
136 predefined styling for the buttons.""")
136
137
137
138 @register()
138 class RadioButtons(_Selection):
139 class RadioButtons(_Selection):
139 """Group of radio buttons that represent an enumeration. Only one radio
140 """Group of radio buttons that represent an enumeration. Only one radio
140 button can be toggled at any point in time."""
141 button can be toggled at any point in time."""
141 _view_name = Unicode('RadioButtonsView', sync=True)
142 _view_name = Unicode('RadioButtonsView', sync=True)
142
143
143
144
145
146 @register()
144 class Select(_Selection):
147 class Select(_Selection):
145 """Listbox that only allows one item to be selected at any given time."""
148 """Listbox that only allows one item to be selected at any given time."""
146 _view_name = Unicode('SelectView', sync=True)
149 _view_name = Unicode('SelectView', sync=True)
@@ -14,7 +14,7 b' pages.'
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from .widget_box import Box
17 from .widget_box import Box, register
18 from IPython.utils.traitlets import Unicode, Dict, CInt
18 from IPython.utils.traitlets import Unicode, Dict, CInt
19 from IPython.utils.warn import DeprecatedClass
19 from IPython.utils.warn import DeprecatedClass
20
20
@@ -51,12 +51,13 b' class _SelectionContainer(Box):'
51 else:
51 else:
52 return None
52 return None
53
53
54
54 @register()
55 class Accordion(_SelectionContainer):
55 class Accordion(_SelectionContainer):
56 """Displays children each on a separate accordion page."""
56 """Displays children each on a separate accordion page."""
57 _view_name = Unicode('AccordionView', sync=True)
57 _view_name = Unicode('AccordionView', sync=True)
58
58
59
59
60 @register()
60 class Tab(_SelectionContainer):
61 class Tab(_SelectionContainer):
61 """Displays children each on a separate accordion tab."""
62 """Displays children each on a separate accordion tab."""
62 _view_name = Unicode('TabView', sync=True)
63 _view_name = Unicode('TabView', sync=True)
@@ -13,7 +13,7 b' Represents a unicode string using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget, CallbackDispatcher
16 from .widget import DOMWidget, CallbackDispatcher, register
17 from IPython.utils.traitlets import Unicode, Bool
17 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
18 from IPython.utils.warn import DeprecatedClass
19
19
@@ -28,17 +28,20 b' class _String(DOMWidget):'
28 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
28 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
29
29
30
30
31 @register()
31 class HTML(_String):
32 class HTML(_String):
32 """Renders the string `value` as HTML."""
33 """Renders the string `value` as HTML."""
33 _view_name = Unicode('HTMLView', sync=True)
34 _view_name = Unicode('HTMLView', sync=True)
34
35
35
36
37 @register()
36 class Latex(_String):
38 class Latex(_String):
37 """Renders math inside the string `value` as Latex (requires $ $ or $$ $$
39 """Renders math inside the string `value` as Latex (requires $ $ or $$ $$
38 and similar latex tags)."""
40 and similar latex tags)."""
39 _view_name = Unicode('LatexView', sync=True)
41 _view_name = Unicode('LatexView', sync=True)
40
42
41
43
44 @register()
42 class Textarea(_String):
45 class Textarea(_String):
43 """Multiline text area widget."""
46 """Multiline text area widget."""
44 _view_name = Unicode('TextareaView', sync=True)
47 _view_name = Unicode('TextareaView', sync=True)
@@ -47,6 +50,7 b' class Textarea(_String):'
47 self.send({"method": "scroll_to_bottom"})
50 self.send({"method": "scroll_to_bottom"})
48
51
49
52
53 @register()
50 class Text(_String):
54 class Text(_String):
51 """Single line textbox widget."""
55 """Single line textbox widget."""
52 _view_name = Unicode('TextView', sync=True)
56 _view_name = Unicode('TextView', sync=True)
General Comments 0
You need to be logged in to leave comments. Login now