##// END OF EJS Templates
Document custom key completions
Thomas Kluyver -
Show More
@@ -1,44 +1,52 b''
1 .. _integrating:
1 .. _integrating:
2
2
3 =====================================
3 =====================================
4 Integrating your objects with IPython
4 Integrating your objects with IPython
5 =====================================
5 =====================================
6
6
7 Tab completion
7 Tab completion
8 ==============
8 ==============
9
9
10 To change the attributes displayed by tab-completing your object, define a
10 To change the attributes displayed by tab-completing your object, define a
11 ``__dir__(self)`` method for it. For more details, see the documentation of the
11 ``__dir__(self)`` method for it. For more details, see the documentation of the
12 built-in `dir() function <http://docs.python.org/library/functions.html#dir>`_.
12 built-in `dir() function <http://docs.python.org/library/functions.html#dir>`_.
13
13
14 You can also customise key completions for your objects, e.g. pressing tab after
15 ``obj["a``. To do so, define a method ``_ipython_key_completions_()``, which
16 returns a list of objects which are possible keys in a subscript expression
17 ``obj[key]``.
18
19 .. versionadded:: 5.0
20 Custom key completions
21
14 Rich display
22 Rich display
15 ============
23 ============
16
24
17 The notebook and the Qt console can display richer representations of objects.
25 The notebook and the Qt console can display richer representations of objects.
18 To use this, you can define any of a number of ``_repr_*_()`` methods. Note that
26 To use this, you can define any of a number of ``_repr_*_()`` methods. Note that
19 these are surrounded by single, not double underscores.
27 these are surrounded by single, not double underscores.
20
28
21 Both the notebook and the Qt console can display ``svg``, ``png`` and ``jpeg``
29 Both the notebook and the Qt console can display ``svg``, ``png`` and ``jpeg``
22 representations. The notebook can also display ``html``, ``javascript``,
30 representations. The notebook can also display ``html``, ``javascript``,
23 and ``latex``. If the methods don't exist, or return ``None``, it falls
31 and ``latex``. If the methods don't exist, or return ``None``, it falls
24 back to a standard ``repr()``.
32 back to a standard ``repr()``.
25
33
26 For example::
34 For example::
27
35
28 class Shout(object):
36 class Shout(object):
29 def __init__(self, text):
37 def __init__(self, text):
30 self.text = text
38 self.text = text
31
39
32 def _repr_html_(self):
40 def _repr_html_(self):
33 return "<h1>" + self.text + "</h1>"
41 return "<h1>" + self.text + "</h1>"
34
42
35 Custom exception tracebacks
43 Custom exception tracebacks
36 ===========================
44 ===========================
37
45
38 Rarely, you might want to display a different traceback with an exception -
46 Rarely, you might want to display a different traceback with an exception -
39 IPython's own parallel computing framework does this to display errors from the
47 IPython's own parallel computing framework does this to display errors from the
40 engines. To do this, define a ``_render_traceback_(self)`` method which returns
48 engines. To do this, define a ``_render_traceback_(self)`` method which returns
41 a list of strings, each containing one line of the traceback.
49 a list of strings, each containing one line of the traceback.
42
50
43 Please be conservative in using this feature; by replacing the default traceback
51 Please be conservative in using this feature; by replacing the default traceback
44 you may hide important information from the user.
52 you may hide important information from the user.
General Comments 0
You need to be logged in to leave comments. Login now