a
    ¦ˆcæ   ã                   @   sº   d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZ dd	lmZ dd
lmZ dd„ Ze	jG dd„ dejƒƒZdd„ Ze e¡ e eee¡ e e¡ dS )a   Defines the core CTrait class.

The CTrait class extends the C-level cTrait type to provide the full CTrait
API. CTraits are the core objects that are used to generate defaults and
validate as well as maintaining a list of notifiers and calling them when
values are modified.
é    Né   )Úctraits)ÚComparisonModeÚDefaultValueÚdefault_value_map)ÚIObservable)ÚSequenceTypesÚ	Undefined)ÚTraitDictObject)ÚTraitListObject)ÚTraitSetObjectc                 G   s   | j | g|¢R Ž S )z" Unpickles new-style objects.
    )Ú__new__)ÚclsÚargs© r   úP/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traits/ctrait.pyÚ
__newobj__   s    r   c                       s¾   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	e‡ fdd„ƒZ
e
jdd„ ƒZ
edd„ ƒZejdd„ ƒZdd„ Zdd„ Zd!dd„Zdd„ Zdd„ Zdd„ Zdd „ Z‡  ZS )"ÚCTraitz1 Extends the underlying C-based cTrait type.
    c                 O   sn   ddl m} ddlm} | j}t||ƒrN| jp0i  ¡ }| |¡ ||i |¤ŽS | 	d| ¡ ||| f i |¤ŽS )z8 Allows a derivative trait to be defined from this one. r   )Ú	TraitType)ÚTraitÚparent)
Ú
trait_typer   Útraitsr   ÚhandlerÚ
isinstanceÚ__dict__ÚcopyÚupdateÚ
setdefault)Úselfr   Úmetadatar   r   r   Údictr   r   r   Ú__call__)   s    

zCTrait.__call__c                 C   sr   |   ¡ \}}|tjtjtjtjfv r(tS |tjtjtj	tj
tjfv rL| ¡ S |tjtjhv r`|S td |¡ƒ‚d S )Nz#Unexpected default value kind: {!r})Údefault_valuer   ÚobjectZcallable_and_argsÚcallableZdisallowr	   Z	dict_copyÚtrait_dict_objectÚtrait_set_objectZ	list_copyÚtrait_list_objectr   ZconstantÚmissingÚRuntimeErrorÚformat)r   ÚkindÚvaluer   r   r   Údefault8   s*    üûÿzCTrait.defaultc                 C   s   t |  ¡ d  S )Nr   )r   r#   ©r   r   r   r   Údefault_kindR   s    zCTrait.default_kindc                 C   s&   | j }|d ur|S ddlm} |S d S )Nr   )ÚAny)r   Ztrait_typesr1   )r   r   r1   r   r   r   r   V   s
    zCTrait.trait_typec                 C   s   | j }|d ur| ¡ S dS )Nr   )r   Úinner_traits©r   r   r   r   r   r2   `   s    zCTrait.inner_traitsc                    s   t ƒ j}t|ƒS )z¢ Get or set the comparison mode on the trait.
        Getter returns a ComparisonMode enum.
        Setter acceps either an int or a ComparisonMode enum.
        )ÚsuperÚcomparison_moder   )r   Zi_comparison_mode©Ú	__class__r   r   r5   h   s    zCTrait.comparison_modec                 C   s   t jj | |¡ d S )N)r   ÚcTraitr5   Ú__set__)r   r-   r   r   r   r5   q   s    c                 C   s   |   ¡ S )zS Return a tuple of callables (fget, fset, validate) for the
        property trait.)Z_get_propertyr/   r   r   r   Úproperty_fieldsu   s    zCTrait.property_fieldsc                 C   sL   g }|D ]4}|du rd}nt  |¡}t|jƒ}| ||g¡ q| j|Ž  dS )zË Set the fget, fset, validate callables for the property.

        Parameters
        ----------
        value : tuple
            Value should be the tuple of callables (fget, fset, validate).

        Nr   )ÚinspectÚ	signatureÚlenÚ
parametersÚextendZ_set_property)r   r-   Zfunc_arg_countsÚargÚnargsÚsigr   r   r   r:   {   s    


c                 C   s   t | j|ƒS )zI Returns whether or not this trait is of a specified trait type.
        )r   r   )r   r   r   r   r   Úis_trait_type“   s    zCTrait.is_trait_typec                 C   sÜ   ddl m} | j}|du rJ| j}|dur2| | ¡}|du rJddl m} |}t||ƒsÒd}i }t|ƒtv rÄ|dd… D ]N}t|ƒtv rŽt	|ƒ}qtt|t
ƒr¾|}| dd¡du rÂ| ¡ }| |d< qt|}qt||i |¤Ž}|| _|S )zF Returns the user interface editor associated with the trait.
        r   )ÚEditorFactoryN)Ú
TextEditorr   Ztrait)Ztraitsui.apirD   Úeditorr   Ú
get_editorrE   r   Útyper   Útupler!   Úgetr   )r   rD   rF   r   rE   r   r   Úitemr   r   r   rG   ˜   s2    




zCTrait.get_editorTc                 C   sZ   |r| j }|dur|S | j}|dur2d| ¡  }nd}| j}| jdu rN| ¡ S d||f S )a¨   Returns the help text for a trait.

        If *full* is False or the trait does not have a **help** string,
        the returned string is constructed from the **desc** attribute on the
        trait and the **info** string on the trait's handler.

        Parameters
        ----------
        full : bool
            Indicates whether to return the value of the *help* attribute of
            the trait itself.
        Nzmust be %s.zmay be any value.zSpecifies %s and %s)Úhelpr   ÚinfoÚdescÚ
capitalize)r   ÚfullrL   r   rM   rN   r   r   r   Úget_helpÄ   s    
zCTrait.get_helpc                 C   s    | j }|dur| |||¡S dS ©z- Returns a description of the trait.
        Nz	any value)r   Ú	full_info)r   r$   Únamer-   r   r   r   r   rS   â   s    zCTrait.full_infoc                 C   s   | j }|dur| ¡ S dS rR   )r   rM   r3   r   r   r   rM   ë   s    zCTrait.infoc                 C   s   | S )z0 Method that returns self for trait converters. r   r/   r   r   r   Ú	as_ctraitô   s    zCTrait.as_ctraitc                 C   s   t | jdf|  ¡ fS )z1 Returns the pickleable form of a CTrait object. r   )r   r7   Ú__getstate__)r   Úprotocolr   r   r   Ú__reduce_ex__ø   s    zCTrait.__reduce_ex__)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   Úpropertyr.   r0   r   r2   r5   Úsetterr:   rC   rG   rQ   rS   rM   rU   rX   Ú__classcell__r   r   r6   r   r   $   s2   


	



,
		r   c                  O   s$   ddl m} t |¡ || i |¤ŽS )Nr   )Úadapt)Ztraits.adaptation.apir`   r   Ú_adapt)r   Úkwr`   r   r   r   Ú_adapt_wrapperý   s    
rc   )r\   r;   Ú r   Ú	constantsr   r   r   Zobservation.i_observabler   Z
trait_baser   r	   r&   r
   r(   r   r'   r   r   Úregisterr8   r   rc   Z_ctraitZ_list_classesra   r   r   r   r   Ú<module>   s     Y
