##// END OF EJS Templates
Better implementation of widget _repr_ style display logic.
Jonathan Frederic -
Show More
@@ -241,13 +241,16 class DisplayHook(Configurable):
241 """
241 """
242 self.check_for_underscore()
242 self.check_for_underscore()
243 if result is not None and not self.quiet():
243 if result is not None and not self.quiet():
244 self.start_displayhook()
244 # If _ipython_display_ is defined, use that to display this object. If
245 self.write_output_prompt()
245 # it returns NotImplemented, use the _repr_ logic (default).
246 format_dict, md_dict = self.compute_format_data(result)
246 if not hasattr(result, '_ipython_display_') or result._ipython_display_() == NotImplemented:
247 self.write_format_data(format_dict, md_dict)
247 self.start_displayhook()
248 self.update_user_ns(result)
248 self.write_output_prompt()
249 self.log_output(format_dict)
249 format_dict, md_dict = self.compute_format_data(result)
250 self.finish_displayhook()
250 self.write_format_data(format_dict, md_dict)
251 self.update_user_ns(result)
252 self.log_output(format_dict)
253 self.finish_displayhook()
251
254
252 def flush(self):
255 def flush(self):
253 if not self.do_full_cache:
256 if not self.do_full_cache:
@@ -149,30 +149,27 class DisplayFormatter(Configurable):
149 format_dict = {}
149 format_dict = {}
150 md_dict = {}
150 md_dict = {}
151
151
152 # If _ipython_display_ is defined, use that to display this object. If
152 for format_type, formatter in self.formatters.items():
153 # it returns NotImplemented, use the _repr_ logic (default).
153 if include and format_type not in include:
154 if not hasattr(obj, '_ipython_display_') or obj._ipython_display_(**kwargs) == NotImplemented:
154 continue
155 for format_type, formatter in self.formatters.items():
155 if exclude and format_type in exclude:
156 if include and format_type not in include:
156 continue
157 continue
157
158 if exclude and format_type in exclude:
158 md = None
159 continue
159 try:
160
160 data = formatter(obj)
161 md = None
161 except:
162 try:
162 # FIXME: log the exception
163 data = formatter(obj)
163 raise
164 except:
164
165 # FIXME: log the exception
165 # formatters can return raw data or (data, metadata)
166 raise
166 if isinstance(data, tuple) and len(data) == 2:
167
167 data, md = data
168 # formatters can return raw data or (data, metadata)
168
169 if isinstance(data, tuple) and len(data) == 2:
169 if data is not None:
170 data, md = data
170 format_dict[format_type] = data
171
171 if md is not None:
172 if data is not None:
172 md_dict[format_type] = md
173 format_dict[format_type] = data
174 if md is not None:
175 md_dict[format_type] = md
176
173
177 return format_dict, md_dict
174 return format_dict, md_dict
178
175
General Comments 0
You need to be logged in to leave comments. Login now