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