Show More
@@ -73,8 +73,8 def display(*objs, **kwargs): | |||||
73 | publish = inst.display_pub.publish |
|
73 | publish = inst.display_pub.publish | |
74 |
|
74 | |||
75 | for obj in objs: |
|
75 | for obj in objs: | |
76 | format_dict = format(obj, include=include, exclude=exclude) |
|
76 | format_dict, md_dict = format(obj, include=include, exclude=exclude) | |
77 | publish('IPython.core.display.display', format_dict) |
|
77 | publish('IPython.core.display.display', format_dict, md_dict) | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | def display_pretty(*objs, **kwargs): |
|
80 | def display_pretty(*objs, **kwargs): |
@@ -153,7 +153,7 class DisplayHook(Configurable): | |||||
153 | """ |
|
153 | """ | |
154 | return self.shell.display_formatter.format(result) |
|
154 | return self.shell.display_formatter.format(result) | |
155 |
|
155 | |||
156 | def write_format_data(self, format_dict): |
|
156 | def write_format_data(self, format_dict, md_dict=None): | |
157 | """Write the format data dict to the frontend. |
|
157 | """Write the format data dict to the frontend. | |
158 |
|
158 | |||
159 | This default version of this method simply writes the plain text |
|
159 | This default version of this method simply writes the plain text | |
@@ -239,8 +239,8 class DisplayHook(Configurable): | |||||
239 | if result is not None and not self.quiet(): |
|
239 | if result is not None and not self.quiet(): | |
240 | self.start_displayhook() |
|
240 | self.start_displayhook() | |
241 | self.write_output_prompt() |
|
241 | self.write_output_prompt() | |
242 | format_dict = self.compute_format_data(result) |
|
242 | format_dict, md_dict = self.compute_format_data(result) | |
243 | self.write_format_data(format_dict) |
|
243 | self.write_format_data(format_dict, md_dict) | |
244 | self.update_user_ns(result) |
|
244 | self.update_user_ns(result) | |
245 | self.log_output(format_dict) |
|
245 | self.log_output(format_dict) | |
246 | self.finish_displayhook() |
|
246 | self.finish_displayhook() |
@@ -135,20 +135,31 class DisplayFormatter(Configurable): | |||||
135 | that format. |
|
135 | that format. | |
136 | """ |
|
136 | """ | |
137 | format_dict = {} |
|
137 | format_dict = {} | |
|
138 | md_dict = {} | |||
138 |
|
139 | |||
139 | for format_type, formatter in self.formatters.items(): |
|
140 | for format_type, formatter in self.formatters.items(): | |
140 | if include and format_type not in include: |
|
141 | if include and format_type not in include: | |
141 | continue |
|
142 | continue | |
142 | if exclude and format_type in exclude: |
|
143 | if exclude and format_type in exclude: | |
143 | continue |
|
144 | continue | |
|
145 | ||||
|
146 | md = None | |||
144 | try: |
|
147 | try: | |
145 | data = formatter(obj) |
|
148 | data = formatter(obj) | |
146 | except: |
|
149 | except: | |
147 | # FIXME: log the exception |
|
150 | # FIXME: log the exception | |
148 | raise |
|
151 | raise | |
|
152 | ||||
|
153 | # formatters can return raw data or (data, metadata) | |||
|
154 | if isinstance(data, tuple) and len(data) == 2: | |||
|
155 | data, md = data | |||
|
156 | ||||
149 | if data is not None: |
|
157 | if data is not None: | |
150 | format_dict[format_type] = data |
|
158 | format_dict[format_type] = data | |
151 | return format_dict |
|
159 | if md is not None: | |
|
160 | md_dict[format_type] = md | |||
|
161 | ||||
|
162 | return format_dict, md_dict | |||
152 |
|
163 | |||
153 | @property |
|
164 | @property | |
154 | def format_types(self): |
|
165 | def format_types(self): |
@@ -52,8 +52,9 class ZMQShellDisplayHook(DisplayHook): | |||||
52 | """Write the output prompt.""" |
|
52 | """Write the output prompt.""" | |
53 | self.msg['content']['execution_count'] = self.prompt_count |
|
53 | self.msg['content']['execution_count'] = self.prompt_count | |
54 |
|
54 | |||
55 | def write_format_data(self, format_dict): |
|
55 | def write_format_data(self, format_dict, md_dict=None): | |
56 | self.msg['content']['data'] = encode_images(format_dict) |
|
56 | self.msg['content']['data'] = encode_images(format_dict) | |
|
57 | self.msg['content']['metadata'] = md_dict | |||
57 |
|
58 | |||
58 | def finish_displayhook(self): |
|
59 | def finish_displayhook(self): | |
59 | """Finish up all displayhook activities.""" |
|
60 | """Finish up all displayhook activities.""" |
General Comments 0
You need to be logged in to leave comments.
Login now