a
    ¦ˆc\  ã                   @   s   d d„ Z G dd„ dƒZdS )c                 C   s   t | |||||d�}|ƒ  dS )aš   Add/Remove notifiers on objects following the description on an
    ObserverGraph.

    All nodes in ``ObserverGraph`` are required to be instances of
    ``IObserver``. The interface of ``IObserver`` supports this function.

    Parameters
    ----------
    object : object
        An object to be observed.
    graph : ObserverGraph
        A graph describing what and how extended traits are being observed.
        All nodes must be ``IObserver``.
    handler : callable(event)
        User-defined callable to handle change events.
        ``event`` is an object representing the change.
        Its type and content depends on the change.
    target : Any
        An object for defining the context of the user's handler notifier.
        This is typically an instance of HasTraits seen by the user as the
        "owner" of the observer.
    dispatcher : callable(callable, event)
        Callable for dispatching the user-defined handler, e.g. dispatching
        callback on a different thread.
    remove : boolean
        If true, notifiers are being removed.

    Raises
    ------
    NotiferNotFound
        Raised when notifier cannot be found for removal.
    ©ÚobjectÚgraphÚhandlerÚtargetÚ
dispatcherÚremoveN)Ú_AddOrRemoveNotifier)r   r   r   r   r   r   Z	callable_© r	   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/observation/_observe.pyÚadd_or_remove_notifiers   s    "úr   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )r   zo Callable for adding or removing notifiers.

    See ``add_or_remove_notifiers`` for the input parameters.
    c                C   s.   || _ || _|| _|| _|| _|| _g | _d S )N)r   r   r   r   r   r   Ú
_processed)Úselfr   r   r   r   r   r   r	   r	   r
   Ú__init__?   s    z_AddOrRemoveNotifier.__init__c                 C   s’   | j | j| j| jg}| jr(|ddd… }z|D ]
}|ƒ  q.W nF ty‚   | jr|| j ¡ \}}| jrp| |¡ qJ| 	|¡ qJ‚ Y n0 | j 
¡  dS )z6 Main function for adding/removing notifiers.
        Néÿÿÿÿ)Ú_add_or_remove_notifiersÚ_add_or_remove_maintainersÚ!_add_or_remove_children_notifiersÚ_add_or_remove_extra_graphsr   Ú	Exceptionr   ÚpopÚadd_toÚremove_fromÚclear)r   ZstepsÚstepÚnotifierÚ
observabler	   r	   r
   Ú__call__J   s$    ü	z_AddOrRemoveNotifier.__call__c              	   C   s8   | j j | j ¡D ]"}t| j|| j| j| j| jd� qdS )z~ Add or remove additional ObserverGraph contributed by the root
        observer. e.g. for handing trait_added event.
        r   N)	r   ÚnodeZiter_extra_graphsr   r   r   r   r   r   )r   Zextra_graphr	   r	   r
   r   k   s    úz0_AddOrRemoveNotifier._add_or_remove_extra_graphsc              
   C   sD   | j jD ]6}| j j | j¡D ] }t||| j| j| j| j	d� qqdS )zM Recursively add or remove notifiers for the children ObserverGraph.
        r   N)
r   Úchildrenr   Ziter_objectsr   r   r   r   r   r   )r   Úchild_graphZnext_objectr	   r	   r
   r   y   s    úz6_AddOrRemoveNotifier._add_or_remove_children_notifiersc                 C   sp   | j j | j¡D ]Z}| j jD ]L}| j jj|| j| j| jd�}| j	rN| 
|¡ n
| |¡ | j ||f¡ qqdS )z‰ Add or remove notifiers for maintaining children notifiers when
        the objects being observed by the root observer change.
        )r   r   r   r   N)r   r   Úiter_observablesr   r   Úget_maintainerr   r   r   r   r   r   r   Úappend)r   r   r   Zchange_notifierr	   r	   r
   r   ‡   s    ü
z/_AddOrRemoveNotifier._add_or_remove_maintainersc                 C   sn   | j jjsdS | j j | j¡D ]J}| j jj| j| j| jd�}| j	rN| 
|¡ n
| |¡ | j ||f¡ qdS )z] Add or remove user notifiers for the objects observed by the root
        observer.
        N)r   r   r   )r   r   Únotifyr    r   Zget_notifierr   r   r   r   r   r   r   r"   )r   r   r   r	   r	   r
   r   œ   s    
ý
z-_AddOrRemoveNotifier._add_or_remove_notifiersN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r	   r	   r	   r
   r   9   s   !r   N)r   r   r	   r	   r	   r
   Ú<module>   s   -