a
    §ˆcAK  ã                   @   sX  d 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 e d	¡Ze d
ejejB ¡Ze 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.
é    N)
ÚBoolÚCallableÚConstantÚDelegateÚFloatÚInstanceÚRangeÚStrÚ	UndefinedÚDict)Úuser_name_foré   )ÚViewSubElement)ÚContainerDelegateÚEditorStyle)ÚEditorFactoryz\d+z^(.*)<(.*)>(.*)$z^(.*)`(.*)`(.*)$T)Ú
allow_noneiñÿÿÿé   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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„ Z/dd„ Z0dd„ Z1dd„ Z2‡  Z3S )Ú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 ƒ jf i |¤Ž |du rdS t|tƒs0tdƒ‚|  |¡\}}|rHd| _|  |¡}|  |¡}|  	|¡}|  
|ddd¡}|  
|ddd¡}|  d	|d
tjdd¡}|  d|dtj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Ú.Ú )ÚsuperÚ__init__Ú
isinstanceÚstrÚ	TypeErrorZ_parse_labelÚ
show_labelZ_parse_styleÚ_parse_sizeÚ_parse_tooltipZ_optionÚ_splitÚfindÚrfindÚname)ÚselfÚvalueÚtraitsÚempty©Ú	__class__© úP/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/item.pyr!     s&    
ÿ


zItem.__init__c                 C   s
   | j dkS )zeReturns a Boolean indicating whether the object is replaceable by an
        Include object.
        r   )r   ©r,   r2   r2   r3   Úis_includable!  s    zItem.is_includablec                 C   s(   | j  ¡ }|dkp&|dkp&t |¡duS )z:Returns True if the item represents a spacer or separator.r   Ú_N)r+   ÚstripÚ
all_digitsÚmatch)r,   r+   r2   r2   r3   Ú	is_spacer'  s    
ÿýzItem.is_spacerc                 C   s>   |   ¡ rdS | jdkr| jS t| jtƒ |jƒ}| | j¡ ¡ S )z>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   r2   r2   r3   rA   1  s    
zItem.get_helpc                 C   sÄ   |   ¡ rdS | j}|dkr|S | j}t| jtƒ |jƒ}| |¡}t|ƒ}|j}|du rZ|S t	|t
ƒ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 )a@  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...éýÿÿÿ)r:   Úlabelr+   r<   r=   r>   r?   r@   r   r"   r#   )r,   rB   rE   r+   r   ZtraitZtlabelr2   r2   r3   Ú	get_label?  s*    


zItem.get_labelc                 C   s   | j dkr| j S | jS )z(Returns an ID used to identify the item.r   )r   r+   r4   r2   r2   r3   Úget_idi  s    
zItem.get_idc                 C   s€   t  |¡}|dur|| d¡}| d¡| d¡ }| d¡}|dk rP|  d|¡ n,|  d|d|… ¡ |  d||d d… ¡ |S )	z;Parses a '<width,height>' value from the string definition.Né   r   rC   ú,r   ÚwidthÚheight)Úsize_patr9   Úgroupr)   Ú
_set_float)r,   r-   r9   ÚdataÚcolr2   r2   r3   r&   p  s    


zItem._parse_sizec                 C   s6   t  |¡}|dur2| d¡| _| d¡| d¡ }|S )z4Parses a *tooltip* value from the string definition.NrH   r   rC   )Útooltip_patr9   rM   Útooltip)r,   r-   r9   r2   r2   r3   r'     s
    
zItem._parse_tooltipc                 C   s$   |  ¡ }|dkr t| |t|ƒƒ dS )zBSets a specified trait to a specified string converted to a float.r   N)r7   ÚsetattrÚfloat)r,   r+   r-   r2   r2   r3   rN   ˆ  s    zItem._set_floatc              	   C   s>   |   ddddddd¡}|du r(d	| j S d
| j|  |d¡f S )z-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,   Úoptionsr2   r2   r3   Ú__repr__Ž  s    ÿ

þzItem.__repr__)N)4Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   rE   r+   Zstyle_sheetr;   r   r   rU   ZdockÚimageÚexportr   r%   Ú
ItemEditorÚeditorr   Zeditor_argsr   r
   r   Úspringyr   Z	has_focusZdefined_whenZvisible_whenZenabled_whenÚPaddingÚpaddingrR   r   Zformat_funcZ
format_strr   rJ   rK   Úinvalidr!   r5   r:   rA   rF   rG   r&   r'   rN   rX   Ú__classcell__r2   r2   r0   r3   r   @   sL   
		
*	r   c                   @   s   e Zd ZdZedƒZdS )ÚUItemzAn Item that has no label.FN©rY   rZ   r[   r\   r   r%   r2   r2   r2   r3   rf   ¢  s   rf   c                   @   s   e Zd ZdZedƒZdS )ÚCustomzAn Item using a 'custom' style.ÚcustomN©rY   rZ   r[   r\   r   rU   r2   r2   r2   r3   rh   ­  s   rh   c                   @   s   e Zd ZdZedƒZdS )ÚUCustomz-An Item using a 'custom' style with no label.FNrg   r2   r2   r2   r3   rk   ¸  s   rk   c                   @   s   e Zd ZdZedƒZdS )ÚReadonlyz!An Item using a 'readonly' style.ÚreadonlyNrj   r2   r2   r2   r3   rl   Ã  s   rl   c                   @   s   e Zd ZdZedƒZdS )Ú	UReadonlyz/An Item using a 'readonly' style with no label.FNrg   r2   r2   r2   r3   rn   Î  s   rn   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚLabelzAn item that is a label.c                    s   t ƒ jf d|i|¤Ž d S )NrE   )r    r!   )r,   rE   r.   r0   r2   r3   r!   Ü  s    zLabel.__init__)rY   rZ   r[   r\   r!   re   r2   r2   r0   r3   ro   Ù  s   ro   c                   @   s   e Zd ZdZedƒZdS )ÚHeadingzAn item that is a fancy label.ri   N)rY   rZ   r[   r\   r   rU   r2   r2   r2   r3   rp   å  s   rp   c                   @   s*   e Zd ZdZdZedƒZeddƒZdZ	dS )ÚSpringz"An item that is a layout "spring".Ztrait_modifiedFztraitsui.api.NullEditorr2   TN)
rY   rZ   r[   r\   r+   r   r%   r   r`   ra   r2   r2   r2   r3   rq   ñ  s
   
rq   )(r\   ÚreZ
traits.apir   r   r   r   r   r   r   r	   r
   r   Ztraits.trait_baser   Zview_elementr   Z	ui_traitsr   r   Zeditor_factoryr   Úcompiler8   Ú	MULTILINEÚDOTALLrL   rQ   r_   rb   r   rf   rh   rk   rl   rn   ro   rp   rq   Zspringr2   r2   r2   r3   Ú<module>   s.   0
  d