Show More
@@ -252,8 +252,9 b' def display(*objs, include=None, exclude=None, metadata=None, transient=None, di' | |||
|
252 | 252 | display in IPython by following the above approach. But in practice, you |
|
253 | 253 | often need to work with existing classes that you can't easily modify. |
|
254 | 254 | |
|
255 |
You can refer to the documentation on |
|
|
256 |
register custom formatters for already existing types |
|
|
255 | You can refer to the documentation on integrating with the display system in | |
|
256 | order to register custom formatters for already existing types | |
|
257 | (:ref:`integrating_rich_display`). | |
|
257 | 258 | |
|
258 | 259 | .. versionadded:: 5.4 display available without import |
|
259 | 260 | .. versionadded:: 6.1 display available without import |
@@ -19,6 +19,8 b' returns a list of objects which are possible keys in a subscript expression' | |||
|
19 | 19 | .. versionadded:: 5.0 |
|
20 | 20 | Custom key completions |
|
21 | 21 | |
|
22 | .. _integrating_rich_display: | |
|
23 | ||
|
22 | 24 | Rich display |
|
23 | 25 | ============ |
|
24 | 26 | |
@@ -28,8 +30,8 b' these are surrounded by single, not double underscores.' | |||
|
28 | 30 | |
|
29 | 31 | Both the notebook and the Qt console can display ``svg``, ``png`` and ``jpeg`` |
|
30 | 32 | representations. The notebook can also display ``html``, ``javascript``, |
|
31 |
and ``latex``. If the methods don't exist, or return ``None``, it |
|
|
32 | back to a standard ``repr()``. | |
|
33 | ``markdown`` and ``latex``. If the methods don't exist, or return ``None``, it | |
|
34 | falls back to a standard ``repr()``. | |
|
33 | 35 | |
|
34 | 36 | For example:: |
|
35 | 37 | |
@@ -40,6 +42,38 b' For example::' | |||
|
40 | 42 | def _repr_html_(self): |
|
41 | 43 | return "<h1>" + self.text + "</h1>" |
|
42 | 44 | |
|
45 | There are also two more powerful display methods: | |
|
46 | ||
|
47 | .. class:: MyObject | |
|
48 | ||
|
49 | .. method:: _repr_mimebundle_(include=None, exclude=None) | |
|
50 | ||
|
51 | Should return a dictionary of multiple formats, keyed by mimetype, or a tuple | |
|
52 | of two dictionaries: *data, metadata*. If this returns something, other | |
|
53 | ``_repr_*_`` methods are ignored. The method should take keyword arguments | |
|
54 | ``include`` and ``exclude``, though it is not required to respect them. | |
|
55 | ||
|
56 | .. method:: _ipython_display_() | |
|
57 | ||
|
58 | Displays the object as a side effect; the return value is ignored. If this | |
|
59 | is defined, all other display methods are ignored. | |
|
60 | ||
|
61 | Formatters for third-party types | |
|
62 | -------------------------------- | |
|
63 | ||
|
64 | The user can also register formatters for types without modifying the class:: | |
|
65 | ||
|
66 | from bar import Foo | |
|
67 | ||
|
68 | def foo_html(obj): | |
|
69 | return '<marquee>Foo object %s</marquee>' % obj.name | |
|
70 | ||
|
71 | html_formatter = get_ipython().display_formatter.formatters['text/html'] | |
|
72 | html_formatter.for_type(Foo, foo_html) | |
|
73 | ||
|
74 | # Or register a type without importing it - this does the same as above: | |
|
75 | html_formatter.for_type_by_name('bar.Foo', foo_html) | |
|
76 | ||
|
43 | 77 | Custom exception tracebacks |
|
44 | 78 | =========================== |
|
45 | 79 |
General Comments 0
You need to be logged in to leave comments.
Login now