| 172 | |
| 173 | """ |
| 174 | def __init__(self, manager): |
| 175 | self.supports_binary = None |
| 176 | self.manager = manager |
| 177 | self.uuid = str(uuid.uuid4()) |
| 178 | # Publish an output area with a unique ID. The javascript can then |
| 179 | # hook into this area. |
| 180 | display(HTML("<div id=%r></div>" % self.uuid)) |
| 181 | try: |
| 182 | self.comm = Comm('matplotlib', data={'id': self.uuid}) |
| 183 | except AttributeError as err: |
| 184 | raise RuntimeError('Unable to create an IPython notebook Comm ' |
| 185 | 'instance. Are you in the IPython ' |
| 186 | 'notebook?') from err |
| 187 | self.comm.on_msg(self.on_message) |
| 188 | |
| 189 | manager = self.manager |
| 190 | self._ext_close = False |
| 191 | |
| 192 | def _on_close(close_message): |
| 193 | self._ext_close = True |
| 194 | manager.remove_comm(close_message['content']['comm_id']) |
| 195 | manager.clearup_closed() |
| 196 | |
| 197 | self.comm.on_close(_on_close) |
| 198 | |
| 199 | def is_open(self): |
| 200 | return not (self._ext_close or self.comm._closed) |