##// END OF EJS Templates
Extend docs on customising object display
Thomas Kluyver -
Show More
@@ -28,8 +28,8 b' these are surrounded by single, not double underscores.'
28 28
29 29 Both the notebook and the Qt console can display ``svg``, ``png`` and ``jpeg``
30 30 representations. The notebook can also display ``html``, ``javascript``,
31 and ``latex``. If the methods don't exist, or return ``None``, it falls
32 back to a standard ``repr()``.
31 ``markdown`` and ``latex``. If the methods don't exist, or return ``None``, it
32 falls back to a standard ``repr()``.
33 33
34 34 For example::
35 35
@@ -40,6 +40,38 b' For example::'
40 40 def _repr_html_(self):
41 41 return "<h1>" + self.text + "</h1>"
42 42
43 There are also two more powerful display methods:
44
45 .. class:: MyObject
46
47 .. method:: _repr_mimebundle_(include=None, exclude=None)
48
49 Should return a dictionary of multiple formats, keyed by mimetype, or a tuple
50 of two dictionaries: *data, metadata*. If this returns something, other
51 ``_repr_*_`` methods are ignored. The method should take keyword arguments
52 ``include`` and ``exclude``, though it is not required to respect them.
53
54 .. method:: _ipython_display_()
55
56 Displays the object as a side effect; the return value is ignored. If this
57 is defined, all other display methods are ignored.
58
59 Formatters for third-party types
60 --------------------------------
61
62 The user can also register formatters for types without modifying the class::
63
64 from bar import Foo
65
66 def foo_html(obj):
67 return '<marquee>Foo object %s</marquee>' % obj.name
68
69 html_formatter = get_ipython().display_formatter.formatters['text/html']
70 html_formatter.for_type(Foo, foo_html)
71
72 # Or register a type without importing it - this does the same as above:
73 html_formatter.for_type_by_name('bar.Foo', foo_html)
74
43 75 Custom exception tracebacks
44 76 ===========================
45 77
General Comments 0
You need to be logged in to leave comments. Login now