Skip to content

Commit fc173e8

Browse files
committed
Chop off fallback text representation to around 110 characters.
This prevents huge text output when it is a fallback. Length 110 is chosen as it fits on a single line in the classic Notebook.
1 parent 48c508a commit fc173e8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ipywidgets/widgets/widget.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,16 @@ def _ipython_display_(self, **kwargs):
701701
"""Called when `IPython.display.display` is called on the widget."""
702702
if self._view_name is not None:
703703

704+
plaintext = repr(self)
705+
if len(plaintext) > 110:
706+
plaintext = plaintext[:110] + '…'
704707
# The 'application/vnd.jupyter.widget-view+json' mimetype has not been registered yet.
705708
# See the registration process and naming convention at
706709
# http://tools.ietf.org/html/rfc6838
707710
# and the currently registered mimetypes at
708711
# http://www.iana.org/assignments/media-types/media-types.xhtml.
709712
data = {
710-
'text/plain': repr(self),
713+
'text/plain': plaintext,
711714
'application/vnd.jupyter.widget-view+json': {
712715
'version_major': 2,
713716
'version_minor': 0,

0 commit comments

Comments
 (0)