a
    §ˆcP  ã                   @   sJ   d Z ddlZddlmZmZmZ ddlmZ e e	¡Z
G dd„ deƒZdS )ú< A monitor for appearance and structural changes to a node. é    N)ÚAnyÚEventÚ	HasTraitsé   )Ú	NodeEventc                   @   s†   e Zd ZdZeƒ ZeeƒZeeƒZ	eeƒZ
eeƒZeeƒZdd„ Zdd„ Zg fdd„Zdd	d
„Zdd„ Zdd„ Zdd„ Zddd„ZdS )ÚNodeMonitorr   c                 C   s   | j jdur|  | j j¡ dS )z) Start listening to changes to the node. N©ÚnodeÚobjÚ_setup_trait_change_handlers©Úself© r   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/tree/node_monitor.pyÚstart@   s    zNodeMonitor.startc                 C   s"   | j jdur| j| j jdd� dS )z( Stop listening to changes to the node. NT)Úremover	   r   r   r   r   ÚstopF   s    zNodeMonitor.stopc                 C   s   t | j|d�| _dS )z  Fires the nodes changed event. ©r
   ÚchildrenN)r   r
   Únodes_changed©r   r   r   r   r   Úfire_nodes_changedL   s    zNodeMonitor.fire_nodes_changedéÿÿÿÿc                 C   s   t | j||d�| _dS )zµ Fires the nodes inserted event.

        If the index is -1 it means the nodes were appended.

        fixme: The tree and model should probably have an 'appended' event.

        )r
   r   ÚindexN)r   r
   Únodes_inserted)r   r   r   r   r   r   Úfire_nodes_insertedQ   s    	ÿzNodeMonitor.fire_nodes_insertedc                 C   s   t | j|d�| _dS )z  Fires the nodes removed event. r   N)r   r
   Únodes_removedr   r   r   r   Úfire_nodes_removed^   s    zNodeMonitor.fire_nodes_removedc                 C   s   t | j||d�| _dS )z! Fires the nodes replaced event. )r
   Úold_childrenr   N)r   r
   Únodes_replaced)r   r   Znew_childrenr   r   r   Úfire_nodes_replacedc   s    ÿzNodeMonitor.fire_nodes_replacedc                 C   s   t | jd�| _dS )z$ Fires the structure changed event. )r
   N)r   r
   Ústructure_changedr   r   r   r   Úfire_structure_changedj   s    z"NodeMonitor.fire_structure_changedFc                 C   s   t  d|rdpd|| ¡ dS )z5 Add or remove trait change handlers to/from a node. z.%s trait listeners on (%s) in NodeMonitor (%s)ZRemovingÚAddingN)ÚloggerÚdebug)r   r   r   r   r   r   r   s   s    
ü	z(NodeMonitor._setup_trait_change_handlersN)r   )F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r   r   r   r   r   r    r"   r   r   r   r   r   r!   r#   r   r   r   r   r   r      s   
	r   )r*   ÚloggingZ
traits.apir   r   r   Z
node_eventr   Ú	getLoggerr'   r%   r   r   r   r   r   Ú<module>   s
   
