3
8Ad].t  ã               @   sn  d Z ddl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 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 dd	lmZ dd
lmZmZ ddlZedƒZe
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)G d"d#„ d#e!ƒZ*G d$d%„ d%e!ƒZ+dS )&zg Defines the Group class used to represent a group of items used in a
    Traits-based user interface.
é    )Úabsolute_import)ÚBoolÚDelegateÚFloatÚInstanceÚListÚPropertyÚRangeÚReadOnlyÚStrÚ
TraitErrorÚcached_propertyé   )ÚViewSubElement)ÚItem)ÚInclude)ÚSequenceTypesÚContainerDelegateÚOrientationÚLayout)Ústr_find)Údock_window_themeÚDockWindowThemeNÚshadowé   z)amount of padding to add around each item)Údescc                   s*  e Zd ZdZeeƒZeZeZ	eZ
eZeZeZeZeedd�ZeZeZeZedƒZeddƒZedƒZedƒZedƒZedƒZedƒZ eZ!eZ"eZ#eZ$e%Z&e'e(dd�Z)e'e(dd�Z*‡ fd	d
„Z+dd„ Z,dd„ Z-dd„ Z.dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4dd„ Z5e6dd „ ƒZ7e6d!d"„ ƒZ8‡  Z9S )#ÚGroupz> Represents a grouping of items in a user interface view.
    F)Ú
allow_noner   é2   TÚcontent)Z
depends_onc                s  t t| ƒjf |Ž | j}x2|D ]*}t|tjƒr|dd… dkr| j|ƒ qW x´|D ]¬}t|tƒrl|j|ƒ qRt	|ƒt
krˆ|jt|Ž ƒ qRt|tjƒrò|dd… dkr¦nJ|dd… dkrâ|dd… dkrâ|jt|dd	… jƒ ƒƒ n|jt|ƒƒ qRtd| ƒ‚qRW | jƒ  dS )
z' Initializes the group object.
        r   r   z-|Nú<ú>zUnrecognized argument type: %séÿÿÿÿr"   )Úsuperr   Ú__init__r   Ú
isinstanceÚsixÚstring_typesÚ_parseÚappendÚtyper   r   r   Ústripr   Ú	TypeErrorÚset_container)ÚselfÚvaluesÚtraitsr   Úvalue)Ú	__class__© új/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/group.pyr$   Å   s$    


 zGroup.__init__c             C   s   t ƒ S )N)r   )r.   r3   r3   r4   Ú_dock_theme_defaultë   s    zGroup._dock_theme_defaultc             C   s   | j dkr| j S dS )z+ Gets the label to use this group.
        Ú r   )Úlabel)r.   Úuir3   r3   r4   Ú	get_labelò   s    
zGroup.get_labelc             C   s
   | j dkS )zk Returns a Boolean value indicating whether the object is replacable
        by an Include object.
        r6   )Úid)r.   r3   r3   r4   Úis_includableþ   s    zGroup.is_includablec             C   sb   x\t | jƒD ]N\}}|jƒ rP|j}||jkr8td| ƒ‚t|ƒ| j|< ||j|< |j|ƒ qW dS )aJ   Replaces any items that have an **id** attribute with an Include
        object with the same ID value, and puts the object with the ID
        into the specified ViewElements object.

        Parameters
        ----------
        view_elements : ViewElements object
            A set of Group, Item, and Include objects
        z*Duplicate definition for view element '%s'N)Ú	enumerater   r;   r:   r   r   Úreplace_include)r.   Zview_elementsÚiÚitemr:   r3   r3   r4   r=   
  s    



zGroup.replace_includec             C   s¢   g }d}|j ƒ }x‚| jD ]x}xt|tƒr4|j|ƒ}qW t|tƒrf| j||ƒr†|j|j|ƒƒ |d7 }n t|t	ƒr†| j||ƒr†|j|ƒ |j
|ƒ qW t| ||d�S )zÜ Returns a ShadowGroup object for the current Group object, which
        recursively resolves all embedded Include objects and which replaces
        each embedded Group object with a corresponding ShadowGroup.
        r   r   )r   r   Úgroups)Z
push_levelr   r%   r   Úfindr   Ú_defined_whenr)   Ú
get_shadowr   Z	pop_levelÚShadowGroup)r.   r8   r   r@   Úlevelr1   r3   r3   r4   rC   $  s    



zGroup.get_shadowc             C   s   x| j D ]
}| |_qW dS )z5 Sets the correct container for the content.
        N)r   Ú	container)r.   r?   r3   r3   r4   r-   E  s    zGroup.set_containerc             C   s   |j dkrdS |j|j ƒS )z= Should the object be defined in the user interface?
        r6   T)Údefined_whenZ	eval_when)r.   r8   r1   r3   r3   r4   rB   O  s    
zGroup._defined_whenc             C   sÞ   d | _  | _| _| j|ƒ\}}| j|ƒ}| j|dddƒ}| j|dddƒ}| j|ddd	ƒ}| j|d
ddƒ}| j|dddƒ}| j|dddƒ}| j|dddƒ}| jo¤| j }| j | _|| _| jd|dtddƒ}|dkrÚ|| _dS )z5 Parses Group options specified as a string.
        Fú-ÚorientationÚ
horizontalú|Úverticalú=ÚlayoutÚsplitú^Útabbedr!   Úshow_labelsTr    Ú	show_leftú!Úselectedr:   ú:r   r   r6   N)	Úshow_borderrR   rS   Z_parse_labelZ_parse_styleZ_optionÚ_splitr   Úobject)r.   r1   ÚemptyrR   r3   r3   r4   r(   Z  s     

zGroup._parsec             C   s
   d| _ dS )z? Handles a label being found in the string definition.
        TN)rW   )r.   r3   r3   r4   Ú_parsed_labely  s    zGroup._parsed_labelc             C   s˜   g }dj dd„ | jD ƒƒ}t|ƒdkr0|j|ƒ | jddddd	d
dddddƒ}|dk	r`|j|ƒ dj |ƒ}t|ƒdkr‚| jjd S d| jj| j|ƒf S )z8 Returns a "pretty print" version of the Group.
        z,
c             S   s   g | ]}|j ƒ ‘qS r3   )Ú__repr__)Ú.0r?   r3   r3   r4   ú
<listcomp>†  s    z"Group.__repr__.<locals>.<listcomp>r   rI   rW   rR   rS   rU   r:   rY   r7   ÚstylerN   Ústyle_sheetNz()z%s(
%s
))Újoinr   Úlenr)   Z_repr_optionsr2   Ú__name__Ú_indent)r.   ÚresultÚitemsÚoptionsr   r3   r3   r4   r\   ‚  s.    


zGroup.__repr__c             C   sZ   d}xD| j D ]:}|jdkr| jdkr0||j7 }q| jdkrt||jƒ}qW |dkrVd}|S )z3 Returns the requested width of the Group.
        g        r   rJ   rL   r   g      ð?g      ð¿)r   ÚwidthrI   Úmax)r.   rh   r?   r3   r3   r4   Ú
_get_width¤  s    


zGroup._get_widthc             C   sZ   d}xD| j D ]:}|jdkr| jdkr2t||jƒ}q| jdkr||j7 }qW |dkrVd}|S )z4 Returns the requested height of the Group.
        g        r   rJ   rL   r   g      ð?g      ð¿)r   ÚheightrI   ri   )r.   rk   r?   r3   r3   r4   Ú_get_heightµ  s    


zGroup._get_height):rc   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r:   r7   r`   r   rY   r_   ÚdockÚimager   r   Ú
dock_themeÚexportr   rI   r   rN   r   Ú
scrollabler	   ÚcolumnsrW   rR   rS   rU   ÚspringyÚhelprG   Úvisible_whenÚenabled_whenÚPaddingÚpaddingr   r   rh   rk   r$   r5   r9   r;   r=   rC   r-   rB   r(   r[   r\   r   rj   rl   Ú__classcell__r3   r3   )r2   r4   r   ;   sP   
	&!
	"r   c               @   s   e Zd ZdZdZdS )ÚHGroupz4 A group whose items are laid out horizontally.
    rJ   N)rc   rm   rn   ro   rI   r3   r3   r3   r4   r}   Ë  s   r}   c               @   s   e Zd ZdZdZdS )ÚVGroupz2 A group whose items are laid out vertically.
    rL   N)rc   rm   rn   ro   rI   r3   r3   r3   r4   r~   Ü  s   r~   c               @   s   e Zd ZdZdZdS )ÚVGridz4 A group whose items are laid out in 2 columns.
    é   N)rc   rm   rn   ro   ru   r3   r3   r3   r4   r   í  s   r   c               @   s   e Zd ZdZdZdZdS )ÚHFlowzx A group in which items are laid out horizontally, and "wrap" when
    they exceed the available horizontal space..
    ÚflowFN)rc   rm   rn   ro   rN   rR   r3   r3   r3   r4   r�   ý  s   r�   c               @   s   e Zd ZdZdZdZdS )ÚVFlowzs A group in which items are laid out vertically, and "wrap" when they
    exceed the available vertical space.
    r‚   FN)rc   rm   rn   ro   rN   rR   r3   r3   r3   r4   rƒ     s   rƒ   c               @   s   e Zd ZdZdZdZdS )ÚVFoldzz A group in which items are laid out vertically and can be collapsed
        (i.e. 'folded') by clicking their title.
    ÚfoldFN)rc   rm   rn   ro   rN   rR   r3   r3   r3   r4   r„   "  s   r„   c               @   s   e Zd ZdZdZdZdS )ÚHSplitzM A horizontal group with splitter bars to separate it from other groups.
    rO   rJ   N)rc   rm   rn   ro   rN   rI   r3   r3   r3   r4   r†   5  s   r†   c               @   s   e Zd ZdZdZdZdS )ÚVSplitzK A vertical group with splitter bars to separate it from other groups.
    rO   rL   N)rc   rm   rn   ro   rN   rI   r3   r3   r3   r4   r‡   G  s   r‡   c               @   s   e Zd ZdZdZdZdS )ÚTabbedz1 A group that is shown as a tabbed notebook.
    rQ   TN)rc   rm   rn   ro   rN   rv   r3   r3   r3   r4   rˆ   Y  s   rˆ   c                   s®   e Zd ZdZ‡ fdd„ZeZeZeZ	eZ
eZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZddd„Z dd„ Z!d	d
„ Z"dd„ Z#dd„ Z$‡  Z%S )rD   z· Corresponds to a Group object, but with all embedded Include
        objects resolved, and with all embedded Group objects replaced by
        corresponding ShadowGroup objects.
    c                s   || _ tt| ƒjf |Ž d S )N)r   r#   rD   r$   )r.   r   r0   )r2   r3   r4   r$   q  s    zShadowGroup.__init__Tc             C   sä   | j dd… }| jdkrà|svd}x¾|t|ƒk rr|| }t|tƒrh|jdƒ}||||d …< |t|ƒ7 }q"|d7 }q"W nj| jt|ƒkrà| jdkràg }g }x8|D ]0}t|tƒrÂ| j||ƒ |j|ƒ qœ|j|ƒ qœW | j||ƒ |}|S )a*   Returns the contents of the Group within a specified context for
        building a user interface.

        This method makes sure that all Group types are of the same type (i.e.,
        Group or Item) and that all Include objects have been replaced by their
        substituted values.
        Nr   Fr   Únormal)	r   r@   rb   r%   rD   Úget_contentrN   Ú_flush_itemsr)   )r.   Zallow_groupsre   r>   r1   rf   r   r?   r3   r3   r4   rŠ   Î  s,    	




zShadowGroup.get_contentc             C   s(   | j dkr| j S djdd„ | jƒ D ƒƒS )z& Returns an ID for the group.
        r6   rV   c             S   s   g | ]}|j ƒ ‘qS r3   )Úget_id)r]   r?   r3   r3   r4   r^   ÿ  s    z&ShadowGroup.get_id.<locals>.<listcomp>)r:   ra   rŠ   )r.   r3   r3   r4   rŒ   ù  s    
zShadowGroup.get_idc             C   s   dS )z5 Sets the correct container for the content.
        Nr3   )r.   r3   r3   r4   r-     s    zShadowGroup.set_containerc             C   sJ   t |ƒdkrF|jt| jd�jddd|| j| j| j| jd�ƒ |dd…= dS )zJ Creates a sub-group for any items contained in a specified list.
        r   )r   r6   F)r@   r7   rW   r   rR   rS   rv   rI   N)	rb   r)   rD   r   Z	trait_setrR   rS   rv   rI   )r.   r   rf   r3   r3   r4   r‹     s    zShadowGroup._flush_itemsc             C   s
   t | jƒS )z8 Returns a "pretty print" version of the Group.
        )Úreprr   )r.   r3   r3   r4   r\   $  s    zShadowGroup.__repr__)T)&rc   rm   rn   ro   r$   r
   r   r@   ÚShadowDelegater:   r7   rY   r_   rp   rq   rr   rs   rI   rN   rt   ru   rW   rR   rS   rU   rv   rw   rG   rx   ry   r{   r`   rŠ   rŒ   r-   r‹   r\   r|   r3   r3   )r2   r4   rD   k  s@   	
+	rD   ),ro   Ú
__future__r   Z
traits.apir   r   r   r   r   r   r	   r
   r   r   r   Zview_elementr   r?   r   Úincluder   Z	ui_traitsr   r   r   r   Úutilr   r   r   r&   rŽ   rz   r   r}   r~   r   r�   rƒ   r„   r†   r‡   rˆ   rD   r3   r3   r3   r4   Ú<module>   s2   4   