Show More
@@ -26,7 +26,7 b" __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown'," | |||||
26 | 'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject', |
|
26 | 'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject', | |
27 | 'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'JSON', 'Javascript', |
|
27 | 'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'JSON', 'Javascript', | |
28 | 'Image', 'clear_output', 'set_matplotlib_formats', 'set_matplotlib_close', |
|
28 | 'Image', 'clear_output', 'set_matplotlib_formats', 'set_matplotlib_close', | |
29 | 'publish_display_data'] |
|
29 | 'publish_display_data', 'update_display'] | |
30 |
|
30 | |||
31 | #----------------------------------------------------------------------------- |
|
31 | #----------------------------------------------------------------------------- | |
32 | # utility functions |
|
32 | # utility functions | |
@@ -78,7 +78,7 b' def _display_mimetype(mimetype, objs, raw=False, metadata=None):' | |||||
78 | # Main functions |
|
78 | # Main functions | |
79 | #----------------------------------------------------------------------------- |
|
79 | #----------------------------------------------------------------------------- | |
80 |
|
80 | |||
81 | def publish_display_data(data, metadata=None, source=None): |
|
81 | def publish_display_data(data, metadata=None, source=None, transient=None, **kwargs): | |
82 | """Publish data and metadata to all frontends. |
|
82 | """Publish data and metadata to all frontends. | |
83 |
|
83 | |||
84 | See the ``display_data`` message in the messaging documentation for |
|
84 | See the ``display_data`` message in the messaging documentation for | |
@@ -113,11 +113,15 b' def publish_display_data(data, metadata=None, source=None):' | |||||
113 | to specify metadata about particular representations. |
|
113 | to specify metadata about particular representations. | |
114 | source : str, deprecated |
|
114 | source : str, deprecated | |
115 | Unused. |
|
115 | Unused. | |
|
116 | traisient : dict | |||
|
117 | A dictionary of transient data. | |||
116 | """ |
|
118 | """ | |
117 | from IPython.core.interactiveshell import InteractiveShell |
|
119 | from IPython.core.interactiveshell import InteractiveShell | |
118 | InteractiveShell.instance().display_pub.publish( |
|
120 | InteractiveShell.instance().display_pub.publish( | |
119 | data=data, |
|
121 | data=data, | |
120 | metadata=metadata, |
|
122 | metadata=metadata, | |
|
123 | transient=transient, | |||
|
124 | **kwargs | |||
121 | ) |
|
125 | ) | |
122 |
|
126 | |||
123 | def display(*objs, **kwargs): |
|
127 | def display(*objs, **kwargs): | |
@@ -145,11 +149,22 b' def display(*objs, **kwargs):' | |||||
145 | A dictionary of metadata to associate with the output. |
|
149 | A dictionary of metadata to associate with the output. | |
146 | mime-type keys in this dictionary will be associated with the individual |
|
150 | mime-type keys in this dictionary will be associated with the individual | |
147 | representation formats, if they exist. |
|
151 | representation formats, if they exist. | |
|
152 | transient : dict, optional | |||
|
153 | A dictionary of transient data to associate with the output. | |||
|
154 | Data in this dict should not be persisted to files (e.g. notebooks). | |||
|
155 | display_id : str, optional | |||
|
156 | Set an id for the display. | |||
|
157 | This id can be used for updating this display area later via update_display. | |||
148 | """ |
|
158 | """ | |
149 |
raw = kwargs. |
|
159 | raw = kwargs.pop('raw', False) | |
150 |
include = kwargs. |
|
160 | include = kwargs.pop('include', None) | |
151 |
exclude = kwargs. |
|
161 | exclude = kwargs.pop('exclude', None) | |
152 |
metadata = kwargs. |
|
162 | metadata = kwargs.pop('metadata', None) | |
|
163 | transient = kwargs.setdefault('transient', {}) | |||
|
164 | if 'display_id' in kwargs: | |||
|
165 | transient['display_id'] = kwargs.pop('display_id') | |||
|
166 | if kwargs.get('update') and 'display_id' not in transient: | |||
|
167 | raise TypeError('display_id required for update_display') | |||
153 |
|
168 | |||
154 | from IPython.core.interactiveshell import InteractiveShell |
|
169 | from IPython.core.interactiveshell import InteractiveShell | |
155 |
|
170 | |||
@@ -158,7 +173,7 b' def display(*objs, **kwargs):' | |||||
158 |
|
173 | |||
159 | for obj in objs: |
|
174 | for obj in objs: | |
160 | if raw: |
|
175 | if raw: | |
161 | publish_display_data(data=obj, metadata=metadata) |
|
176 | publish_display_data(data=obj, metadata=metadata, **kwargs) | |
162 | else: |
|
177 | else: | |
163 | format_dict, md_dict = format(obj, include=include, exclude=exclude) |
|
178 | format_dict, md_dict = format(obj, include=include, exclude=exclude) | |
164 | if not format_dict: |
|
179 | if not format_dict: | |
@@ -167,7 +182,14 b' def display(*objs, **kwargs):' | |||||
167 | if metadata: |
|
182 | if metadata: | |
168 | # kwarg-specified metadata gets precedence |
|
183 | # kwarg-specified metadata gets precedence | |
169 | _merge(md_dict, metadata) |
|
184 | _merge(md_dict, metadata) | |
170 |
publish_display_data(data=format_dict, metadata=md_dict |
|
185 | publish_display_data(data=format_dict, metadata=md_dict, | |
|
186 | **kwargs) | |||
|
187 | ||||
|
188 | ||||
|
189 | def update_display(*objs, **kwargs): | |||
|
190 | """Update an existing display""" | |||
|
191 | kwargs['update'] = True | |||
|
192 | return display(*objs, **kwargs) | |||
171 |
|
193 | |||
172 |
|
194 | |||
173 | def display_pretty(*objs, **kwargs): |
|
195 | def display_pretty(*objs, **kwargs): |
@@ -52,7 +52,7 b' class DisplayPublisher(Configurable):' | |||||
52 | if not isinstance(metadata, dict): |
|
52 | if not isinstance(metadata, dict): | |
53 | raise TypeError('metadata must be a dict, got: %r' % data) |
|
53 | raise TypeError('metadata must be a dict, got: %r' % data) | |
54 |
|
54 | |||
55 | def publish(self, data, metadata=None, source=None): |
|
55 | def publish(self, data, metadata=None, source=None, **kwargs): | |
56 | """Publish data and metadata to all frontends. |
|
56 | """Publish data and metadata to all frontends. | |
57 |
|
57 | |||
58 | See the ``display_data`` message in the messaging documentation for |
|
58 | See the ``display_data`` message in the messaging documentation for |
General Comments 0
You need to be logged in to leave comments.
Login now