##// END OF EJS Templates
display_mime(objs, metadata) puts metadata into mime type key...
MinRK -
Show More
@@ -62,14 +62,15 b' def _display_mimetype(mimetype, objs, raw=False, metadata=None):'
62 62 Are the data objects raw data or Python objects that need to be
63 63 formatted before display? [default: False]
64 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 69 if raw:
68 for obj in objs:
69 publish_display_data('display', {mimetype : obj}, metadata)
70 else:
71 display(*objs, metadata=metadata, include=[mimetype])
72
70 # turn list of pngdata into list of { 'image/png': pngdata }
71 objs = [ {mimetype: obj} for obj in objs ]
72 display(*objs, raw=raw, metadata=metadata, include=[mimetype])
73
73 74 #-----------------------------------------------------------------------------
74 75 # Main functions
75 76 #-----------------------------------------------------------------------------
@@ -84,6 +85,9 b' def display(*objs, **kwargs):'
84 85 ----------
85 86 objs : tuple of objects
86 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 91 include : list or tuple, optional
88 92 A list of format type strings (MIME types) to include in the
89 93 format data dict. If this is set *only* the format types included
@@ -97,19 +101,24 b' def display(*objs, **kwargs):'
97 101 mime-type keys in this dictionary will be associated with the individual
98 102 representation formats, if they exist.
99 103 """
104 raw = kwargs.get('raw', False)
100 105 include = kwargs.get('include')
101 106 exclude = kwargs.get('exclude')
102 107 metadata = kwargs.get('metadata')
103 108
104 109 from IPython.core.interactiveshell import InteractiveShell
105 format = InteractiveShell.instance().display_formatter.format
106
107 for obj in objs:
108 format_dict, md_dict = format(obj, include=include, exclude=exclude)
109 if metadata:
110 # kwarg-specified metadata gets precedence
111 _merge(md_dict, metadata)
112 publish_display_data('display', format_dict, md_dict)
110
111 if raw:
112 for obj in objs:
113 publish_display_data('display', obj, metadata)
114 else:
115 format = InteractiveShell.instance().display_formatter.format
116 for obj in objs:
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 124 def display_pretty(*objs, **kwargs):
@@ -124,7 +133,7 b' def display_pretty(*objs, **kwargs):'
124 133 Are the data objects raw data or Python objects that need to be
125 134 formatted before display? [default: False]
126 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 138 _display_mimetype('text/plain', objs, **kwargs)
130 139
@@ -141,7 +150,7 b' def display_html(*objs, **kwargs):'
141 150 Are the data objects raw data or Python objects that need to be
142 151 formatted before display? [default: False]
143 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 155 _display_mimetype('text/html', objs, **kwargs)
147 156
@@ -158,7 +167,7 b' def display_svg(*objs, **kwargs):'
158 167 Are the data objects raw data or Python objects that need to be
159 168 formatted before display? [default: False]
160 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 172 _display_mimetype('image/svg+xml', objs, **kwargs)
164 173
@@ -175,7 +184,7 b' def display_png(*objs, **kwargs):'
175 184 Are the data objects raw data or Python objects that need to be
176 185 formatted before display? [default: False]
177 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 189 _display_mimetype('image/png', objs, **kwargs)
181 190
@@ -192,7 +201,7 b' def display_jpeg(*objs, **kwargs):'
192 201 Are the data objects raw data or Python objects that need to be
193 202 formatted before display? [default: False]
194 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 206 _display_mimetype('image/jpeg', objs, **kwargs)
198 207
@@ -209,7 +218,7 b' def display_latex(*objs, **kwargs):'
209 218 Are the data objects raw data or Python objects that need to be
210 219 formatted before display? [default: False]
211 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 223 _display_mimetype('text/latex', objs, **kwargs)
215 224
@@ -228,7 +237,7 b' def display_json(*objs, **kwargs):'
228 237 Are the data objects raw data or Python objects that need to be
229 238 formatted before display? [default: False]
230 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 242 _display_mimetype('application/json', objs, **kwargs)
234 243
@@ -245,7 +254,7 b' def display_javascript(*objs, **kwargs):'
245 254 Are the data objects raw data or Python objects that need to be
246 255 formatted before display? [default: False]
247 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 259 _display_mimetype('application/javascript', objs, **kwargs)
251 260
General Comments 0
You need to be logged in to leave comments. Login now