Skip to content

Commit

Permalink
fix: custom msg'es do not have state
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Nov 30, 2018
1 parent d21eff1 commit a6b9e2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
7 changes: 4 additions & 3 deletions nbconvert/preprocessors/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,10 @@ def run_cell(self, cell, cell_index=0):
continue
elif msg_type.startswith('comm'):
data = content['data']
self.widget_state.setdefault(content['comm_id'], {}).update(data['state'])
if 'buffer_paths' in data and data['buffer_paths']:
self.widget_buffers[content['comm_id']] = _get_buffer_data(msg)
if 'state' in data: # ignore custom msg'es
self.widget_state.setdefault(content['comm_id'], {}).update(data['state'])
if 'buffer_paths' in data and data['buffer_paths']:
self.widget_buffers[content['comm_id']] = _get_buffer_data(msg)
continue

display_id = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,43 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a72770a4f541425f8fe85833a3dc2a8e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value=u'Hello World')"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"import ipywidgets\n",
"ipywidgets.Label('Hello World')"
"label = ipywidgets.Label('Hello World')\n",
"label"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# it should also handle custom msg'es\n",
"label.send({'msg': 'Hello'})"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
"pygments_lexer": "ipython3",
"version": "3.6.4"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_execute_function(self):

def test_widgets(self):
"""Runs a test notebook with widgets and checks the widget state is saved."""
input_file = os.path.join(current_dir, 'files', 'widget-hello-world.ipynb')
input_file = os.path.join(current_dir, 'files', 'JupyterWidgets.ipynb')
opts = dict(kernel_name="python")
res = self.build_resources()
res['metadata']['path'] = os.path.dirname(input_file)
Expand Down

0 comments on commit a6b9e2b

Please sign in to comment.