ó
æNXc           @  sŠ   d  Z  d d l m Z d e f d „  ƒ  YZ i  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d	 „  ƒ Z
 e d
 „  ƒ Z d S(   so  Infrastructure for registering and firing callbacks on application events.

Unlike :mod:`IPython.core.hooks`, which lets end users set single functions to
be called at specific times, or a collection of alternative methods to try,
callbacks are designed to be used by extension authors. A number of callbacks
can be registered for the same event without needing to be aware of one another.

The functions defined in this module are no-ops indicating the names of available
events and the arguments which will be passed to them.

.. note::

   This API is experimental in IPython 2.0, and may be revised in future versions.
iÿÿÿÿ(   t   print_functiont   EventManagerc           B  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s3  Manage a collection of events and a sequence of callbacks for each.
    
    This is attached to :class:`~IPython.core.interactiveshell.InteractiveShell`
    instances as an ``events`` attribute.
    
    .. note::

       This API is experimental in IPython 2.0, and may be revised in future versions.
    c         C  s    | |  _  d „  | Dƒ |  _ d S(   s  Initialise the :class:`CallbackManager`.
        
        Parameters
        ----------
        shell
          The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
        available_callbacks
          An iterable of names for callback events.
        c         S  s   i  |  ] } g  | “ q S(    (    (   t   .0t   n(    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pys
   <dictcomp>&   s   	 N(   t   shellt	   callbacks(   t   selfR   t   available_events(    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   __init__   s    
	c         C  s7   t  | ƒ s t d | ƒ ‚ n  |  j | j | ƒ d S(   sô  Register a new event callback
        
        Parameters
        ----------
        event : str
          The event for which to register this callback.
        function : callable
          A function to be called on the given event. It should take the same
          parameters as the appropriate callback prototype.
        
        Raises
        ------
        TypeError
          If ``function`` is not callable.
        KeyError
          If ``event`` is not one of the known events.
        s   Need a callable, got %rN(   t   callablet	   TypeErrorR   t   append(   R   t   eventt   function(    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   register(   s    c         C  s   |  j  | j | ƒ d S(   s'   Remove a callback from the given event.N(   R   t   remove(   R   R   R   (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt
   unregister>   s    c         O  sd   x] |  j  | D]N } y | | | Ž  Wq t k
 r[ t d j | | ƒ ƒ |  j j ƒ  q Xq Wd S(   sÑ   Call callbacks for ``event``.
        
        Any additional arguments are passed to all callbacks registered for this
        event. Exceptions raised by callbacks are caught, and a message printed.
        s   Error in callback {} (for {}):N(   R   t	   Exceptiont   printt   formatR   t   showtraceback(   R   R   t   argst   kwargst   func(    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   triggerB   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyR      s
   				c         C  s   |  t  |  j <|  S(   N(   R   R   (   t   callback_proto(    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   _define_eventR   s    c           C  s   d S(   s¨   Fires before code is executed in response to user/frontend action.
    
    This includes comm and widget messages and silent execution, as well as user
    code cells.N(    (    (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   pre_execute]   s    c           C  s   d S(   s$   Fires before user-entered code runs.N(    (    (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   pre_run_celle   s    c           C  s   d S(   s§   Fires after code is executed in response to user/frontend action.
    
    This includes comm and widget messages and silent execution, as well as user
    code cells.N(    (    (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   post_executej   s    c           C  s   d S(   s#   Fires after user-entered code runs.N(    (    (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   post_run_cellr   s    c         C  s   d S(   sQ  Fires after initialisation of :class:`~IPython.core.interactiveshell.InteractiveShell`.
    
    This is before extensions and startup scripts are loaded, so it can only be
    set by subclassing.
    
    Parameters
    ----------
    ip : :class:`~IPython.core.interactiveshell.InteractiveShell`
      The newly initialised shell.
    N(    (   t   ip(    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   shell_initializedw   s    N(   R   t
   __future__R    t   objectR   R   R   R   R   R    R!   R#   (    (    (    sK   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/events.pyt   <module>   s   ?	