Show More
@@ -26,13 +26,13 b' from IPython.core.formatters import _safe_get_formatter_method' | |||
|
26 | 26 | from IPython.utils.py3compat import (string_types, cast_bytes_py2, cast_unicode, |
|
27 | 27 | unicode_type) |
|
28 | 28 | from IPython.testing.skipdoctest import skip_doctest |
|
29 | from .displaypub import publish_display_data | |
|
30 | 29 | |
|
31 | 30 | __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown', |
|
32 | 31 | 'display_svg', 'display_png', 'display_jpeg', 'display_latex', 'display_json', |
|
33 | 32 | 'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject', |
|
34 | 33 | 'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'JSON', 'Javascript', |
|
35 |
'clear_output', 'set_matplotlib_formats', 'set_matplotlib_close' |
|
|
34 | 'clear_output', 'set_matplotlib_formats', 'set_matplotlib_close', | |
|
35 | 'publish_display_data'] | |
|
36 | 36 | |
|
37 | 37 | #----------------------------------------------------------------------------- |
|
38 | 38 | # utility functions |
@@ -84,6 +84,48 b' def _display_mimetype(mimetype, objs, raw=False, metadata=None):' | |||
|
84 | 84 | # Main functions |
|
85 | 85 | #----------------------------------------------------------------------------- |
|
86 | 86 | |
|
87 | def publish_display_data(data, metadata=None, source=None): | |
|
88 | """Publish data and metadata to all frontends. | |
|
89 | ||
|
90 | See the ``display_data`` message in the messaging documentation for | |
|
91 | more details about this message type. | |
|
92 | ||
|
93 | The following MIME types are currently implemented: | |
|
94 | ||
|
95 | * text/plain | |
|
96 | * text/html | |
|
97 | * text/markdown | |
|
98 | * text/latex | |
|
99 | * application/json | |
|
100 | * application/javascript | |
|
101 | * image/png | |
|
102 | * image/jpeg | |
|
103 | * image/svg+xml | |
|
104 | ||
|
105 | Parameters | |
|
106 | ---------- | |
|
107 | data : dict | |
|
108 | A dictionary having keys that are valid MIME types (like | |
|
109 | 'text/plain' or 'image/svg+xml') and values that are the data for | |
|
110 | that MIME type. The data itself must be a JSON'able data | |
|
111 | structure. Minimally all data should have the 'text/plain' data, | |
|
112 | which can be displayed by all frontends. If more than the plain | |
|
113 | text is given, it is up to the frontend to decide which | |
|
114 | representation to use. | |
|
115 | metadata : dict | |
|
116 | A dictionary for metadata related to the data. This can contain | |
|
117 | arbitrary key, value pairs that frontends can use to interpret | |
|
118 | the data. mime-type keys matching those in data can be used | |
|
119 | to specify metadata about particular representations. | |
|
120 | source : str, deprecated | |
|
121 | Unused. | |
|
122 | """ | |
|
123 | from IPython.core.interactiveshell import InteractiveShell | |
|
124 | InteractiveShell.instance().display_pub.publish( | |
|
125 | data=data, | |
|
126 | metadata=metadata, | |
|
127 | ) | |
|
128 | ||
|
87 | 129 | def display(*objs, **kwargs): |
|
88 | 130 | """Display a Python object in all frontends. |
|
89 | 131 |
@@ -19,9 +19,11 b' from __future__ import print_function' | |||
|
19 | 19 | |
|
20 | 20 | from IPython.config.configurable import Configurable |
|
21 | 21 | from IPython.utils import io |
|
22 | from IPython.utils.py3compat import string_types | |
|
23 | 22 | from IPython.utils.traitlets import List |
|
24 | 23 | |
|
24 | # This used to be defined here - it is imported for backwards compatibility | |
|
25 | from .display import publish_display_data | |
|
26 | ||
|
25 | 27 | #----------------------------------------------------------------------------- |
|
26 | 28 | # Main payload class |
|
27 | 29 | #----------------------------------------------------------------------------- |
@@ -112,48 +114,3 b' class CapturingDisplayPublisher(DisplayPublisher):' | |||
|
112 | 114 | |
|
113 | 115 | # empty the list, *do not* reassign a new list |
|
114 | 116 | del self.outputs[:] |
|
115 | ||
|
116 | ||
|
117 | def publish_display_data(data, metadata=None, source=None): | |
|
118 | """Publish data and metadata to all frontends. | |
|
119 | ||
|
120 | See the ``display_data`` message in the messaging documentation for | |
|
121 | more details about this message type. | |
|
122 | ||
|
123 | The following MIME types are currently implemented: | |
|
124 | ||
|
125 | * text/plain | |
|
126 | * text/html | |
|
127 | * text/markdown | |
|
128 | * text/latex | |
|
129 | * application/json | |
|
130 | * application/javascript | |
|
131 | * image/png | |
|
132 | * image/jpeg | |
|
133 | * image/svg+xml | |
|
134 | ||
|
135 | Parameters | |
|
136 | ---------- | |
|
137 | data : dict | |
|
138 | A dictionary having keys that are valid MIME types (like | |
|
139 | 'text/plain' or 'image/svg+xml') and values that are the data for | |
|
140 | that MIME type. The data itself must be a JSON'able data | |
|
141 | structure. Minimally all data should have the 'text/plain' data, | |
|
142 | which can be displayed by all frontends. If more than the plain | |
|
143 | text is given, it is up to the frontend to decide which | |
|
144 | representation to use. | |
|
145 | metadata : dict | |
|
146 | A dictionary for metadata related to the data. This can contain | |
|
147 | arbitrary key, value pairs that frontends can use to interpret | |
|
148 | the data. mime-type keys matching those in data can be used | |
|
149 | to specify metadata about particular representations. | |
|
150 | source : str, deprecated | |
|
151 | Unused. | |
|
152 | """ | |
|
153 | from IPython.core.interactiveshell import InteractiveShell | |
|
154 | InteractiveShell.instance().display_pub.publish( | |
|
155 | data=data, | |
|
156 | metadata=metadata, | |
|
157 | ) | |
|
158 | ||
|
159 |
General Comments 0
You need to be logged in to leave comments.
Login now