a
    §ˆc­_  ã                   @   sN  d 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m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.
é    )ÚBoolÚDelegateÚFloatÚInstanceÚListÚPropertyÚRangeÚReadOnlyÚStrÚ
TraitErrorÚcached_propertyé   )ÚViewSubElement)ÚItem)ÚInclude)ÚSequenceTypesÚContainerDelegateÚOrientationÚLayout)Údock_window_themeÚDockWindowThemeÚshadowé   z)amount of padding to add around each item)Údescc                       s8  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 )#ÚGroupz8Represents a grouping of items in a user interface view.F)Ú
allow_noner   é2   TÚcontent)Zobservec                    s  t ƒ jf i |¤Ž | j}|D ](}t|tƒr|dd… dv r|  |¡ q|D ]ª}t|tƒrd| |¡ qJt|ƒt	v r€| t
|Ž ¡ qJt|tƒrè|dd… dv rœqô|dd… dkrØ|dd… dkrØ| t|dd…  ¡ ƒ¡ qô| t|ƒ¡ qJtd| ƒ‚qJ|  ¡  dS )	zInitializes the group object.r   r   z-|Nú<éÿÿÿÿú>zUnrecognized argument type: %s)ÚsuperÚ__init__r   Ú
isinstanceÚstrÚ_parser   ÚappendÚtyper   r   r   Ústripr   Ú	TypeErrorÚset_container)ÚselfÚvaluesÚtraitsr   Úvalue©Ú	__class__© úQ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/group.pyr"   Ä   s$    

 zGroup.__init__c                 C   s   t ƒ S ©N)r   ©r+   r1   r1   r2   Ú_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+   Úuir1   r1   r2   Ú	get_labelì   s    
zGroup.get_labelc                 C   s
   | j dkS )zjReturns a Boolean value indicating whether the object is replacable
        by an Include object.
        r6   )Úidr4   r1   r1   r2   Úis_includableó   s    zGroup.is_includablec                 C   s^   t | jƒD ]N\}}| ¡ rN|j}||jv r6td| ƒ‚t|ƒ| j|< ||j|< | |¡ q
dS )aI  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:   r1   r1   r2   r=   ù   s    

ÿ
zGroup.replace_includec                 C   sš   g }d}|  ¡ }| jD ]t}t|tƒr0| |¡}qt|tƒr`|  ||¡r€| | |¡¡ |d7 }n t|t	ƒr€|  ||¡r€| |¡ | 
|¡ q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@   Úlevelr.   r1   r1   r2   rC     s    





zGroup.get_shadowc                 C   s   | j D ]
}| |_qdS ©z+Sets the correct container for the content.N)r   Ú	container)r+   r?   r1   r1   r2   r*   +  s    
zGroup.set_containerc                 C   s   |j dkrdS | |j ¡S )z3Should the object be defined in the user interface?r6   T)Údefined_whenZ	eval_when)r+   r8   r.   r1   r1   r2   rB   0  s    
zGroup._defined_whenc                 C   sà   d | _  | _| _|  |¡\}}|  |¡}|  |ddd¡}|  |ddd¡}|  |ddd	¡}|  |d
dd¡}|  |ddd¡}|  |ddd¡}|  |ddd¡}| jo¤| j }| j | _|| _|  d|dtjdd¡}|dkrÜ|| _	dS )z+Parses Group options specified as a string.Fú-ÚorientationÚ
horizontalú|Úverticalú=ÚlayoutÚsplitú^Útabbedr    Úshow_labelsTr   Ú	show_leftú!Úselectedr:   ú:r   r   r6   N)
Úshow_borderrS   rT   Z_parse_labelZ_parse_styleZ_optionÚ_splitr$   rA   Úobject)r+   r.   ÚemptyrS   r1   r1   r2   r%   6  s     

zGroup._parsec                 C   s
   d| _ dS )z5Handles a label being found in the string definition.TN)rX   r4   r1   r1   r2   Ú_parsed_labelP  s    zGroup._parsed_labelc                 C   s˜   g }d  dd„ | jD ƒ¡}t|ƒdkr0| |¡ |  ddddd	d
ddddd¡}|dur`| |¡ d  |¡}t|ƒdkr‚| jjd S d| jj|  |¡f S )ú.Returns a "pretty print" version of the Group.z,
c                 S   s   g | ]}|  ¡ ‘qS r1   )Ú__repr__©Ú.0r?   r1   r1   r2   Ú
<listcomp>W  ó    z"Group.__repr__.<locals>.<listcomp>r   rJ   rX   rS   rT   rV   r:   rZ   r7   ÚstylerO   Ústyle_sheetNz()z%s(
%s
))Újoinr   Úlenr&   Z_repr_optionsr0   Ú__name__Ú_indent)r+   ÚresultÚitemsÚoptionsr   r1   r1   r2   r^   T  s.    
õ

zGroup.__repr__c                 C   sV   d}| j D ]:}|jdkr
| jdkr.||j7 }q
| jdkr
t||jƒ}q
|dkrRd}|S )z)Returns the requested width of the Group.ç        r   rK   rM   r   ç      ð¿)r   ÚwidthrJ   Úmax)r+   rn   r?   r1   r1   r2   Ú
_get_widthu  s    



zGroup._get_widthc                 C   sV   d}| j D ]:}|jdkr
| jdkr0t||jƒ}q
| jdkr
||j7 }q
|dkrRd}|S )z*Returns the requested height of the Group.rl   r   rK   rM   r   rm   )r   ÚheightrJ   ro   )r+   rq   r?   r1   r1   r2   Ú_get_height…  s    



zGroup._get_height):rg   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r
   r:   r7   rd   r   rZ   rc   ÚdockÚimager   r   Ú
dock_themeÚexportr   rJ   r   rO   r   Ú
scrollabler   ÚcolumnsrX   rS   rT   rV   ÚspringyÚhelprH   Úvisible_whenÚenabled_whenÚPaddingÚpaddingr   r   rn   rq   r"   r5   r9   r;   r=   rC   r*   rB   r%   r\   r^   r   rp   rr   Ú__classcell__r1   r1   r/   r2   r   4   sT   
%!
r   c                   @   s   e Zd ZdZdZdS )ÚHGroupz.A group whose items are laid out horizontally.rK   N©rg   rs   rt   ru   rJ   r1   r1   r1   r2   rƒ   –  s   rƒ   c                   @   s   e Zd ZdZdZdS )ÚVGroupz,A group whose items are laid out vertically.rM   Nr„   r1   r1   r1   r2   r…   ¢  s   r…   c                   @   s   e Zd ZdZdZdS )ÚVGridz.A group whose items are laid out in 2 columns.é   N)rg   rs   rt   ru   r{   r1   r1   r1   r2   r†   ®  s   r†   c                   @   s   e Zd ZdZdZdZdS )ÚHFlowzwA group in which items are laid out horizontally, and "wrap" when
    they exceed the available horizontal space..
    ÚflowFN©rg   rs   rt   ru   rO   rS   r1   r1   r1   r2   rˆ   ¹  s   
rˆ   c                   @   s   e Zd ZdZdZdZdS )ÚVFlowzrA group in which items are laid out vertically, and "wrap" when they
    exceed the available vertical space.
    r‰   FNrŠ   r1   r1   r1   r2   r‹   È  s   	r‹   c                   @   s   e Zd ZdZdZdZdS )ÚVFoldzuA group in which items are laid out vertically and can be collapsed
    (i.e. 'folded') by clicking their title.
    ÚfoldFNrŠ   r1   r1   r1   r2   rŒ   Ö  s   
rŒ   c                   @   s   e Zd ZdZdZdZdS )ÚHSplitzGA horizontal group with splitter bars to separate it from other groups.rP   rK   N©rg   rs   rt   ru   rO   rJ   r1   r1   r1   r2   rŽ   å  s   rŽ   c                   @   s   e Zd ZdZdZdZdS )ÚVSplitzEA vertical group with splitter bars to separate it from other groups.rP   rM   Nr�   r1   r1   r1   r2   r�   ò  s   r�   c                   @   s   e Zd ZdZdZdZdS )ÚTabbedz+A group that is shown as a tabbed notebook.rR   TN)rg   rs   rt   ru   rO   r|   r1   r1   r1   r2   r‘   ÿ  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ƒ jf i |¤Ž d S r3   )r   r!   r"   )r+   r   r-   r/   r1   r2   r"     s    zShadowGroup.__init__Tc                 C   sÜ   | j dd… }| jdkrØ|srd}|t|ƒk rØ|| }t|tƒrf| d¡}||||d …< |t|ƒ7 }q |d7 }q nf| jt|ƒkrØ| jdkrØg }g }|D ]0}t|tƒr¼|  ||¡ | |¡ q–| |¡ q–|  ||¡ |}|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@   rf   r#   rD   Úget_contentrO   Ú_flush_itemsr&   )r+   Zallow_groupsri   r>   r.   rj   r   r?   r1   r1   r2   r“   h  s,    	



zShadowGroup.get_contentc                 C   s(   | j dkr| j S d dd„ |  ¡ D ƒ¡S )zReturns an ID for the group.r6   rW   c                 S   s   g | ]}|  ¡ ‘qS r1   )Úget_idr_   r1   r1   r2   ra   ”  rb   z&ShadowGroup.get_id.<locals>.<listcomp>)r:   re   r“   r4   r1   r1   r2   r•   �  s    
zShadowGroup.get_idc                 C   s   dS rF   r1   r4   r1   r1   r2   r*   –  s    zShadowGroup.set_containerc                 C   sJ   t |ƒdkrF| t| jd�jddd|| j| j| j| jd�¡ |dd…= dS )z@Creates a sub-group for any items contained in a specified list.r   )r   r6   F)r@   r7   rX   r   rS   rT   r|   rJ   N)	rf   r&   rD   r   Z	trait_setrS   rT   r|   rJ   )r+   r   rj   r1   r1   r2   r”   š  s    øþzShadowGroup._flush_itemsc                 C   s
   t | jƒS )r]   )Úreprr   r4   r1   r1   r2   r^   ¬  s    zShadowGroup.__repr__)T)&rg   rs   rt   ru   r"   r	   r   r@   ÚShadowDelegater:   r7   rZ   rc   rv   rw   rx   ry   rJ   rO   rz   r{   rX   rS   rT   rV   r|   r}   rH   r~   r   r�   rd   r“   r•   r*   r”   r^   r‚   r1   r1   r/   r2   rD     s@   
'rD   N)'ru   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   r   r   r—   r€   r   rƒ   r…   r†   rˆ   r‹   rŒ   rŽ   r�   r‘   rD   r1   r1   r1   r2   Ú<module>   s*   4  d