##// END OF EJS Templates
Basic display logic...
Jonathan Frederic -
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 from copy import copy
2 from copy import copy
7 import uuid
3 import uuid
8 import sys
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 class Widget(Comm):
11 class Widget(Comm):
12
12
13 ### Public declarations
13 ### Public declarations
14 target_name = Unicode('widget')
14 target_name = Unicode('widget')
15 default_view_name = Unicode()
15 view_name = Unicode()
16
16
17
17
18 ### Private/protected declarations
18 ### Private/protected declarations
@@ -31,7 +31,11 b' class Widget(Comm):'
31 if parent is not None:
31 if parent is not None:
32 parent._children.append(self)
32 parent._children.append(self)
33 self._parent = parent
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 self.comm = Comm(target_name=self.target_name)
39 self.comm = Comm(target_name=self.target_name)
36 self.comm.on_msg(self._handle_msg)
40 self.comm.on_msg(self._handle_msg)
37
41
@@ -114,9 +118,8 b' class Widget(Comm):'
114
118
115
119
116 ### Public methods
120 ### Public methods
117 def show(self, view_name=None):
121 def _repr_widget_(self):
118 if not view_name:
122 view_name = self.view_name
119 view_name = self.default_view_name
120 if not view_name:
123 if not view_name:
121 view_name = self.target_name
124 view_name = self.target_name
122
125
@@ -133,7 +136,8 b' class Widget(Comm):'
133
136
134 # Now show children if any.
137 # Now show children if any.
135 for child in self.children:
138 for child in self.children:
136 child.show()
139 child._repr_widget_()
140 return self._get_backbone_js
137
141
138
142
139 def send_state(self):
143 def send_state(self):
@@ -145,4 +149,7 b' class Widget(Comm):'
145 pass # Eat errors, nom nom nom
149 pass # Eat errors, nom nom nom
146 self.comm.send({"method": "update",
150 self.comm.send({"method": "update",
147 "state": state})
151 "state": state})
148 No newline at end of file
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