Show More
@@ -1,18 +1,18 b'' | |||
|
1 | from IPython.kernel.comm import Comm | |
|
2 | from IPython.config import LoggingConfigurable | |
|
3 | from IPython.utils.traitlets import Unicode, Float, Bool, Dict | |
|
4 | from IPython.display import clear_output | |
|
5 | 1 |
|
|
6 | 2 | from copy import copy |
|
7 | 3 | import uuid |
|
8 | 4 | import sys |
|
9 | 5 | |
|
6 | from IPython.kernel.comm import Comm | |
|
7 | from IPython.config import LoggingConfigurable | |
|
8 | from IPython.utils.traitlets import Unicode, Dict | |
|
9 | from IPython.display import Javascript, display | |
|
10 | 10 | |
|
11 | 11 | class Widget(Comm): |
|
12 | 12 | |
|
13 | 13 | ### Public declarations |
|
14 | 14 | target_name = Unicode('widget') |
|
15 |
|
|
|
15 | view_name = Unicode() | |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | ### Private/protected declarations |
@@ -32,6 +32,10 b' class Widget(Comm):' | |||
|
32 | 32 | parent._children.append(self) |
|
33 | 33 | self._parent = parent |
|
34 | 34 | |
|
35 | # Send frontend type code. | |
|
36 | display(Javascript(data=self._get_backbone_js())) | |
|
37 | ||
|
38 | # Create a comm. | |
|
35 | 39 | self.comm = Comm(target_name=self.target_name) |
|
36 | 40 | self.comm.on_msg(self._handle_msg) |
|
37 | 41 | |
@@ -114,9 +118,8 b' class Widget(Comm):' | |||
|
114 | 118 | |
|
115 | 119 | |
|
116 | 120 | ### Public methods |
|
117 | def show(self, view_name=None): | |
|
118 | if not view_name: | |
|
119 | view_name = self.default_view_name | |
|
121 | def _repr_widget_(self): | |
|
122 | view_name = self.view_name | |
|
120 | 123 | if not view_name: |
|
121 | 124 | view_name = self.target_name |
|
122 | 125 | |
@@ -133,7 +136,8 b' class Widget(Comm):' | |||
|
133 | 136 | |
|
134 | 137 | # Now show children if any. |
|
135 | 138 | for child in self.children: |
|
136 |
child. |
|
|
139 | child._repr_widget_() | |
|
140 | return self._get_backbone_js | |
|
137 | 141 | |
|
138 | 142 | |
|
139 | 143 | def send_state(self): |
@@ -146,3 +150,6 b' class Widget(Comm):' | |||
|
146 | 150 | self.comm.send({"method": "update", |
|
147 | 151 | "state": state}) |
|
148 | 152 | |
|
153 | ### Private methods | |
|
154 | def _get_backbone_js(self): | |
|
155 | return 'alert("woohoo!");' |
General Comments 0
You need to be logged in to leave comments.
Login now