3
8Ad]U  ã               @   s|  d Z ddlmZ ddlZddl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lmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlZejdƒZejdejejB ƒZ ejdejejB ƒZ!e
edd�Z"ed%dddd�Z#G dd„ deƒZ$G dd„ de$ƒZ%G dd„ de$ƒZ&G dd„ de&ƒZ'G dd„ de$ƒZ(G dd„ de(ƒZ)G dd „ d e$ƒZ*G d!d"„ d"e*ƒZ+G d#d$„ d$e$ƒZ,e,ƒ Z-dS )&zl Defines the Item class, which is used to represent a single item within
    a Traits-based user interface.
é    )Úabsolute_importN)
ÚBoolÚCallableÚConstantÚDelegateÚFloatÚInstanceÚRangeÚStrÚ	UndefinedÚDict)Úuser_name_foré   )ÚViewSubElement)ÚContainerDelegateÚEditorStyle)Ústr_findÚ	str_rfind)ÚEditorFactoryz\d+z^(.*)<(.*)>(.*)$z^(.*)`(.*)`(.*)$T)Ú
allow_noneé   z$amount of padding to add around item)Údescc                   sü   e Zd ZdZeZeZeZeZeZ	e
Ze
Ze
Ze
Ze
ZeddƒZeZeZeeƒZedƒZeeƒZedƒZedƒZeZeZeZe Z!eZ"e#Z$eZ%e&dƒZ'e&dƒZ(eZ)d‡ fdd„	Z*d	d
„ Z+dd„ Z,dd„ Z-dd„ Z.dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3‡  Z4S )ÚItemaÊ   An element in a Traits-based user interface.

    Magic:

    - Items are rendered as layout elements if :attr:`name` is set to
      special values:

      * ``name=''``, the item is rendered as a static label

      * ``name='_'``, the item is rendered as a separator

      * ``name=' '``, the item is rendered as a 5 pixel spacer

      * ``name='23'`` (any number), the item is rendered as a spacer of
        the size specified (number of pixels)
    Ú	containerZshow_labelsFg      ð?Nc                sÂ   t t| ƒjf |Ž |dkrdS t|tjƒs2tdƒ‚| j|ƒ\}}|rJd| _| j	|ƒ}| j
|ƒ}| j|ƒ}| j|dddƒ}| j|dddƒ}| jd	|d
tddƒ}| jd|dtddƒ}|dkr¾|| _dS )z& Initializes the item object.
        Nz�The argument to Item must be a string of the form: [id:][object.[object.]*][name]['['label']']`tooltip`[<width[,height]>][#^][$|@|*|~|;style]Fú#Ú	resizableTú^Ú
emphasizedÚidú:r   r   ÚobjectÚ.Ú )Úsuperr   Ú__init__Ú
isinstanceÚsixÚstring_typesÚ	TypeErrorZ_parse_labelÚ
show_labelZ_parse_styleÚ_parse_sizeÚ_parse_tooltipZ_optionÚ_splitr   r   Úname)ÚselfÚvalueÚtraitsÚempty)Ú	__class__© úi/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/item.pyr$   
  s$    


zItem.__init__c             C   s
   | j dkS )zj Returns a Boolean indicating whether the object is replaceable by an
            Include object.
        r"   )r   )r.   r3   r3   r4   Úis_includable+  s    zItem.is_includablec             C   s(   | j jƒ }|dkp&|dkp&tj|ƒdk	S )zD Returns True if the item represents a spacer or separator.
        r"   Ú_N)r-   ÚstripÚ
all_digitsÚmatch)r.   r-   r3   r3   r4   Ú	is_spacer5  s    
zItem.is_spacerc             C   s>   | j ƒ rdS | jdkr| jS t| jtƒ |jƒ}|j| jƒjƒ S )zH Gets the help text associated with the Item in a specified UI.
        Nr"   )	r:   ÚhelpÚevalÚobject_ÚglobalsÚcontextÚ
base_traitr-   Úget_help)r.   Úuir    r3   r3   r4   rA   A  s    
zItem.get_helpc             C   sÆ   | j ƒ rdS | j}|dkr|S | j}t| jtƒ |jƒ}|j|ƒ}t|ƒ}|j}|dkrZ|S t	|t
jƒrº|dd… dkr†||dd…  S |dd… dkr¦|dd… | S | jdkr¶| jS |S ||||ƒS )aA   Gets the label to use for a specified Item.

        If not specified, the label is set as the name of the
        corresponding trait, replacing '_' with ' ', and capitalizing
        the first letter (see :func:`user_name_for`). This is called
        the *user name*.

        Magic:

        - if attr:`item.label` is specified, and it begins with '...',
          the final label is the user name followed by the item label
        - if attr:`item.label` is specified, and it ends with '...',
          the final label is the item label followed by the user name
        Nr"   r   é   z...éýÿÿÿrD   )r:   Úlabelr-   r<   r=   r>   r?   r@   r   r%   r&   r'   )r.   rB   rE   r-   r    ZtraitZtlabelr3   r3   r4   Ú	get_labelT  s*    

zItem.get_labelc             C   s   | j dkr| j S | jS )z2 Returns an ID used to identify the item.
        r"   )r   r-   )r.   r3   r3   r4   Úget_id‚  s    
zItem.get_idc             C   s€   t j|ƒ}|dk	r||jdƒ}|jdƒ|jdƒ }|jdƒ}|dk rP| jd|ƒ n,| jd|d|… ƒ | jd||d d… ƒ |S )	zE Parses a '<width,height>' value from the string definition.
        Né   r   rC   ú,r   ÚwidthÚheight)Úsize_patr9   ÚgroupÚfindÚ
_set_float)r.   r/   r9   ÚdataÚcolr3   r3   r4   r*   Ž  s    


zItem._parse_sizec             C   s6   t j|ƒ}|dk	r2|jdƒ| _|jdƒ|jdƒ }|S )z> Parses a *tooltip* value from the string definition.
        NrH   r   rC   )Útooltip_patr9   rM   Útooltip)r.   r/   r9   r3   r3   r4   r+   ¢  s
    
zItem._parse_tooltipc             C   s$   |j ƒ }|dkr t| |t|ƒƒ dS )zL Sets a specified trait to a specified string converted to a float.
        r"   N)r7   ÚsetattrÚfloat)r.   r-   r/   r3   r3   r4   rO   °  s    zItem._set_floatc             C   s>   | j dddddddƒ}|dkr(d	| j S d
| j| j|dƒf S )z7 Returns a "pretty print" version of the Item.
        r   r    rE   Ústyler)   rJ   rK   NzItem( '%s' )zItem( '%s'
%s
)z      )Z_repr_optionsr-   Ú_indent)r.   Úoptionsr3   r3   r4   Ú__repr__»  s    

zItem.__repr__g      ð¿g      ð¿)N)5Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   rE   r-   Zstyle_sheetr;   r   r    rV   ZdockÚimageZexportr   r)   Ú
ItemEditorÚeditorr   Zeditor_argsr   r   r   ÚspringyZ	full_sizer   Z	has_focusZdefined_whenZvisible_whenZenabled_whenÚPaddingÚpaddingrS   r   Zformat_funcZ
format_strr   rJ   rK   Úinvalidr$   r5   r:   rA   rF   rG   r*   r+   rO   rY   Ú__classcell__r3   r3   )r2   r4   r   H   sN   
		!
.r   c               @   s   e Zd ZdZedƒZdS )ÚUItemz  An Item that has no label.
    FN)rZ   r[   r\   r]   r   r)   r3   r3   r3   r4   rf   Ì  s   rf   c               @   s   e Zd ZdZedƒZdS )ÚCustomz% An Item using a 'custom' style.
    ÚcustomN)rZ   r[   r\   r]   r   rV   r3   r3   r3   r4   rg   ×  s   rg   c               @   s   e Zd ZdZedƒZdS )ÚUCustomz3 An Item using a 'custom' style with no label.
    FN)rZ   r[   r\   r]   r   r)   r3   r3   r3   r4   ri   â  s   ri   c               @   s   e Zd ZdZedƒZdS )ÚReadonlyz' An Item using a 'readonly' style.
    ÚreadonlyN)rZ   r[   r\   r]   r   rV   r3   r3   r3   r4   rj   í  s   rj   c               @   s   e Zd ZdZedƒZdS )Ú	UReadonlyz5 An Item using a 'readonly' style with no label.
    FN)rZ   r[   r\   r]   r   r)   r3   r3   r3   r4   rl   ø  s   rl   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚLabelz An item that is a label.
    c                s   t t| ƒjf d|i|—Ž d S )NrE   )r#   rm   r$   )r.   rE   r0   )r2   r3   r4   r$     s    zLabel.__init__)rZ   r[   r\   r]   r$   re   r3   r3   )r2   r4   rm     s   rm   c               @   s   e Zd ZdZedƒZdS )ÚHeadingz$ An item that is a fancy label.
    rh   N)rZ   r[   r\   r]   r   rV   r3   r3   r3   r4   rn     s   rn   c               @   s*   e Zd ZdZdZedƒZedf ƒZdZ	dS )ÚSpringz( An item that is a layout "spring".
    Ztrait_modifiedFztraitsui.api.NullEditorTN)
rZ   r[   r\   r]   r-   r   r)   r   r`   ra   r3   r3   r3   r4   ro   "  s
   
ro   iñÿÿÿ).r]   Ú
__future__r   ÚreZ
traits.apir   r   r   r   r   r   r	   r
   r   r   Ztraits.trait_baser   Zview_elementr   Z	ui_traitsr   r   Úutilr   r   Zeditor_factoryr   r&   Úcompiler8   Ú	MULTILINEÚDOTALLrL   rR   r_   rb   r   rf   rg   ri   rj   rl   rm   rn   ro   Zspringr3   r3   r3   r4   Ú<module>   s6   0
   