From 3527bb2254ade3598a4f01ade5eee62d0ebf9441 2014-01-17 17:25:09 From: Jonathan Frederic Date: 2014-01-17 17:25:09 Subject: [PATCH] Repr style out for widgets --- diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index b4ccf03..f9614b2 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -149,27 +149,30 @@ class DisplayFormatter(Configurable): format_dict = {} md_dict = {} - for format_type, formatter in self.formatters.items(): - if include and format_type not in include: - continue - if exclude and format_type in exclude: - continue - - md = None - try: - data = formatter(obj) - except: - # FIXME: log the exception - raise - - # formatters can return raw data or (data, metadata) - if isinstance(data, tuple) and len(data) == 2: - data, md = data - - if data is not None: - format_dict[format_type] = data - if md is not None: - md_dict[format_type] = md + # If _ipython_display_ is defined, use that to display this object. If + # it returns NotImplemented, use the _repr_ logic (default). + if not hasattr(obj, '_ipython_display_') or obj._ipython_display_(**kwargs) == NotImplemented: + for format_type, formatter in self.formatters.items(): + if include and format_type not in include: + continue + if exclude and format_type in exclude: + continue + + md = None + try: + data = formatter(obj) + except: + # FIXME: log the exception + raise + + # formatters can return raw data or (data, metadata) + if isinstance(data, tuple) and len(data) == 2: + data, md = data + + if data is not None: + format_dict[format_type] = data + if md is not None: + md_dict[format_type] = md return format_dict, md_dict