##// END OF EJS Templates
Document new callbacks system
Thomas Kluyver -
Show More
@@ -0,0 +1,38 b''
1 =====================
2 Registering callbacks
3 =====================
4
5 Extension code can register callbacks functions which will be called on specific
6 events within the IPython code. You can see the current list of available
7 callbacks, and the parameters that will be passed with each, in the callback
8 prototype functions defined in :mod:`IPython.core.callbacks`.
9
10 To register callbacks, use :meth:`IPython.core.callbacks.CallbackManager.register`.
11 For example::
12
13 class VarWatcher(object):
14 def __init__(self, ip):
15 self.shell = ip
16 self.last_x = None
17
18 def pre_execute(self):
19 self.last_x = self.shell.user_ns.get('x', None)
20
21 def post_execute(self):
22 if self.shell.user_ns.get('x', None) != self.last_x:
23 print("x changed!")
24
25 def load_ipython_extension(ip):
26 vw = VarWatcher(ip)
27 ip.callbacks.register('pre_execute', vw.pre_execute)
28 ip.callbacks.register('post_execute', vw.post_execute)
29
30 .. seealso::
31
32 Module :mod:`IPython.core.hooks`
33 The older 'hooks' system allows end users to customise some parts of
34 IPython's behaviour.
35
36 :doc:`inputtransforms`
37 By registering input transformers that don't change code, you can monitor
38 what is being executed.
@@ -0,0 +1,1 b''
1 * A new callback system has been introduced. For details, see :doc:`/config/callbacks`.
@@ -120,5 +120,10 b' def shell_initialised(ip):'
120 120
121 121 This is before extensions and startup scripts are loaded, so it can only be
122 122 set by subclassing.
123
124 Parameters
125 ----------
126 ip : :class:`~IPython.core.interactiveshell.InteractiveShell`
127 The newly initialised shell.
123 128 """
124 129 pass
@@ -28,3 +28,4 b' Extending and integrating with IPython'
28 28 extensions/index
29 29 integrating
30 30 inputtransforms
31 callbacks
General Comments 0
You need to be logged in to leave comments. Login now