-
Notifications
You must be signed in to change notification settings - Fork 963
Using the new Comm Python package #3533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,7 +229,7 @@ def test_update_dynamically(self, send_state): #pylint: disable=no-self-use | |
| assert box.layout.grid_template_areas == ('"top-left top-right"\n' + | ||
| '"bottom-left bottom-right"') | ||
| # check whether frontend was informed | ||
| send_state.assert_called_once_with(key="grid_template_areas") | ||
| send_state.assert_called_with(key="grid_template_areas") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it not called once? is it called multiple times?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think the test was faulty from the beginning. Though it's unclear to me as to why my PR fixes it. Setting |
||
|
|
||
| box = widgets.TwoByTwoLayout(top_left=button1, top_right=button3, | ||
| bottom_left=None, bottom_right=button4) | ||
|
|
@@ -240,7 +240,7 @@ def test_update_dynamically(self, send_state): #pylint: disable=no-self-use | |
| box.merge = False | ||
| assert box.layout.grid_template_areas == ('"top-left top-right"\n' + | ||
| '"bottom-left bottom-right"') | ||
| send_state.assert_called_once_with(key="grid_template_areas") | ||
| send_state.assert_called_with(key="grid_template_areas") | ||
|
|
||
|
|
||
| class TestAppLayout(TestCase): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,8 @@ | |
| from contextlib import contextmanager | ||
| from collections.abc import Iterable | ||
| from IPython import get_ipython | ||
| from ipykernel.comm import Comm | ||
| from traitlets import ( | ||
| HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, | ||
| Any, HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, | ||
| Undefined) | ||
| from json import loads as jsonloads, dumps as jsondumps | ||
|
|
||
|
|
@@ -480,7 +479,7 @@ def get_view_spec(self): | |
|
|
||
| _view_count = Int(None, allow_none=True, | ||
| 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) | ||
| comm = Instance('ipykernel.comm.Comm', allow_none=True) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #3602 for removing this as a trait. |
||
| comm = Any(allow_none=True) | ||
|
|
||
| keys = List(help="The traits which are synced.") | ||
|
|
||
|
|
@@ -525,7 +524,15 @@ def open(self): | |
| if self._model_id is not None: | ||
| args['comm_id'] = self._model_id | ||
|
|
||
| self.comm = Comm(**args) | ||
| try: | ||
| from comm import create_comm | ||
| except ImportError: | ||
| def create_comm(**kwargs): | ||
| from ipykernel.comm import Comm | ||
|
|
||
| return Comm(**kwargs) | ||
|
|
||
| self.comm = create_comm(**args) | ||
|
|
||
| @observe('comm') | ||
| def _comm_changed(self, change): | ||
|
|
@@ -686,7 +693,7 @@ def notify_change(self, change): | |
| # Send the state to the frontend before the user-registered callbacks | ||
| # are called. | ||
| name = change['name'] | ||
| if self.comm is not None and self.comm.kernel is not None: | ||
| if self.comm is not None and getattr(self.comm, 'kernel', True) is not None: | ||
| # Make sure this isn't information that the front-end just sent us. | ||
| if name in self.keys and self._should_send_property(name, getattr(self, name)): | ||
| # Send new state to front-end | ||
|
|
@@ -814,7 +821,7 @@ def _repr_mimebundle_(self, **kwargs): | |
|
|
||
| def _send(self, msg, buffers=None): | ||
| """Sends a message to the model in the front-end.""" | ||
| if self.comm is not None and self.comm.kernel is not None: | ||
| if self.comm is not None and (self.comm.kernel is not None if hasattr(self.comm, "kernel") else True): | ||
| self.comm.send(data=msg, buffers=buffers) | ||
|
|
||
| def _repr_keys(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.