3
:Ad]{Æ  ã               @   sL  d Z ddlmZ ddlZddlmZmZ ddlZedƒZ	ddl
mZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZ dd
lmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z* ddddddddddœ	Z+da,i Z-i Z.da/da0da1da2da3dVdd„Z4dWdd„Z5dXdd„Z6dd„ Z7dd„ Z8dd „ Z9d!d"„ Z:d#d$„ Z;d%d&„ Z<d'd(„ Z=d)d*„ Z>G d+d,„ d,eƒZ?dd-l
mZ ej@e?ƒ e	eAe*eBeCeDejEfZFeDejEeAe*eBeCeGeHeIeeee	fZJejK�r dd.lmLZLmMZM eJddY… eLeMf eJd/d…  ZJeefZNee?fZOeDd0ejEd0eAde*e*dƒeBd1eCd2eGg eHf eIi ePdi
ZQeegZReGeIgZSd3d4„ ZTd5d6„ ZUG d7d8„ d8eVƒZWG d9d:„ d:eWƒZXi aYd;d<„ ZZd=d>„ Z[d?d@„ Z\dAdB„ Z]e]e_]G dCdD„ dDeVƒZ^G dEdF„ dFeVƒZ_dGdH„ Z`e`e_`G dIdJ„ dJeVƒZadZdKdL„ZbeWebƒZbG dMdN„ dNeVƒZci Zde?dOƒZedPdQ„ ZfeWefƒZfdRdS„ ZgeWegƒZgdTdU„ ZheWehƒZhdS )[a˜  
Defines the 'core' traits for the Traits package. A trait is a type definition
that can be used for normal Python object attributes, giving the attributes
some additional characteristics:

Initialization:
    Traits have predefined values that do not need to be explicitly
    initialized in the class constructor or elsewhere.
Validation:
    Trait attributes have flexible, type-checked values.
Delegation:
    Trait attributes' values can be delegated to other objects.
Notification:
    Trait attributes can automatically notify interested parties when
    their values change.
Visualization:
    Trait attributes can automatically construct (automatic or
    programmer-defined) user interfaces that allow their values to be
    edited or displayed)

.. note:: 'trait' is a synonym for 'property', but is used instead of the
    word 'property' to differentiate it from the Python language 'property'
    feature.
é    )Úabsolute_importN)ÚFunctionTypeÚ
MethodTypeé   )Útrait_handlers)ÚcTrait)Ú
TraitError)ÚSequenceTypesÚSelfÚ	UndefinedÚMissingÚ	TypeTypesÚadd_article)ÚTraitHandlerÚTraitInstanceÚTraitFunctionÚTraitCoerceTypeÚTraitCastTypeÚ	TraitEnumÚTraitCompoundÚTraitMapÚTraitStringÚ	ThisClassÚ	TraitTypeÚ
_arg_countÚ
_read_onlyÚ_write_onlyÚ_undefined_getÚ_undefined_setÚUNSPECIFIED_DEFAULT_VALUEÚCALLABLE_AND_ARGS_DEFAULT_VALUE)Ú	LONG_TYPEÚvalueÚselfÚlistÚdictÚfactoryÚmethod)	r   r   é   é   é   é   é   é   é   TFc             C   s&   t dkr"ddlm} |d| |d�a t S )z< Factory function that returns an editor for passwords.
    Nr   )Ú
TextEditorT)ÚpasswordÚauto_setÚ	enter_set)ÚPasswordEditorÚtraitsui.apir/   )r1   r2   r/   © r5   út/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traits-5.1.2-py3.6-linux-x86_64.egg/traits/traits.pyÚpassword_editor}   s
    r7   c             C   s:   | |ft kr.ddlm} |d| |d�t | |f< t | |f S )zI Factory function that returns a text editor for multi-line strings.
    r   )r/   T)Ú
multi_liner1   r2   )ÚMultilineTextEditorsr4   r/   )r1   r2   r/   r5   r5   r6   Úmulti_line_text_editorŒ   s
    r:   c             C   sŽ   |dk	r$t |tƒr$ddl}|j|ƒ}| ||ftkr€ddlm} |dkrXdd„ }dd„ }n|j}|j}|d||| |d�t| ||f< t| ||f S )	z< Factory function that returns a text editor for bytes.
    Nr   )r/   c             S   s   | j dƒjdƒS )NÚhexÚascii)ÚencodeÚdecode)Úbr5   r5   r6   Ú<lambda>§   s    zbytes_editor.<locals>.<lambda>c             S   s   | j dƒjdƒS )Nr<   r;   )r=   r>   )Úsr5   r5   r6   r@   ¨   s    T)r8   Zformat_funcÚevaluater1   r2   )	Ú
isinstanceÚstrÚcodecsÚlookupÚBytesEditorsr4   r/   r>   r=   )r1   r2   ÚencodingrE   r/   ÚformatrB   r5   r5   r6   Úbytes_editor™   s$    


rJ   c              C   s   t dkrddlm}  | ƒ a t S )za Factory function that returns an editor that treats a multi-line string
    as source code.
    Nr   )Ú
CodeEditor)ÚSourceCodeEditorr4   rK   )rK   r5   r5   r6   Úcode_editor¸   s    rM   c              C   s   t dkrddlm}  | ƒ a t S )za Factory function for an "editor" that displays a multi-line string as
    interpreted HTML.
    Nr   )Ú
HTMLEditor)ÚHTMLTextEditorr4   rN   )rN   r5   r5   r6   Úhtml_editorÆ   s    rP   c              C   s   t dkrddlm}  | ƒ a t S )zM Factory function that returns a Python shell for editing Python values.
    Nr   )ÚShellEditor)ÚPythonShellEditorr4   rQ   )rQ   r5   r5   r6   Úshell_editorÔ   s    rS   c               C   s   t dkrddlm a  t ƒ a t S )zJ Factory function that returns a Time editor for editing Time values.
    Nr   )Ú
TimeEditor)rT   r4   r5   r5   r5   r6   Útime_editorá   s    rU   c               C   s   t dkrddlm a  t ƒ a t S )zJ Factory function that returns a Date editor for editing Date values.
    Nr   )Ú
DateEditor)rV   r4   r5   r5   r5   r6   Údate_editorî   s    rW   c             C   sF   ddl m}m}m} t| |ƒr&| j}nt| |ƒr8| j}ndS t||ƒS )zH Does a trait handler or type expect a HasTraits subclass instance?
    r   )Ú	HasTraitsÚBaseInstancer   F)Ú
traits.apirX   rY   r   rC   ÚaClassÚklassÚ
issubclass)ÚhandlerrX   rY   r   Úclsr5   r5   r6   Ú_expects_hastraits_instanceû   s    

r`   c             C   sJ   ddl m}m} t| |ƒr | jS t| |ƒr0| jS d}t|jt| ƒƒƒ‚dS )z> Get the instance factory of an Instance or TraitInstance
    r   )rY   r   z;handler should be TraitInstance or BaseInstance, but got {}N)	rZ   rY   r   rC   r[   Údefault_valueÚ
ValueErrorrI   Úrepr)r^   rY   r   Úmsgr5   r5   r6   Ú_instance_handler_factory	  s    

re   c       
   
   C   s¢   |j j}t|ƒrdddlm} ddlm}m}m}m	} ddl
m} ||||gdd|ƒ dddt|ƒd�S dd	l
m}	 |	|| jr€| jnd
t| jƒ| jr–| jndd�S dS )z? Factory that constructs an appropriate editor for a list.
    r   )ÚObjectColumn)ÚEvalFilterTemplateÚRuleFilterTemplateÚMenuFilterTemplateÚEvalTableFilter)ÚTableEditorÚ ZverticalT)ÚfiltersZ	edit_viewÚorientationÚsearchZ	deletableZshow_toolbarZreorderableZrow_factory)Ú
ListEditorr+   )Ztrait_handlerÚrowsÚuse_notebookÚ	page_nameN)Z
item_traitr^   r`   Ztraitsui.table_columnrf   Ztraitsui.table_filterrg   rh   ri   rj   r4   rk   re   rp   rq   Úboolrr   rs   )
Útraitr^   Zitem_handlerrf   rg   rh   ri   rj   rk   rp   r5   r5   r6   Úlist_editor  s,    rv   c               @   sš   e Zd ZdZdd„ Zdd„ ZeeƒZdd„ ZeeƒZ	dd	„ Z
ee
ƒZd
d„ ZeeƒZdd„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚCTraitz1 Extends the underlying C-based cTrait type.
    c             O   sN   | j }t|tƒr2| jpi jƒ }|j|ƒ |||ŽS |jd| ƒ t|| f |ŽS )NÚparent)r^   rC   r   Ú__dict__ÚcopyÚupdateÚ
setdefaultÚTrait)r#   ÚargsÚmetadatar^   r%   r5   r5   r6   Ú__call__K  s    


zCTrait.__call__c             C   s@   | j ƒ \}}|dkrtS |d	kr(|jƒ S |d
kr<|d d … S |S )Nr(   r-   r.   r*   r,   r)   r+   )r(   r-   r.   )r*   r,   )r)   r+   )ra   r   rz   )r#   Úkindr"   r5   r5   r6   Z__get_defaultZ  s    zCTrait.__get_defaultc             C   s   t | jƒ d  S )Nr   )ÚKindMapra   )r#   r5   r5   r6   Z__get_default_kindi  s    zCTrait.__get_default_kindc             C   s&   | j }|d k	r|S ddlm} |S d S )Nr   )ÚAny)r^   Útrait_typesrƒ   )r#   r^   rƒ   r5   r5   r6   Z__get_trait_typen  s
    zCTrait.__get_trait_typec             C   s   | j }|d k	r|jƒ S f S )N)r^   Úinner_traits)r#   r^   r5   r5   r6   Z__get_inner_traitsy  s    zCTrait.__get_inner_traitsc             C   s   t | j|ƒS )zI Returns whether or not this trait is of a specified trait type.
        )rC   Ú
trait_type)r#   r†   r5   r5   r6   Úis_trait_type†  s    zCTrait.is_trait_typec             C   sÜ   ddl m} | j}|dkrJ| j}|dk	r2|j| ƒ}|dkrJddl m} |}t||ƒsÒf }i }t|ƒtkrÈx^|dd… D ]N}t|ƒtkr�t	|ƒ}qvt|t
ƒrÀ|}|jddƒdkrÄ|jƒ }| |d< qv|}qvW |||Ž}|| _|S )zF Returns the user interface editor associated with the trait.
        r   )ÚEditorFactoryN)r/   ru   )r4   rˆ   Úeditorr^   Ú
get_editorr/   rC   Útyper	   Útupler%   Úgetrz   )r#   rˆ   r‰   r^   r/   r~   ÚtraitsÚitemr5   r5   r6   rŠ   �  s2    





zCTrait.get_editorTc             C   sZ   |r| j }|dk	r|S | j}|dk	r2d|jƒ  }nd}| j}| jdkrN|jƒ S d||f S )aÐ   Returns the help text for a trait.

        Parameters
        ----------
        full : bool
            Indicates whether to return the value of the *help* attribute of
            the trait itself.

        Description
        -----------
        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.
        Nzmust be %s.zmay be any value.zSpecifies %s and %s)Úhelpr^   ÚinfoÚdescÚ
capitalize)r#   Úfullr�   r^   r‘   r’   r5   r5   r6   Úget_help¿  s    
zCTrait.get_helpc             C   s    | j }|dk	r|j|||ƒS dS )z- Returns a description of the trait.
        Nz	any value)r^   Ú	full_info)r#   ÚobjectÚnamer"   r^   r5   r5   r6   r–   ã  s    zCTrait.full_infoc             C   s   | j }|dk	r|jƒ S dS )z- Returns a description of the trait.
        Nz	any value)r^   r‘   )r#   r^   r5   r5   r6   r‘   ð  s    zCTrait.infoc             C   s   t | jdf| jƒ fS )Nr   )Ú
__newobj__Ú	__class__Ú__getstate__)r#   Úprotocolr5   r5   r6   Ú__reduce_ex__ý  s    zCTrait.__reduce_ex__c                sL   ‡ ‡fdd„}| j }|j}|dkr,i  |_}||tˆƒˆ f< |j|dƒ dS )z` Registers listeners on an assigned 'TraitValue' object's 'value'
            property.
        c                  s   ˆj ˆ d ƒ d S )N)Ztrait_property_changedr5   )r˜   r—   r5   r6   r^   
  s    z!CTrait._register.<locals>.handlerNr"   )Ú_trait_valueÚ	_handlersÚidÚon_trait_change)r#   r—   r˜   r^   ÚtvÚhandlersr5   )r˜   r—   r6   Ú	_register  s    
zCTrait._registerc             C   sD   | j }|j}t|ƒ|f}|j|ƒ}|dk	r@||= |j|ddd� dS )zb Unregisters listeners on an assigned 'TraitValue' object's 'value'
            property.
        Nr"   T)Úremove)rž   rŸ   r    r�   r¡   )r#   r—   r˜   r¢   r£   Úkeyr^   r5   r5   r6   Ú_unregister  s    
zCTrait._unregisterN)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r€   Z_CTrait__get_defaultÚpropertyÚdefaultZ_CTrait__get_default_kindZdefault_kindZ_CTrait__get_trait_typer†   Z_CTrait__get_inner_traitsr…   r‡   rŠ   r•   r–   r‘   r�   r¤   r§   r5   r5   r5   r6   rw   C  s$   		0
$rw   )Úctraits)ÚInstanceTypeÚ	ClassTyper(   rl   g        y                c             G   s   | j | f|žŽ S )z" Unpickles new-style objects.
    )Ú__new__)r_   r~   r5   r5   r6   r™   d  s    r™   c             C   s>   yt j| ƒd S    ytjt| ƒƒd S    dS Y nX d S )Nr   r)   r   )ÚDefaultValueSpecialÚindexÚDefaultValueTypesr‹   )ra   r5   r5   r6   Ú_default_value_typeo  s    rµ   c               @   s   e Zd Zddd„Zdd„ ZdS )ÚTraitFactoryNc             C   s   |d k	r|| _ |j| _d S )N)Úmaker_functionr«   )r#   r·   r5   r5   r6   Ú__init__…  s    zTraitFactory.__init__c             O   s   | j ||ŽS )N)r·   )r#   r~   r   r5   r5   r6   r€   Ž  s    zTraitFactory.__call__)N)r¨   r©   rª   r¸   r€   r5   r5   r5   r6   r¶   ~  s   
	r¶   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTraitImportErrorzŽ Defines a factory class for deferring import problems until encountering
        code that actually tries to use the unimportable trait.
    c             C   s
   || _ d S )N)Úmessage)r#   rº   r5   r5   r6   r¸   ›  s    zTraitImportError.__init__c             O   s   t | jƒ‚d S )N)r   rº   )r#   r~   r   r5   r5   r6   r€   ¢  s    zTraitImportError.__call__N)r¨   r©   rª   r«   r¸   r€   r5   r5   r5   r6   r¹   ’  s   r¹   c             C   s"   t | ƒ}|tkr| ƒ t|< t| S )N)r    Ú_trait_factory_instances)ru   Útidr5   r5   r6   Útrait_factory­  s    
r½   c             C   sT   t | tƒr| S t | tƒr t| ƒS t | tƒr>t| tƒr>| ƒ jƒ S t | tƒrP| jƒ S dS )zl Casts a CTrait, TraitFactory or TraitType to a CTrait but returns None
        if it is none of those.
    N)rC   rw   r¶   r½   r‹   r]   r   Ú	as_ctrait)Ú	somethingr5   r5   r6   Ú
trait_cast¼  s    



rÀ   c             C   s   t | ƒp
| S )z` Attempts to cast a value to a trait. Returns either a trait or the
        original value.
    )rÀ   )r¿   r5   r5   r6   Útry_trait_castÕ  s    rÁ   c             C   sp   ddl m} t| tƒr| S | dkr&|} t| tƒr8t| ƒS t| tƒrVt| tƒrV| ƒ j	ƒ S t| tƒrh| j	ƒ S t
| ƒS )z- Returns a trait derived from its input.
    r   )rƒ   N)r„   rƒ   rC   rw   r¶   r½   r‹   r]   r   r¾   r}   )r¿   rƒ   r5   r5   r6   Ú
trait_fromá  s    



rÂ   c               @   s   e Zd Zdd„ ZdS )Ú_InstanceArgsc             C   s   |f| | _ || _d S )N)r~   Úkw)r#   r&   r~   rÄ   r5   r5   r6   r¸   ÿ  s    z_InstanceArgs.__init__N)r¨   r©   rª   r¸   r5   r5   r5   r6   rÃ   þ  s   rÃ   c               @   s    e Zd ZdZdf dfdd„ZdS )ÚDefaultzÁ Generates a value the first time it is accessed.

    A Default object can be used anywhere a default trait value would normally
    be specified, to generate a default value dynamically.
    Nc             C   s   |||f| _ d S )N)ra   )r#   Úfuncr~   rÄ   r5   r5   r6   r¸     s    zDefault.__init__)r¨   r©   rª   r«   r¸   r5   r5   r5   r6   rÅ     s   rÅ   c              O   s   t | |Žjƒ S )aÍ   Creates a trait definition.

    Parameters
    ----------
    This function accepts a variety of forms of parameter lists:

    +-------------------+---------------+-------------------------------------+
    | Format            | Example       | Description                         |
    +===================+===============+=====================================+
    | Trait(*default*)  | Trait(150.0)  | The type of the trait is inferred   |
    |                   |               | from the type of the default value, |
    |                   |               | which must be in *ConstantTypes*.   |
    +-------------------+---------------+-------------------------------------+
    | Trait(*default*,  | Trait(None,   | The trait accepts any of the        |
    | *other1*,         | 0, 1, 2,      | enumerated values, with the first   |
    | *other2*, ...)    | 'many')       | value being the default value. The  |
    |                   |               | values must be of types in          |
    |                   |               | *ConstantTypes*, but they need not  |
    |                   |               | be of the same type. The *default*  |
    |                   |               | value is not valid for assignment   |
    |                   |               | unless it is repeated later in the  |
    |                   |               | list.                               |
    +-------------------+---------------+-------------------------------------+
    | Trait([*default*, | Trait([None,  | Similar to the previous format, but |
    | *other1*,         | 0, 1, 2,      | takes an explicit list or a list    |
    | *other2*, ...])   | 'many'])      | variable.                           |
    +-------------------+---------------+-------------------------------------+
    | Trait(*type*)     | Trait(Int)    | The *type* parameter must be a name |
    |                   |               | of a Python type (see               |
    |                   |               | *PythonTypes*). Assigned values     |
    |                   |               | must be of exactly the specified    |
    |                   |               | type; no casting or coercion is     |
    |                   |               | performed. The default value is the |
    |                   |               | appropriate form of zero, False,    |
    |                   |               | or emtpy string, set or sequence.   |
    +-------------------+---------------+-------------------------------------+
    | Trait(*class*)    |::             | Values must be instances of *class* |
    |                   |               | or of a subclass of *class*. The    |
    |                   | class MyClass:| default value is None, but None     |
    |                   |    pass       | cannot be assigned as a value.      |
    |                   | foo = Trait(  |                                     |
    |                   | MyClass)      |                                     |
    +-------------------+---------------+-------------------------------------+
    | Trait(None,       |::             | Similar to the previous format, but |
    | *class*)          |               | None *can* be assigned as a value.  |
    |                   | class MyClass:|                                     |
    |                   |   pass        |                                     |
    |                   | foo = Trait(  |                                     |
    |                   | None, MyClass)|                                     |
    +-------------------+---------------+-------------------------------------+
    | Trait(*instance*) |::             | Values must be instances of the     |
    |                   |               | same class as *instance*, or of a   |
    |                   | class MyClass:| subclass of that class. The         |
    |                   |    pass       | specified instance is the default   |
    |                   | i = MyClass() | value.                              |
    |                   | foo =         |                                     |
    |                   |   Trait(i)    |                                     |
    +-------------------+---------------+-------------------------------------+
    | Trait(*handler*)  | Trait(        | Assignment to this trait is         |
    |                   | TraitEnum )   | validated by an object derived from |
    |                   |               | **traits.TraitHandler**.            |
    +-------------------+---------------+-------------------------------------+
    | Trait(*default*,  | Trait(0.0, 0.0| This is the most general form of    |
    | { *type* |        | 'stuff',      | the function. The notation:         |
    | *constant* |      | TupleType)    | ``{...|...|...}+`` means a list of  |
    | *dict* | *class* ||               | one or more of any of the items     |
    | *function* |      |               | listed between the braces. Thus, the|
    | *handler* |       |               | most general form of the function   |
    | *trait* }+ )      |               | consists of a default value,        |
    |                   |               | followed by one or more of several  |
    |                   |               | possible items. A trait defined by  |
    |                   |               | multiple items is called a          |
    |                   |               | "compound" trait.                   |
    +-------------------+---------------+-------------------------------------+

    All forms of the Trait function accept both predefined and arbitrary
    keyword arguments. The value of each keyword argument becomes bound to the
    resulting trait object as the value of an attribute having the same name
    as the keyword. This feature lets you associate metadata with a trait.

    The following predefined keywords are accepted:

    Keywords
    --------
    desc : str
        Describes the intended meaning of the trait. It is used in
        exception messages and fly-over help in user interfaces.
    label : str
        Provides a human-readable name for the trait. It is used to label user
        interface editors for traits.
    editor : traits.api.Editor
        Instance of a subclass Editor object to use when creating a user
        interface editor for the trait. See the "Traits UI User Guide" for
        more information on trait editors.
    comparison_mode : int
        Indicates when trait change notifications should be generated based upon
        the result of comparing the old and new values of a trait assignment:

        * 0 (NO_COMPARE): The values are not compared and a trait change
          notification is generated on each assignment.
        * 1 (OBJECT_IDENTITY_COMPARE): A trait change notification is
          generated if the old and new values are not the same object.
        * 2 (RICH_COMPARE): A trait change notification is generated if the
          old and new values are not equal using Python's
          'rich comparison' operator. This is the default.

    rich_compare : bool
        Indicates whether the basis for considering a trait attribute value to
        have changed is a "rich" comparison (True, the default), or simple
        object identity (False). This attribute can be useful in cases
        where a detailed comparison of two objects is very expensive, or where
        you do not care whether the details of an object change, as long as the
        same object is used.

            .. deprecated:: 3.0.3
                Use ``comparison_mode`` instead


    )Ú_TraitMakerr¾   )Ú
value_typer   r5   r5   r6   r}     s    xr}   c               @   s>   e Zd ZdddœZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )rÇ   r(   r-   )ÚeventÚconstantc             O   s   |j ddƒ | j||Ž d S )Nr‹   ru   )r|   Údefine)r#   rÈ   r   r5   r5   r6   r¸   £  s    z_TraitMaker.__init__c          
   O   sZ  t }d  } }}t|ƒdk�r¬|d }|dd … }t|ƒdkrXt|ƒtkrX|d | }}t|ƒdk�rdt|ƒ}|tkrŠt|ƒ}tj|ƒ}nÖt	|t
ƒr°|}|jƒ \}}|j|d< n°t	|tƒrÄ|}d }nœ|tkrØtƒ }d }nˆt|ƒ}t	|tjƒ�r"| j|dddƒ}t|ƒdk�rt|ƒ}n
tf |Ž}n>|tk�r6t|ƒ}n*|jddƒ t|ƒ}||jk�r¬tj|ƒ}�nHg }	g }
i }| j||	||
ƒ t|	ƒdk�rÖ|	d d k�rÖt|
ƒdk�rÖt	|
d tƒ�rÖg }	|
d jƒ  |jddƒ t|	ƒdk�rt|ƒt|
ƒ dk�r||	k�r|	jd|ƒ |
jt|	ƒƒ t|ƒdk�r:|
jt|ƒƒ t|
ƒdk�rRtƒ }�nZt|
ƒdk�rH|
d }t	|t
ƒ�rŠ|d  }}|j|d< n¼t	|tƒ�r¬|jddƒ |d k�r¶|jƒ  n�t	|tƒ�rØt}|j|j |j!f}nnt|	ƒdk�r¬t|ƒdk�r¬|j}t|ƒ}|t"k�rt}|f |f}n*t	||ƒ�s¬|t#k	�r8|f}t}||d f}ndxbt$|
ƒD ]N\}}t	|t
ƒ�rR|jd	k�r„t%d
t&|jƒ ƒ‚|j'}|d k�r–P ||
|< �qRW t(|
ƒ}|| _'|| _)|dk �r@t	|t*ƒ�rÚt}|j}nf|d k�rô|d k	�rô|j'}|d k	�r.|j+}|dk �r.y|j,d d|ƒ}W n   Y nX |dk �r@t-|ƒ}|| _+|| _|j.ƒ | _/d S )Nr   r   r‹   Zmin_lenZmax_lenÚregexZinstance_handlerZ_instance_changed_handlerru   z2Cannot create a complex trait containing %s trait.rl   )0r   Úlenr‹   r	   rÁ   ÚPythonTypesr   ÚDefaultValuesr�   rC   rw   ra   r   r   ÚsixÚstring_typesÚextractr   r   r   r|   r   r[   Údo_listÚ
allow_noneÚinsertÚappendr   r   rÃ   r    Zcreate_default_valuer~   rÄ   r%   rŒ   Ú	enumerater   r   r^   r   ÚclonerÅ   Údefault_value_typeÚvalidaterµ   rz   r   )r#   rÈ   r   rÙ   ra   r^   rØ   Z	typeValueZstring_optionsÚenumÚotherÚmapr[   Úir�   r5   r5   r6   rË   «  sä    

















z_TraitMaker.definec             C   sÎ   xÈ|D ]À}|t kr"|jt|ƒƒ qt|ƒ}t|ƒ}|tkrF|j|ƒ q|tkr`| j||||ƒ q|tkrt|j	|ƒ q|t
krŒ|jt|ƒƒ q|tkr¢|jtƒ ƒ qt|tƒr¸|j|ƒ q|jt|ƒƒ qW d S )N)rÎ   rÖ   r   rÁ   r‹   ÚConstantTypesr	   rÓ   r%   r{   ÚCallableTypesr   r   rC   Ú
TraitTypesr   )r#   r$   rÛ   rÝ   rÜ   r�   ZtypeItemr5   r5   r6   rÓ   W  s$    

z_TraitMaker.do_listc       	      C   s>  | j }t| jj|jdƒdƒƒ}| j}|d k	rL|j|ƒ |jd k	rL|jjƒ |_|j| j| jƒ | j	}|d k	rº||_	t
|dd ƒ}|d krŠ|j}|j|ƒ t
|dd ƒ}|d k	rº||_|j|jƒ |jdƒ}|d k	rÚ|j|dkƒ |jdƒ}|d k	rö|j|ƒ |j|jdd	ƒdkƒ t|ƒdk�r:|jd k�r.||_n|jj|ƒ |S )
Nr‹   r   Zfast_validateÚpost_setattrÚrich_compareTÚcomparison_modeZtrait_valueF)r   rw   Útype_mapr�   rØ   ry   rz   ra   rÙ   r^   ÚgetattrrÚ   Zset_validaterâ   Z	is_mappedZrich_comparisonrä   Zvalue_allowedrÍ   r{   )	r#   r   ru   rØ   r^   rÚ   râ   rã   rä   r5   r5   r6   r¾   x  s>    





z_TraitMaker.as_ctraitc             G   s0   i }x&|D ]}||kr
|| ||< ||= q
W |S )Nr5   )r#   Z	from_dictÚkeysZto_dictr¦   r5   r5   r6   rÒ   ¨  s    

z_TraitMaker.extractN)	r¨   r©   rª   rå   r¸   rË   rÓ   r¾   rÒ   r5   r5   r5   r6   rÇ   š  s   
 -!0rÇ   c       	      K   sâ  d|d< | rÆ|dkrÆ| dk	|dk	 |dk	 }|dkrÆ|dkrFt |ƒS d}| dk	rV| }|dk	r†t|ƒ}|dk	r†|j }}|dk	r†|j}|dk	s–|dk	rÆd|krº|dk	rº|jdk	rº|j|d< t |||ƒS | dkrîd|d< |dkrèt} t}nt} n|dk�rt}d|d< |dk	�rVt|ƒ}|j}|dk�r6|dk	�r6|j}d|k�rV|jdk	�rV|j|d< |j	d	t
| d	dƒƒ |jd	ƒdk	�r”t
| d
dƒ�r”|j	ddƒ d}tdƒ}|jƒ |_|dk	�r¼t|ƒ}|j| t| ƒ|t|ƒ||ƒ ||_|S )a„   Returns a trait whose value is a Python property.

    Parameters
    ----------
    fget : function
        The "getter" function for the property.
    fset : function
        The "setter" function for the property.
    fvalidate : function
        The validation function for the property. The method should return the
        value to set or raise TraitError if the new value is not valid.
    force : bool
        Indicates whether to use only the function definitions specified by
        **fget** and **fset**, and not look elsewhere on the class.
    handler : function
        A trait handler function for the trait.
    trait : Trait or value
        A trait definition or a value that can be converted to a trait that
        constrains the values of the property trait.

    Description
    -----------
    If no getter, setter or validate functions are specified (and **force** is
    not True), it is assumed that they are defined elsewhere on the class whose
    attribute this trait is assigned to. For example::

        class Bar(HasTraits):

            # A float traits Property that should be always positive.
            foo = Property(Float)

            # Shadow trait attribute
            _foo = Float

            def _set_foo(self,x):
                self._foo = x

            def _validate_foo(self, x):
                if x <= 0:
                    raise TraitError(
                        'foo property should be a positive number')
                return x

            def _get_foo(self):
                return self._foo

    You can use the **depends_on** metadata attribute to indicate that the
    property depends on the value of another trait. The value of **depends_on**
    is an extended name specifier for traits that the property depends on. The
    property will a trait change notification if any of the traits specified
    by **depends_on** change. For example::

        class Wheel ( Part ):
            axle     = Instanced( Axle )
            position = Property( depends_on = 'axle.chassis.position' )

    For details of the extended trait name syntax, refer to the on_trait_change()
    method of the HasTraits class.
    r¬   r‹   Nr   r   r‰   TZ	transientZ
depends_onZcached_propertyFÚcachedr*   )ÚForwardPropertyrÀ   r^   rÚ   r‰   r   r   r   r   r|   ræ   r�   rw   rz   ry   r   r¬   )	ÚfgetÚfsetZ	fvalidateÚforcer^   ru   r   ÚsumÚnr5   r5   r6   ÚProperty¶  sb    D






rï   c               @   s   e Zd ZdZddd„ZdS )ré   zi Used to implement Property traits where accessor functions are defined
    implicitly on the class.
    Nc             C   s   |j ƒ | _|| _|| _d S )N)rz   r   rÚ   r^   )r#   r   rÚ   r^   r5   r5   r6   r¸   H  s    
zForwardProperty.__init__)NN)r¨   r©   rª   r«   r¸   r5   r5   r5   r6   ré   C  s   ré   r.   c              O   s   ddl m} || |ŽS )aË   Returns a trait whose value must be a GUI toolkit-specific color.

    Description
    -----------
    For wxPython, the returned trait accepts any of the following values:

    * A wx.Colour instance
    * A wx.ColourPtr instance
    * an integer whose hexadecimal form is 0x*RRGGBB*, where *RR* is the red
      value, *GG* is the green value, and *BB* is the blue value

    Default Value
    -------------
    For wxPython, 0xffffff (that is, white)
    r   )Ú
ColorTrait)Útraitsui.toolkit_traitsrð   )r~   r   rð   r5   r5   r6   ÚColort  s    rò   c              O   s   ddl m} || |ŽS )a^   Returns a trait whose value must be a GUI toolkit-specific RGB-based
        color.

    Description
    -----------
    For wxPython, the returned trait accepts any of the following values:

    * A tuple of the form (*r*, *g*, *b*), in which *r*, *g*, and *b* represent
      red, green, and blue values, respectively, and are floats in the range
      from 0.0 to 1.0
    * An integer whose hexadecimal form is 0x*RRGGBB*, where *RR* is the red
      value, *GG* is the green value, and *BB* is the blue value

    Default Value
    -------------
    For wxPython, (1.0, 1.0, 1.0) (that is, white)
    r   )ÚRGBColorTrait)rñ   ró   )r~   r   ró   r5   r5   r6   ÚRGBColorŒ  s    rô   c              O   s   ddl m} || |ŽS )až   Returns a trait whose value must be a GUI toolkit-specific font.

    Description
    -----------
    For wxPython, the returned trait accepts any of the following:

    * a wx.Font instance
    * a wx.FontPtr instance
    * a string describing the font, including one or more of the font family,
      size, weight, style, and typeface name.

    Default Value
    -------------
    For wxPython, 'Arial 10'
    r   )Ú	FontTrait)rñ   rõ   )r~   r   rõ   r5   r5   r6   ÚFont¦  s    rö   )TF)TF)TFNéþÿÿÿ)NNNFNN)ir«   Ú
__future__r   ÚsysÚtypesr   r   rÐ   r‹   ZNoneTyperl   r   r®   r   Ztrait_errorsr   Z
trait_baser	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    Z_py2to3r!   r‚   r3   r9   rG   rL   rO   rR   rV   rT   r7   r:   rJ   rM   rP   rS   rU   rW   r`   re   rv   rw   Z_ctraitÚintÚfloatÚcomplexrD   Ú	text_typerß   r$   rŒ   r%   rÎ   ÚPY2r¯   r°   rà   rá   rt   rÏ   r²   r´   r™   rµ   r—   r¶   r¹   r»   r½   rÀ   rÁ   rÂ   rÃ   rÅ   r}   rÇ   rï   ré   ZSpecialNamesZgeneric_traitrò   rô   rö   r5   r5   r5   r6   Ú<module>+   sØ    	P


, g
 	|       
 