|
9 | 9 |
|
10 | 10 | from ipywidgets import DOMWidget, widget_serialization
|
11 | 11 | from traitlets import (
|
12 |
| - Unicode, Bool, Float, List, Any, Instance, CaselessStrEnum, Enum, |
| 12 | + Unicode, Bool, CInt, Float, List, Any, Instance, CaselessStrEnum, Enum, |
13 | 13 | default
|
14 | 14 | )
|
15 | 15 |
|
@@ -152,6 +152,15 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore):
|
152 | 152 |
|
153 | 153 | header_visible = Bool(True).tag(sync=True)
|
154 | 154 |
|
| 155 | + _width = CInt().tag(sync=True) |
| 156 | + _height = CInt().tag(sync=True) |
| 157 | + |
| 158 | + _figure_label = Unicode('Figure').tag(sync=True) |
| 159 | + _message = Unicode().tag(sync=True) |
| 160 | + _cursor = Unicode('pointer').tag(sync=True) |
| 161 | + |
| 162 | + _image_mode = Unicode('full').tag(sync=True) |
| 163 | + |
155 | 164 | _closed = Bool(True)
|
156 | 165 |
|
157 | 166 | # Must declare the superclass private members.
|
@@ -183,7 +192,29 @@ def _handle_message(self, object, content, buffers):
|
183 | 192 | self.manager.handle_json(content)
|
184 | 193 |
|
185 | 194 | def send_json(self, content):
|
186 |
| - self.send({'data': json.dumps(content)}) |
| 195 | + # Change in the widget state? |
| 196 | + if content['type'] == 'cursor': |
| 197 | + cursors = ['pointer', 'default', 'crosshair', 'move'] |
| 198 | + self._cursor = cursors[content['cursor']] |
| 199 | + |
| 200 | + elif content['type'] == 'message': |
| 201 | + self._message = content['message'] |
| 202 | + |
| 203 | + elif content['type'] == 'figure_label': |
| 204 | + self._figure_label = content['label'] |
| 205 | + |
| 206 | + elif content['type'] == 'resize': |
| 207 | + self._width = content['size'][0] |
| 208 | + self._height = content['size'][1] |
| 209 | + # Send resize message anyway |
| 210 | + self.send({'data': json.dumps(content)}) |
| 211 | + |
| 212 | + elif content['type'] == 'image_mode': |
| 213 | + self._image_mode = content['mode'] |
| 214 | + |
| 215 | + else: |
| 216 | + # Default: send the message to the front-end |
| 217 | + self.send({'data': json.dumps(content)}) |
187 | 218 |
|
188 | 219 | def send_binary(self, data):
|
189 | 220 | self.send({'data': '{"type": "binary"}'}, buffers=[data])
|
|
0 commit comments