Show More
@@ -8,7 +8,7 b' import os' | |||||
8 | import IPython |
|
8 | import IPython | |
9 | from IPython.kernel.comm import Comm |
|
9 | from IPython.kernel.comm import Comm | |
10 | from IPython.config import LoggingConfigurable |
|
10 | from IPython.config import LoggingConfigurable | |
11 | from IPython.utils.traitlets import Unicode, Dict |
|
11 | from IPython.utils.traitlets import Unicode, Dict, List | |
12 | from IPython.display import Javascript, display |
|
12 | from IPython.display import Javascript, display | |
13 | from IPython.utils.py3compat import string_types |
|
13 | from IPython.utils.py3compat import string_types | |
14 |
|
14 | |||
@@ -18,6 +18,7 b' class Widget(LoggingConfigurable):' | |||||
18 | ### Public declarations |
|
18 | ### Public declarations | |
19 | target_name = Unicode('widget') |
|
19 | target_name = Unicode('widget') | |
20 | default_view_name = Unicode() |
|
20 | default_view_name = Unicode() | |
|
21 | js_requirements = List() | |||
21 |
|
22 | |||
22 |
|
23 | |||
23 | ### Private/protected declarations |
|
24 | ### Private/protected declarations | |
@@ -122,6 +123,10 b' class Widget(LoggingConfigurable):' | |||||
122 | if not view_name: |
|
123 | if not view_name: | |
123 | view_name = self.default_view_name |
|
124 | view_name = self.default_view_name | |
124 |
|
125 | |||
|
126 | # Require traitlet specified widget js | |||
|
127 | for requirement in self.js_requirements: | |||
|
128 | self._require_js(requirement) | |||
|
129 | ||||
125 | # Create a comm. |
|
130 | # Create a comm. | |
126 | if self.comm is None: |
|
131 | if self.comm is None: | |
127 | self.comm = Comm(target_name=self.target_name) |
|
132 | self.comm = Comm(target_name=self.target_name) | |
@@ -155,3 +160,16 b' class Widget(LoggingConfigurable):' | |||||
155 | self.comm.send({"method": "update", |
|
160 | self.comm.send({"method": "update", | |
156 | "state": state}) |
|
161 | "state": state}) | |
157 |
|
162 | |||
|
163 | ### Private methods | |||
|
164 | ||||
|
165 | def _require_js(self, js_path): | |||
|
166 | # Since we are loading requirements that must be loaded before this call | |||
|
167 | # returns, preform async js load. | |||
|
168 | display(Javascript(data=""" | |||
|
169 | $.ajax({ | |||
|
170 | url: '{0}', | |||
|
171 | async: false, | |||
|
172 | dataType: "script", | |||
|
173 | timeout: 1000, // Wait a maximum of one second for the script to load. | |||
|
174 | }); | |||
|
175 | """.format(js_path))) No newline at end of file |
@@ -1,11 +1,12 b'' | |||||
1 | import os |
|
1 | import os | |
2 |
|
2 | |||
3 | from base import Widget |
|
3 | from base import Widget | |
4 | from IPython.utils.traitlets import Unicode |
|
4 | from IPython.utils.traitlets import Unicode, List | |
5 | from IPython.utils.javascript import display_all_js |
|
5 | from IPython.utils.javascript import display_all_js | |
6 |
|
6 | |||
7 | class ContainerWidget(Widget): |
|
7 | class ContainerWidget(Widget): | |
8 | target_name = Unicode('container_widget') |
|
8 | target_name = Unicode('container_widget') | |
9 | default_view_name = Unicode('ContainerView') |
|
9 | default_view_name = Unicode('ContainerView') | |
|
10 | js_requirements = List(["notebook/js/widgets/container.js"]) | |||
10 |
|
11 | |||
11 | _keys = [] |
|
12 | _keys = [] |
@@ -1,12 +1,13 b'' | |||||
1 | import os |
|
1 | import os | |
2 |
|
2 | |||
3 | from base import Widget |
|
3 | from base import Widget | |
4 | from IPython.utils.traitlets import Unicode, Float, Bool |
|
4 | from IPython.utils.traitlets import Unicode, Float, Bool, List | |
5 | from IPython.utils.javascript import display_all_js |
|
5 | from IPython.utils.javascript import display_all_js | |
6 |
|
6 | |||
7 | class FloatRangeWidget(Widget): |
|
7 | class FloatRangeWidget(Widget): | |
8 | target_name = Unicode('FloatRangeWidgetModel') |
|
8 | target_name = Unicode('FloatRangeWidgetModel') | |
9 | default_view_name = Unicode('FloatSliderView') |
|
9 | default_view_name = Unicode('FloatSliderView') | |
|
10 | js_requirements = List(["notebook/js/widgets/float_range.js"]) | |||
10 | _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'] |
|
11 | _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'] | |
11 |
|
12 | |||
12 | value = Float(0.0) |
|
13 | value = Float(0.0) |
@@ -1,12 +1,13 b'' | |||||
1 | import os |
|
1 | import os | |
2 |
|
2 | |||
3 | from base import Widget |
|
3 | from base import Widget | |
4 | from IPython.utils.traitlets import Unicode, Int, Bool |
|
4 | from IPython.utils.traitlets import Unicode, Int, Bool, List | |
5 | from IPython.utils.javascript import display_all_js |
|
5 | from IPython.utils.javascript import display_all_js | |
6 |
|
6 | |||
7 | class IntRangeWidget(Widget): |
|
7 | class IntRangeWidget(Widget): | |
8 | target_name = Unicode('IntRangeWidgetModel') |
|
8 | target_name = Unicode('IntRangeWidgetModel') | |
9 | default_view_name = Unicode('IntSliderView') |
|
9 | default_view_name = Unicode('IntSliderView') | |
|
10 | js_requirements = List(["notebook/js/widgets/int_range.js"]) | |||
10 | _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'] |
|
11 | _keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation'] | |
11 |
|
12 | |||
12 | value = Int(0) |
|
13 | value = Int(0) |
@@ -7,6 +7,7 b' from IPython.utils.javascript import display_all_js' | |||||
7 | class SelectionWidget(Widget): |
|
7 | class SelectionWidget(Widget): | |
8 | target_name = Unicode('SelectionWidgetModel') |
|
8 | target_name = Unicode('SelectionWidgetModel') | |
9 | default_view_name = Unicode('DropdownView') |
|
9 | default_view_name = Unicode('DropdownView') | |
|
10 | js_requirements = List(["notebook/js/widgets/selection.js"]) | |||
10 | _keys = ['value', 'values', 'disabled'] |
|
11 | _keys = ['value', 'values', 'disabled'] | |
11 |
|
12 | |||
12 | value = Unicode() |
|
13 | value = Unicode() |
@@ -1,12 +1,13 b'' | |||||
1 | import os |
|
1 | import os | |
2 |
|
2 | |||
3 | from base import Widget |
|
3 | from base import Widget | |
4 | from IPython.utils.traitlets import Unicode, Bool |
|
4 | from IPython.utils.traitlets import Unicode, Bool, List | |
5 | from IPython.utils.javascript import display_all_js |
|
5 | from IPython.utils.javascript import display_all_js | |
6 |
|
6 | |||
7 | class StringWidget(Widget): |
|
7 | class StringWidget(Widget): | |
8 | target_name = Unicode('StringWidgetModel') |
|
8 | target_name = Unicode('StringWidgetModel') | |
9 | default_view_name = Unicode('TextboxView') |
|
9 | default_view_name = Unicode('TextboxView') | |
|
10 | js_requirements = List(["notebook/js/widgets/string.js"]) | |||
10 | _keys = ['value', 'row_count', 'disabled'] |
|
11 | _keys = ['value', 'row_count', 'disabled'] | |
11 |
|
12 | |||
12 | value = Unicode() |
|
13 | value = Unicode() |
General Comments 0
You need to be logged in to leave comments.
Login now