Show More
@@ -62,14 +62,15 b' def _display_mimetype(mimetype, objs, raw=False, metadata=None):' | |||||
62 | Are the data objects raw data or Python objects that need to be |
|
62 | Are the data objects raw data or Python objects that need to be | |
63 | formatted before display? [default: False] |
|
63 | formatted before display? [default: False] | |
64 | metadata : dict (optional) |
|
64 | metadata : dict (optional) | |
65 | Metadata to be associated with the output. |
|
65 | Metadata to be associated with the specific mimetype output. | |
66 | """ |
|
66 | """ | |
|
67 | if metadata: | |||
|
68 | metadata = {mimetype: metadata} | |||
67 | if raw: |
|
69 | if raw: | |
68 | for obj in objs: |
|
70 | # turn list of pngdata into list of { 'image/png': pngdata } | |
69 | publish_display_data('display', {mimetype : obj}, metadata) |
|
71 | objs = [ {mimetype: obj} for obj in objs ] | |
70 | else: |
|
72 | display(*objs, raw=raw, metadata=metadata, include=[mimetype]) | |
71 | display(*objs, metadata=metadata, include=[mimetype]) |
|
73 | ||
72 |
|
||||
73 | #----------------------------------------------------------------------------- |
|
74 | #----------------------------------------------------------------------------- | |
74 | # Main functions |
|
75 | # Main functions | |
75 | #----------------------------------------------------------------------------- |
|
76 | #----------------------------------------------------------------------------- | |
@@ -84,6 +85,9 b' def display(*objs, **kwargs):' | |||||
84 | ---------- |
|
85 | ---------- | |
85 | objs : tuple of objects |
|
86 | objs : tuple of objects | |
86 | The Python objects to display. |
|
87 | The Python objects to display. | |
|
88 | raw : bool, optional | |||
|
89 | Are the objects to be displayed already mimetype-keyed dicts of raw display data, | |||
|
90 | or Python objects that need to be formatted before display? [default: False] | |||
87 | include : list or tuple, optional |
|
91 | include : list or tuple, optional | |
88 | A list of format type strings (MIME types) to include in the |
|
92 | A list of format type strings (MIME types) to include in the | |
89 | format data dict. If this is set *only* the format types included |
|
93 | format data dict. If this is set *only* the format types included | |
@@ -97,19 +101,24 b' def display(*objs, **kwargs):' | |||||
97 | mime-type keys in this dictionary will be associated with the individual |
|
101 | mime-type keys in this dictionary will be associated with the individual | |
98 | representation formats, if they exist. |
|
102 | representation formats, if they exist. | |
99 | """ |
|
103 | """ | |
|
104 | raw = kwargs.get('raw', False) | |||
100 | include = kwargs.get('include') |
|
105 | include = kwargs.get('include') | |
101 | exclude = kwargs.get('exclude') |
|
106 | exclude = kwargs.get('exclude') | |
102 | metadata = kwargs.get('metadata') |
|
107 | metadata = kwargs.get('metadata') | |
103 |
|
108 | |||
104 | from IPython.core.interactiveshell import InteractiveShell |
|
109 | from IPython.core.interactiveshell import InteractiveShell | |
105 | format = InteractiveShell.instance().display_formatter.format |
|
110 | ||
106 |
|
111 | if raw: | ||
107 | for obj in objs: |
|
112 | for obj in objs: | |
108 | format_dict, md_dict = format(obj, include=include, exclude=exclude) |
|
113 | publish_display_data('display', obj, metadata) | |
109 | if metadata: |
|
114 | else: | |
110 | # kwarg-specified metadata gets precedence |
|
115 | format = InteractiveShell.instance().display_formatter.format | |
111 | _merge(md_dict, metadata) |
|
116 | for obj in objs: | |
112 | publish_display_data('display', format_dict, md_dict) |
|
117 | format_dict, md_dict = format(obj, include=include, exclude=exclude) | |
|
118 | if metadata: | |||
|
119 | # kwarg-specified metadata gets precedence | |||
|
120 | _merge(md_dict, metadata) | |||
|
121 | publish_display_data('display', format_dict, md_dict) | |||
113 |
|
122 | |||
114 |
|
123 | |||
115 | def display_pretty(*objs, **kwargs): |
|
124 | def display_pretty(*objs, **kwargs): | |
@@ -124,7 +133,7 b' def display_pretty(*objs, **kwargs):' | |||||
124 | Are the data objects raw data or Python objects that need to be |
|
133 | Are the data objects raw data or Python objects that need to be | |
125 | formatted before display? [default: False] |
|
134 | formatted before display? [default: False] | |
126 | metadata : dict (optional) |
|
135 | metadata : dict (optional) | |
127 | Metadata to be associated with the output. |
|
136 | Metadata to be associated with the specific mimetype output. | |
128 | """ |
|
137 | """ | |
129 | _display_mimetype('text/plain', objs, **kwargs) |
|
138 | _display_mimetype('text/plain', objs, **kwargs) | |
130 |
|
139 | |||
@@ -141,7 +150,7 b' def display_html(*objs, **kwargs):' | |||||
141 | Are the data objects raw data or Python objects that need to be |
|
150 | Are the data objects raw data or Python objects that need to be | |
142 | formatted before display? [default: False] |
|
151 | formatted before display? [default: False] | |
143 | metadata : dict (optional) |
|
152 | metadata : dict (optional) | |
144 | Metadata to be associated with the output. |
|
153 | Metadata to be associated with the specific mimetype output. | |
145 | """ |
|
154 | """ | |
146 | _display_mimetype('text/html', objs, **kwargs) |
|
155 | _display_mimetype('text/html', objs, **kwargs) | |
147 |
|
156 | |||
@@ -158,7 +167,7 b' def display_svg(*objs, **kwargs):' | |||||
158 | Are the data objects raw data or Python objects that need to be |
|
167 | Are the data objects raw data or Python objects that need to be | |
159 | formatted before display? [default: False] |
|
168 | formatted before display? [default: False] | |
160 | metadata : dict (optional) |
|
169 | metadata : dict (optional) | |
161 | Metadata to be associated with the output. |
|
170 | Metadata to be associated with the specific mimetype output. | |
162 | """ |
|
171 | """ | |
163 | _display_mimetype('image/svg+xml', objs, **kwargs) |
|
172 | _display_mimetype('image/svg+xml', objs, **kwargs) | |
164 |
|
173 | |||
@@ -175,7 +184,7 b' def display_png(*objs, **kwargs):' | |||||
175 | Are the data objects raw data or Python objects that need to be |
|
184 | Are the data objects raw data or Python objects that need to be | |
176 | formatted before display? [default: False] |
|
185 | formatted before display? [default: False] | |
177 | metadata : dict (optional) |
|
186 | metadata : dict (optional) | |
178 | Metadata to be associated with the output. |
|
187 | Metadata to be associated with the specific mimetype output. | |
179 | """ |
|
188 | """ | |
180 | _display_mimetype('image/png', objs, **kwargs) |
|
189 | _display_mimetype('image/png', objs, **kwargs) | |
181 |
|
190 | |||
@@ -192,7 +201,7 b' def display_jpeg(*objs, **kwargs):' | |||||
192 | Are the data objects raw data or Python objects that need to be |
|
201 | Are the data objects raw data or Python objects that need to be | |
193 | formatted before display? [default: False] |
|
202 | formatted before display? [default: False] | |
194 | metadata : dict (optional) |
|
203 | metadata : dict (optional) | |
195 | Metadata to be associated with the output. |
|
204 | Metadata to be associated with the specific mimetype output. | |
196 | """ |
|
205 | """ | |
197 | _display_mimetype('image/jpeg', objs, **kwargs) |
|
206 | _display_mimetype('image/jpeg', objs, **kwargs) | |
198 |
|
207 | |||
@@ -209,7 +218,7 b' def display_latex(*objs, **kwargs):' | |||||
209 | Are the data objects raw data or Python objects that need to be |
|
218 | Are the data objects raw data or Python objects that need to be | |
210 | formatted before display? [default: False] |
|
219 | formatted before display? [default: False] | |
211 | metadata : dict (optional) |
|
220 | metadata : dict (optional) | |
212 | Metadata to be associated with the output. |
|
221 | Metadata to be associated with the specific mimetype output. | |
213 | """ |
|
222 | """ | |
214 | _display_mimetype('text/latex', objs, **kwargs) |
|
223 | _display_mimetype('text/latex', objs, **kwargs) | |
215 |
|
224 | |||
@@ -228,7 +237,7 b' def display_json(*objs, **kwargs):' | |||||
228 | Are the data objects raw data or Python objects that need to be |
|
237 | Are the data objects raw data or Python objects that need to be | |
229 | formatted before display? [default: False] |
|
238 | formatted before display? [default: False] | |
230 | metadata : dict (optional) |
|
239 | metadata : dict (optional) | |
231 | Metadata to be associated with the output. |
|
240 | Metadata to be associated with the specific mimetype output. | |
232 | """ |
|
241 | """ | |
233 | _display_mimetype('application/json', objs, **kwargs) |
|
242 | _display_mimetype('application/json', objs, **kwargs) | |
234 |
|
243 | |||
@@ -245,7 +254,7 b' def display_javascript(*objs, **kwargs):' | |||||
245 | Are the data objects raw data or Python objects that need to be |
|
254 | Are the data objects raw data or Python objects that need to be | |
246 | formatted before display? [default: False] |
|
255 | formatted before display? [default: False] | |
247 | metadata : dict (optional) |
|
256 | metadata : dict (optional) | |
248 | Metadata to be associated with the output. |
|
257 | Metadata to be associated with the specific mimetype output. | |
249 | """ |
|
258 | """ | |
250 | _display_mimetype('application/javascript', objs, **kwargs) |
|
259 | _display_mimetype('application/javascript', objs, **kwargs) | |
251 |
|
260 |
General Comments 0
You need to be logged in to leave comments.
Login now