3
=Ad]  ã               @   s8   d Z ddlZddlmZmZmZmZ G dd„ deƒZdS )z: A hook to allow code be executed when a class is loaded. é    N)ÚCallableÚ	HasTraitsÚMetaHasTraitsÚStrc               @   s8   e Zd ZdZeZeZdd„ Zdd„ Z	dd„ Z
dd	„ Zd
S )ÚClassLoadHookz· A hook to allow code to be executed when a class is loaded.

    If the class is *already* loaded when the 'connect' method is called then
    the code is executed immediately.

    c             C   s2   t j| j| jƒ | j| jƒ}|dk	r.| j|ƒ dS )z= Connect the load hook to listen for the class being loaded. N)r   Zadd_listenerÚon_class_loadedÚ
class_nameÚ
_get_class)ÚselfÚcls© r   út/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/envisage-4.7.2-py3.6.egg/envisage/class_load_hook.pyÚconnect$   s
    
zClassLoadHook.connectc             C   s   t j| j| jƒ dS )z Disconnect the load hook. N)r   Zremove_listenerr   r   )r
   r   r   r   Ú
disconnect0   s    zClassLoadHook.disconnectc             C   s   | j dk	r| j |ƒ dS )z€ This method is called when the class is loaded.

        If 'self.on_load' is not None, it calls 'self.on_load(cls)'.

        N)Úon_load)r
   r   r   r   r   r   7   s    

zClassLoadHook.on_class_loadedc             C   sf   d|kr^|j dƒ}dj|dd… ƒ}|d }tjj|dƒ}|dk	rXt||ƒrXt||ƒ}qbd}nd}|S )zu Returns the class defined by *class_path*.

        Returns **None** if the class has not yet been loaded.

        Ú.Né   éÿÿÿÿr   )ÚsplitÚjoinÚsysÚmodulesÚgetÚhasattrÚgetattr)r
   Z
class_pathÚ
componentsÚmodule_namer   ÚmoduleÚklassr   r   r   r	   G   s    

zClassLoadHook._get_classN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	   r   r   r   r   r      s   r   )r"   r   Z
traits.apir   r   r   r   r   r   r   r   r   Ú<module>   s   