|
9 | 9 | from contextlib import contextmanager
|
10 | 10 | from collections.abc import Iterable
|
11 | 11 | from IPython import get_ipython
|
12 |
| -from ipykernel.comm import Comm |
| 12 | +from comm import create_comm |
13 | 13 | from traitlets import (
|
14 |
| - HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, |
| 14 | + Any, HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, |
15 | 15 | Undefined)
|
16 | 16 | from json import loads as jsonloads, dumps as jsondumps
|
17 | 17 |
|
@@ -421,7 +421,7 @@ def get_view_spec(self):
|
421 | 421 |
|
422 | 422 | _view_count = Int(None, allow_none=True,
|
423 | 423 | help="EXPERIMENTAL: The number of views of the model displayed in the frontend. This attribute is experimental and may change or be removed in the future. None signifies that views will not be tracked. Set this to 0 to start tracking view creation/deletion.").tag(sync=True)
|
424 |
| - comm = Instance('ipykernel.comm.Comm', allow_none=True) |
| 424 | + comm = Any(None, allow_none=True) |
425 | 425 |
|
426 | 426 | keys = List(help="The traits which are synced.")
|
427 | 427 |
|
@@ -466,7 +466,7 @@ def open(self):
|
466 | 466 | if self._model_id is not None:
|
467 | 467 | args['comm_id'] = self._model_id
|
468 | 468 |
|
469 |
| - self.comm = Comm(**args) |
| 469 | + self.comm = create_comm(**args) |
470 | 470 |
|
471 | 471 | @observe('comm')
|
472 | 472 | def _comm_changed(self, change):
|
@@ -627,11 +627,10 @@ def notify_change(self, change):
|
627 | 627 | # Send the state to the frontend before the user-registered callbacks
|
628 | 628 | # are called.
|
629 | 629 | name = change['name']
|
630 |
| - if self.comm is not None and self.comm.kernel is not None: |
631 |
| - # Make sure this isn't information that the front-end just sent us. |
632 |
| - if name in self.keys and self._should_send_property(name, getattr(self, name)): |
633 |
| - # Send new state to front-end |
634 |
| - self.send_state(key=name) |
| 630 | + # Make sure this isn't information that the front-end just sent us. |
| 631 | + if name in self.keys and self._should_send_property(name, getattr(self, name)): |
| 632 | + # Send new state to front-end |
| 633 | + self.send_state(key=name) |
635 | 634 | super().notify_change(change)
|
636 | 635 |
|
637 | 636 | def __repr__(self):
|
@@ -755,7 +754,7 @@ def _repr_mimebundle_(self, **kwargs):
|
755 | 754 |
|
756 | 755 | def _send(self, msg, buffers=None):
|
757 | 756 | """Sends a message to the model in the front-end."""
|
758 |
| - if self.comm is not None and self.comm.kernel is not None: |
| 757 | + if self.comm is not None: |
759 | 758 | self.comm.send(data=msg, buffers=buffers)
|
760 | 759 |
|
761 | 760 | def _repr_keys(self):
|
|
0 commit comments