Skip to content

Commit

Permalink
Use _repr_mimebundle_ instead of _ipython_display
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout committed Dec 31, 2019
1 parent 560c5a2 commit 8e7e8fe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 36 deletions.
3 changes: 1 addition & 2 deletions ipywidgets/widgets/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ def __init__(self, __interact_f, __options={}, **kwargs):
else:
for widget in self.kwargs_widgets:
widget.observe(self.update, names='value')

self.on_displayed(self.update)
self.update()

# Callback function
def update(self, *args):
Expand Down
33 changes: 4 additions & 29 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container,
Undefined)
from ipython_genutils.py3compat import string_types, PY3
from IPython.display import display
from json import loads as jsonloads, dumps as jsondumps

from base64 import standard_b64encode
Expand Down Expand Up @@ -400,7 +399,6 @@ def _default_keys(self):
_property_lock = Dict()
_holding_sync = False
_states_to_send = Set()
_display_callbacks = Instance(CallbackDispatcher, ())
_msg_callbacks = Instance(CallbackDispatcher, ())

#-------------------------------------------------------------------------
Expand Down Expand Up @@ -468,7 +466,7 @@ def close(self):
Widget.widgets.pop(self.model_id, None)
self.comm.close()
self.comm = None
self._ipython_display_ = None
self._repr_mimebundle_ = None

def send_state(self, key=None):
"""Sends the widget state, or a piece of it, to the front-end, if it exists.
Expand Down Expand Up @@ -570,21 +568,6 @@ def on_msg(self, callback, remove=False):
True if the callback should be unregistered."""
self._msg_callbacks.register_callback(callback, remove=remove)

def on_displayed(self, callback, remove=False):
"""(Un)Register a widget displayed callback.
Parameters
----------
callback: method handler
Must have a signature of::
callback(widget, **kwargs)
kwargs from display are passed through without modification.
remove: bool
True if the callback should be unregistered."""
self._display_callbacks.register_callback(callback, remove=remove)

def add_traits(self, **traits):
"""Dynamically add trait attributes to the Widget."""
super(Widget, self).add_traits(**traits)
Expand Down Expand Up @@ -692,10 +675,6 @@ def _handle_custom_msg(self, content, buffers):
"""Called when a custom msg is received."""
self._msg_callbacks(self, content, buffers)

def _handle_displayed(self, **kwargs):
"""Called when a view has been displayed for this widget instance"""
self._display_callbacks(self, **kwargs)

@staticmethod
def _trait_to_json(x, self):
"""Convert a trait value to json."""
Expand All @@ -706,9 +685,8 @@ def _trait_from_json(x, self):
"""Convert json values to objects."""
return x

def _ipython_display_(self, **kwargs):
"""Called when `IPython.display.display` is called on the widget."""

def _repr_mimebundle_(self, **kwargs):
"""Called when `IPython.display.display` is called."""
plaintext = repr(self)
if len(plaintext) > 110:
plaintext = plaintext[:110] + '…'
Expand All @@ -726,10 +704,7 @@ def _ipython_display_(self, **kwargs):
'version_minor': 0,
'model_id': self._model_id
}
display(data, raw=True)

if self._view_name is not None:
self._handle_displayed(**kwargs)
return data

def _send(self, msg, buffers=None):
"""Sends a message to the model in the front-end."""
Expand Down
5 changes: 0 additions & 5 deletions ipywidgets/widgets/widget_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ class Box(DOMWidget, CoreWidget):
def __init__(self, children=(), **kwargs):
kwargs['children'] = children
super(Box, self).__init__(**kwargs)
self.on_displayed(Box._fire_children_displayed)

def _fire_children_displayed(self):
for child in self.children:
child._handle_displayed()


@register
Expand Down

0 comments on commit 8e7e8fe

Please sign in to comment.