Format: application/x-python-code
⬇ Download File (5.4 KB)
   1  o
   2  
   3  ��h��@s`dZGdd�de�ZiZdd�Zedd��Zedd��Zed	d
   4  ��Zedd��Zed
   5  d��Z	dS)aoInfrastructure for registering and firing callbacks on application events.
   6  
   7  Unlike :mod:`IPython.core.hooks`, which lets end users set single functions to
   8  be called at specific times, or a collection of alternative methods to try,
   9  callbacks are designed to be used by extension authors. A number of callbacks
  10  can be registered for the same event without needing to be aware of one another.
  11  
  12  The functions defined in this module are no-ops indicating the names of available
  13  events and the arguments which will be passed to them.
  14  
  15  .. note::
  16  
  17     This API is experimental in IPython 2.0, and may be revised in future versions.
  18  c@s2eZdZdZddd�Zdd�Zdd�Zd	d
  19  �ZdS)
  20  �EventManagera3Manage a collection of events and a sequence of callbacks for each.
  21      
  22      This is attached to :class:`~IPython.core.interactiveshell.InteractiveShell`
  23      instances as an ``events`` attribute.
  24      
  25      .. note::
  26  
  27         This API is experimental in IPython 2.0, and may be revised in future versions.
  28      TcCs ||_dd�|D�|_||_dS)a�Initialise the :class:`CallbackManager`.
  29  
  30          Parameters
  31          ----------
  32          shell
  33              The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
  34          available_events
  35              An iterable of names for callback events.
  36          print_on_error:
  37              A boolean flag to set whether the EventManager will print a warning which a event errors.
  38          cSsi|]}|g�qS�r)�.0�nrr�Ic:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/events.py�
  39  <dictcomp>)sz)EventManager.__init__.<locals>.<dictcomp>N)�shell�	callbacks�print_on_error)�selfr�available_eventsr	rrr�__init__s
  40  zEventManager.__init__cCs:t|�s
  41  td|��||j|vr|j|�|�dSdS)a�Register a new event callback.
  42  
  43          Parameters
  44          ----------
  45          event : str
  46              The event for which to register this callback.
  47          function : callable
  48              A function to be called on the given event. It should take the same
  49              parameters as the appropriate callback prototype.
  50  
  51          Raises
  52          ------
  53          TypeError
  54              If ``function`` is not callable.
  55          KeyError
  56              If ``event`` is not one of the known events.
  57          zNeed a callable, got %rN)�callable�	TypeErrorr�append�r
  58  �event�functionrrr�register,s
  59  �zEventManager.registercCs.||j|vr|j|�|�Std�||���)z'Remove a callback from the given event.z0Function {!r} is not registered as a {} callback)r�remove�
  60  ValueError�formatrrrr�
  61  unregisterCszEventManager.unregistercOsh|j|dd�D](}z	||i|��Wq	ttfy1|jr*td�||||��|j��Yq	wdS)z�Call callbacks for ``event``.
  62  
  63          Any additional arguments are passed to all callbacks registered for this
  64          event. Exceptions raised by callbacks are caught, and a message printed.
  65          Nz@Error in callback {} (for {}), with arguments args {},kwargs {}:)r�	Exception�KeyboardInterruptr	�printrr�
  66  showtraceback)r
  67  r�args�kwargs�funcrrr�triggerJs����zEventManager.triggerN)T)�__name__�
  68  __module__�__qualname__�__doc__rrrrrrrrrs
  69  
  70  rcCs|t|j<|S)N)rr )Zcallback_functionrrr�
  71  _define_event_s
  72  r$cC�dS)z�Fires before code is executed in response to user/frontend action.
  73  
  74      This includes comm and widget messages and silent execution, as well as user
  75      code cells.
  76      Nrrrrr�pre_executej�r&cCr%)z�Fires before user-entered code runs.
  77  
  78      Parameters
  79      ----------
  80      info : :class:`~IPython.core.interactiveshell.ExecutionInfo`
  81          An object containing information used for the code execution.
  82      Nr)�inforrr�pre_run_cells�	r)cCr%)z�Fires after code is executed in response to user/frontend action.
  83  
  84      This includes comm and widget messages and silent execution, as well as user
  85      code cells.
  86      Nrrrrr�post_execute~r'r+cCr%)z�Fires after user-entered code runs.
  87  
  88      Parameters
  89      ----------
  90      result : :class:`~IPython.core.interactiveshell.ExecutionResult`
  91          The object which will be returned as the execution result.
  92      Nr)�resultrrr�
  93  post_run_cell�r*r-cCr%)aKFires after initialisation of :class:`~IPython.core.interactiveshell.InteractiveShell`.
  94  
  95      This is before extensions and startup scripts are loaded, so it can only be
  96      set by subclassing.
  97  
  98      Parameters
  99      ----------
 100      ip : :class:`~IPython.core.interactiveshell.InteractiveShell`
 101          The newly initialised shell.
 102      Nr)�iprrr�shell_initialized�sr/N)
 103  r#�objectrrr$r&r)r+r-r/rrrr�<module>sL
 104  
 105  
 106  
 107  
 108  
 109