a
    §ˆcÿ»  ã                   @   s‚  d Z ddlmZ ddlZddlmZmZ ddl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 dd
lmZmZmZ ddlmZ ddlmZ ddlmZ dZe d¡Z dd„ Z!dd„ Z"dd„ Z#G dd„ deƒZ$dd„ Z%d3dd„Z&dd„ Z'dd „ Z(d!d"„ Z)G d#d$„ d$ej*ƒZ+G d%d&„ d&e,ƒZ-G d'd(„ d(eƒZ.G d)d*„ d*e.ƒZ/G d+d,„ d,e.ƒZ0G d-d.„ d.ej1ƒZ2da3d/d0œd1d2„Z4dS )4zECreates a panel-based PyQt user interface for a specified UI object.
é    )ÚescapeN)ÚQtCoreÚQtGui)ÚAnyÚHasPrivateTraitsÚInstanceÚ	Undefined)Úmatch)ÚGroup)ÚUndoHistory)Úhelp_template)Ú
UndoButtonÚRevertButtonÚ
HelpButtoné   )Úposition_window)Ú	BasePanel)ÚEditorz?=:;,.<>/\"'-+#|z\d+c                 C   s   t | |dƒ dS )úDCreates a panel-based PyQt user interface for a specified UI object.FN©Ú_ui_panel_for©ÚuiÚparent© r   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/ui_panel.pyÚui_panel>   s    r   c                 C   s   t | |dƒ dS )z×Creates a subpanel-based PyQt user interface for a specified UI object.
    A subpanel does not allow control buttons (other than those specified in
    the UI object) and does not show headers for view titles.
    TNr   r   r   r   r   Úui_subpanelC   s    r   c                 C   st   t | ||ƒj | _}||_| j d¡|_| |_z|  ¡  W n&   | d¡ ~d| _d| _	‚ Y n0 |  
¡  d| _	dS )r   ÚobjectNFT)Ú_PanelÚcontrolÚ_parentÚcontextÚgetZ_objectZ_uiZ
prepare_uiÚ	setParentÚresultÚrestore_prefs)r   r   Úis_subpanelr    r   r   r   r   K   s    
r   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )r   z;PyQt user interface panel for Traits-based user interfaces.c              	      s‚  t ƒ j|d� |j}|j}|dur^|jˆ jdddd� |jˆ jdddd� |jˆ jdddd� ‡ fdd	„|jD ƒ}t	|ƒ}| o˜|d
kp˜ˆ  
|d d¡ }|dkrØ|jr´ˆ  |t¡ |jrÆˆ  |t¡ |jrØˆ  |t¡ |�s|du �r|D ]0}	ˆ  
|	d¡�s
ˆ  
|	d¡rìtƒ  }|_ �qqìt|ƒˆ _|j}
|�sbt|tjƒ�rTt| ¡ tjƒ�rbt|tjƒ�rfd}
tˆ jtjƒ�r†|
dk�s†|�rbt ¡ }t |¡}| dddd¡ |
dk�rÈ| t ||jd�j¡ tˆ jtjƒ�ræ| ˆ j¡ ntˆ jtj!ƒ�r| "ˆ j¡ |ˆ _|�rbt #¡ }| $tj#j%j&tj#j'j(B ¡ | )d¡ | |¡ t *t+j,j-j.¡}|D ]þ}	tj*j/j0}ˆ  
|	d¡�rÊˆ  1|	||ˆ j2dd¡ˆ _ˆ  1|	||ˆ j3dd¡ˆ _4|jˆ jddd� |jˆ jddd� nŠˆ  
|	d¡�rtj*j/j5}ˆ  1|	||ˆ j6d¡ˆ _|jˆ jddd� nHˆ  
|	d¡�r8tj*j/j7}ˆ  1|	||ˆ j8¡ nˆ  
|	d¡�sXˆ  1|	||¡ �qX| |¡ ˆ  9|¡ t:ˆ jj;|ƒˆ j_;dS )úInitialise the object.)r   NZundoableTr   )ÚremoveÚdispatchZredoablec                    s   g | ]}ˆ   |¡‘qS r   )Zcoerce_button)Ú.0Úbutton©Úselfr   r   Ú
<listcomp>w   ó    z#_Panel.__init__.<locals>.<listcomp>r   r   Ú ZUndoZRevert)r   Útexté   FZRedo©r*   ZHelp)<ÚsuperÚ__init__ÚhistoryÚviewZobserveZ_on_undoableZ_on_redoableZ_on_revertableÚbuttonsÚlenZ	is_buttonZundoZcheck_buttonr   Úrevertr   Úhelpr   r   Úpanelr    ÚtitleÚ
isinstancer   ÚQMainWindowr   ÚQDialogÚ
QTabWidgetÚQWidgetÚQVBoxLayoutÚsetContentsMarginsÚ	addWidgetÚheading_textÚQLayoutÚ	addLayoutÚQFrameZsetFrameStyleÚShadowÚSunkenÚShapeÚHLineZsetFixedHeightÚQDialogButtonBoxr   ÚQtÚOrientationÚ
HorizontalZ
ButtonRoleZ
ActionRoleZ
add_buttonZ_on_undoZ_on_redoZredoZ	ResetRoleZ
_on_revertZHelpRoleZ_on_helpÚ_add_toolbarÚ_size_hint_wrapperÚsizeHint)r.   r   r   r'   r7   r8   r9   Z
nr_buttonsZhas_buttonsr,   r>   ÚwÚlayoutÚ	separatorÚbboxÚrole©Ú	__class__r-   r   r6   c   sÄ    
ÿ
ÿ
ÿÿÿ
ÿ
ýü
úÿþý

ÿ


ÿÿÿÿ
ÿÿ


z_Panel.__init__c                 C   s^   t |tjƒsdS | jjj}|durZd | _| _| || ¡}| 	d¡ | 
|¡ d | _| _dS )z)Adds a toolbar to the `parent` (QtWindow)NF)r?   r   r@   r   r8   ÚtoolbarZ_last_groupZ_last_parentZcreate_tool_barZ
setMovableZ
addToolBar)r.   r   r]   Z
qt_toolbarr   r   r   rS   ç   s    


z_Panel._add_toolbarc                 C   s   |j dkrdS | j |j ¡S )z\Returns whether the toolbar action should be defined in the user
        interface.
        r1   T)Zdefined_whenr   Z	eval_when)r.   Úactionr   r   r   Úcan_add_to_toolbarõ   s    
z_Panel.can_add_to_toolbar)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r6   rS   r_   Ú__classcell__r   r   r[   r   r   `   s
    r   c                 C   s´   | j  ¡  | j}t|ƒ}|dkr$d}|dkr>t|d | ƒj}n"|dkr`t ¡ }t||| ƒ | |_	| j
r°|dur°t|tjƒr�t ¡ }| |¡ |}t ¡ }| |¡ | d¡ |}|S )zÊCreates a panel-based PyQt user interface for a specified UI object.
    This function does not modify the UI object passed to it.  The object
    returned may be either a widget, a layout or None.
    r   Nr   T)ÚinfoZbind_contextÚ_groupsr:   Ú_GroupPanelr    r   rB   Ú_fill_panelr   Ú
scrollabler?   rH   rC   Ú	setLayoutÚQScrollAreaÚ	setWidgetÚsetWidgetResizable)r   ÚcontentZ	nr_groupsr=   rV   Úsar   r   r   r=   ÿ   s*    



r=   c                 C   sb  d}t |ƒD �]D\}}| |¡}|dkr0d| }t|tƒrþ|jrD|}t||dd�}|j}	|j}
t|
t| ƒƒr¦|
 	¡ dkr¦|
 
d¡}t| tjƒrš|
 d¡ qÒ|
 d¡ n,t|	tjƒr¸|	}nt ¡ }|	durÒ| |	¡ | ¡ }|durü| tjjjtjjjB ¡ n,t ¡ }t |¡}| dddd¡ |||ƒ t| tjƒ�rF|  ||¡ q|  ||¡ q|  |¡ dS )z/Fill a page based container panel with content.r   r1   zPage %dT©Úsuppress_labelr   N)Ú	enumerateÚ	get_labelr?   r
   Úselectedrg   r    Úsub_controlÚtypeÚcountÚwidgetr   rB   Z	removeTabZ
removeItemrC   rj   rW   ÚsetAlignmentr   rP   ÚAlignmentFlagÚ	AlignLeftÚAlignToprD   rE   ZaddTabÚaddItemÚsetCurrentIndex)r=   rn   r   Zitem_handlerÚactiveÚindexÚitemZ	page_nameZgpÚpageZsub_pageÚnewrW   r   r   r   rh   $  s@    





rh   c                    s   ‡ ‡fdd„}|S )z=Wrap an existing sizeHint method with sizes from a UI object.c                     sP   ˆ ƒ } ˆj d urLˆj jdkr.|  tˆj jƒ¡ ˆj jdkrL|  tˆj jƒ¡ | S )Nr   )r8   ÚwidthZsetWidthÚintÚheightZ	setHeight)Úsize©Úfr   r   r   rU   Z  s    
z$_size_hint_wrapper.<locals>.sizeHintr   )r‰   r   rU   r   rˆ   r   rT   W  s    	rT   c              	   C   sž   | j | j }tƒ }|jdkr.|jt|jƒ }n|j}g }| d¡D ]4}| ¡ sB| 	|j
t| | ¡ƒt| | ¡ƒf ¡ qB|j|d |¡f }t||ddƒ dS )z;Displays a help window for the specified UI's active Group.r1   FÚ
ç      Ð?g…ëQ¸Õ?N)rf   Z_active_groupr   r<   Z
group_helpr   Zno_group_helpÚget_contentZ	is_spacerÚappendÚ	item_helprs   Úget_helpZ
group_htmlÚjoinÚHTMLHelpWindow)r   r,   ÚgroupÚtemplateÚheaderÚfieldsr�   Úhtml_contentr   r   r   Ú	show_helpf  s"    
þÿÿr—   c                 C   sF   |   ¡ }tƒ }t|ddƒ}|durB|j| ¡ |f }t||ddƒ dS )z1Displays a pop-up help window for a single trait.r<   Nr‹   g¤p=
×£À?)ZGetEventObjectr   ÚgetattrZ	item_htmlZGetLabelr‘   )Úeventr    r“   r<   r–   r   r   r   Úshow_help_popup|  s    rš   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú_GroupSplitterz5A splitter for a Traits UI Group with layout='split'.c                 C   s   t j | ¡ || _d| _dS )zStore the group.FN)r   Ú	QSplitterr6   Ú_groupÚ_initialized)r.   r’   r   r   r   r6   �  s    z_GroupSplitter.__init__c                 C   sF   t j | |¡ |  ¡ }| jsB|rB|  ¡ s4t|t jƒrBd| _|  ¡  dS )a,  Overridden to position the splitter based on the Group when the
        application is initializing.

        Because the splitter layout algorithm requires that the available
        space be known, we have to wait until the UI that contains this
        splitter gives it its initial size.
        TN)	r   rœ   ÚresizeEventr   rž   Z	isVisibler?   r@   Ú_resize_items)r.   r™   r   r   r   r   rŸ   “  s    ÿþý
ýz_GroupSplitter.resizeEventc                 C   s&   t j | |¡ | js"d| _|  ¡  dS )z5Wait for the show event to resize items if necessary.TN)r   rœ   Ú	showEventrž   r    )r.   r™   r   r   r   r¡   ¦  s    z_GroupSplitter.showEventc           	      C   s  |   ¡ tjjjk}g }| jjD ]"}|r4| |j¡ q| |j	¡ q|rP|  ¡ }n|  	¡ }|}d}t
|ƒD ]Z\}}|dkr| qÄ|dkrº|dkr˜t||ƒ}n||9 }t|ƒ}|||< ||8 }qh|d7 }qh|dkrüt|| ƒ}t
|ƒD ]\}}|dk rà|||< qàn|d  |7  < |  |¡ dS )znSize the splitter based on the 'width' or 'height' attributes
        of the Traits UI view elements.
        r   r   éÿÿÿÿN)Úorientationr   rP   rQ   rR   r�   rn   r�   r„   r†   rr   Úminr…   ZsetSizes)	r.   Z
use_widthsÚsizesr�   ÚtotalZavailZremainÚiÚszr   r   r   r    ­  s:    


z_GroupSplitter._resize_itemsN)r`   ra   rb   rc   r6   rŸ   r¡   r    r   r   r   r   r›   Š  s
   r›   c                   @   s¢   e Zd ZdZd&dd„Zdd„ Zdd„ Zd	d
„ Zdd„ 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ej d¡fdd „Zd(d"d#„Zd$d%„ ZdS ))rg   zYA sub-panel for a single group of items.  It may be either a layout or a
    widget.
    Fc                 C   sÄ  |  ¡ }|| _|| _|jdkr,tjjj| _ntjjj	| _d } }}|rNd}n|j
}|jrtt |¡}t | j|¡}n,|dkr t | j¡ }}| td|d�j¡ t|ƒdkr°�n¾|jdkrÆtdƒ‚�n¨|jdk�ržt|ƒ}	|	 d	¡ | jtjjj	k�r|	 tjjj¡ |	 ¡ }
|
 d
¡ |
 d
¡ |jdk�r@|
 tjjj ¡ n|
 !tjjj ¡ |	 "|
¡ |du �rj|	}n
| |	¡ t#||	|d�}|  $||¡ |  %||	¡ �nÐ|jdv �r8|jdk�rÀt &¡ }nt '¡ }| ¡ }
|
 d
¡ |
 d
¡ | "|
¡ t(||| j| j)ƒ |du �r|}n
| |¡ t*|||d�}|  $||¡ �n6|j+�rž|du �rZt | j¡ }}t,|tj-ƒ�r~t .¡ }| /|¡ |}t 0¡ }| 1|¡ | 2d¡ |}|j3dk�s¶|j4dk�r|du �rÐt | j¡ }}t,|tj-ƒ�rôt .¡ }| /|¡ |}|  $|t5|d�¡ t,|d t6ƒ�r$|  7||¡}n|  8||¡}| 9tjj:j;tjj:j<B ¡ |du �rZ|}n||u�rn| =|¡ |j>�r´t,|tj-ƒ�rš|}t .¡ }| /|¡ t,|tj.ƒ�r´| ?|j>¡ || _|| _@dS )r(   Z
horizontalNr1   ©r2   r   Zflowz$'the 'flow' layout isn't implementedÚsplitFé2   )r    Úsplitterr   )ÚtabbedÚfoldr­   )Ú	containerr    r   T)r    )ArŒ   r’   r   r£   r   Ú
QBoxLayoutÚ	DirectionÚLeftToRightÚ	directionÚTopToBottomÚlabelZshow_borderZ	QGroupBoxrF   rG   r    r:   rW   ÚNotImplementedErrorr›   ZsetOpaqueResizeZsetOrientationr   rP   rQ   ZVerticalÚ
sizePolicyÚsetHorizontalStretchZsetVerticalStretchZsetVerticalPolicyÚQSizePolicyÚPolicyÚ	ExpandingÚsetHorizontalPolicyÚsetSizePolicyÚSplitterGroupEditorÚ_setup_editorÚ_add_splitter_itemsrB   ZQToolBoxrh   Ú_add_page_itemÚTabbedFoldGroupEditorri   r?   rH   rC   rj   rk   rl   rm   Úvisible_whenÚenabled_whenÚGroupEditorr
   Ú_add_groupsÚ
_add_itemsry   rz   r{   r|   rI   Ústyle_sheetÚsetStyleSheetru   )r.   r’   r   rq   rn   ÚouterÚsubÚinnerrµ   r¬   ÚpolicyÚeditorrx   Zscroll_arearW   r   r   r   r6   è  s´    








ÿ















z_GroupPanel.__init__c                 C   s¦   |D ]œ}t |tƒr&t|| jdd�j}n|  |g¡}|durt |tjƒrlt ¡ }| 	dddd¡ | 
|¡ |}| ¡ }|dur–| tjjjtjjjB ¡ | |¡ qdS )z9Adds a set of groups or items separated by splitter bars.Trp   Nr   )r?   r
   rg   r   r    rÇ   r   rH   rC   rE   rj   rW   ry   r   rP   rz   r{   r|   rF   )r.   rn   r¬   r�   r=   rV   rW   r   r   r   rÀ   …  s     

ÿz_GroupPanel._add_splitter_itemsc                 C   sT   |j dkr| jj |j |¡ |jdkr6| j |j|¡ |jdkrP| j |j|¡ dS )zSetup the editor for a group.r1   N)Úidr   re   ÚbindrÃ   Úadd_visiblerÄ   Úadd_enabled)r.   r’   rÎ   r   r   r   r¿      s    


z_GroupPanel._setup_editorc                 C   s   |   |g|¡ dS )z)Adds a single Item to a page based panel.N)rÇ   )r.   r�   rW   r   r   r   rÁ   «  s    z_GroupPanel._add_page_itemc                 C   sp   |du rt  | j¡}|D ]R}t|| jƒj}t|t jƒrB| |¡ qt|t j	ƒrZ| 
|¡ q| t  d¡¡ q|S )zvAdds a list of Group objects to the panel, creating a layout if
        needed.  Return the outermost layout.
        Nú )r   r°   r³   rg   r   r    r?   rC   rF   rH   rI   ÚQLabel)r.   rn   rÊ   Zsubgroupr=   r   r   r   rÆ   ¯  s    z_GroupPanel._add_groupsc                 C   s    |   | jd¡ |   | jd¡ dS )z�Set the visible and enabled states of all labels as controlled by
        a 'visible_when' or 'enabled_when' expression.
        ÚenabledÚvisibleN)Ú_evaluate_label_conditionÚ_label_enabled_whensÚ_label_visible_whensr-   r   r   r   Ú_label_whenÆ  s    z_GroupPanel._label_whenc           
   	   C   s~   | j  | j j¡}dddœ}|D ]Z\}}t||| ƒ}zt|tƒ |ƒ}|t|ƒƒ W q tyv   ddlm	}	 |	ƒ  Y q0 qdS )z©Evaluates a list of (eval, widget) pairs and calls the appropriate
        method on the label widget to toggle whether it is visible/enabled
        as needed.
        Z
setVisibleZ
setEnabled)rÖ   rÕ   r   )Úraise_to_debugN)
r   Z_get_contextr"   r˜   ÚevalÚglobalsÚboolÚ	ExceptionÚtraitsui.apirÛ   )
r.   Z
conditionsÚkindr"   Zmethod_dictÚwhenrµ   Zmethod_to_callZ
cond_valuerÛ   r   r   r   r×   Í  s    
z%_GroupPanel._evaluate_label_conditionNc           $   	      s>  ˆ j }|j}|j}ˆ j}|j}|j}g ˆ _g ˆ _d}	|D ]}
|	|
jO }	q8|	sT|dkr”t	 
¡ }|du rj|}n
| |¡ d}|rˆtjjj}q´tjjj}n |du r¨t	 ˆ j¡}|}d}d}d}|D �].}
|d7 }|dkræ||kræd}|d7 }|
j}|dkrød}|dk�r&|
j}|dk�rìˆ  |
||||	¡ q¼|d	k�rFˆ  |
|||||	¡ q¼t |¡�rhˆ  |
|||||	¡ q¼t|
jtƒ |jƒ}| |¡}|j}|du �rª|j �r¦d
|j  nd}|
j!}|du �r(| "¡ j#f i |
j$¤Ž}|du �rìddl%m&} |ƒ }|
j'du�r |
j'|_'|
j(dk�r|
j(|_(|
j)dk�r(|
j)|_)t*||
j+d ƒ}|||||
jdƒj#|
|
j,d�}| -|¡ |j.}|
j/�rz| 0|
j/¡ |j1|_1|
j�r®ˆ  2|
||¡}ˆ  3|||||	|¡ nd}||_4|
j5�rÊˆ  6|¡ |
j7�rÚ|ˆ j _8d}|
j9}|
j:}|dk�sþ|dk�r:ˆ jt	jj;j<k}| =¡ }| 9¡ }| :¡ }d} d}!d|  k �rFdk�r\n n|�r\t>d| ƒ}t>|ƒ}|dk �rz| }d} n
t?||ƒ}d|  k �rœdk�r²n n|�s²t>d| ƒ}t>|ƒ}|dk �rÐ| }d}!n
t?||ƒ}| @t?|dƒ¡ | At?|dƒ¡ |dk�s
|�s| �r| B|¡ |dk�s*|�r:|!�r:| C|¡ ˆ  D||
||¡ ˆ  3|||||	¡ |
jE�pf|}"| F|"||
jE¡ ˆ j  jG|jHO  _G|jI J|¡ t*||"d dƒ}#|#du�rº| K|#¡ |
jLdk�rÔ| M|
jL|¡ |
jNdkr¼| O|
jN|¡ q¼tPˆ jƒtPˆ jƒ dk�r:ˆ j j Q¡ D ]}|jR‡ fdd„dd� �qˆ  S¡  |S )zhAdds a list of Item objects, creating a layout if needed.  Return
        the outermost layout.
        Fr   Nr   r¢   rÓ   Ú5r1   Ú_z
Specifies )ÚToolkitEditorFactoryZ_editor)r�   Zobject_nameg        g      ð?éd   TZ_definedc                      s   ˆ   ¡ S )N)rÚ   r   r-   r   r   Ú<lambda>Ô  r0   z(_GroupPanel._add_items.<locals>.<lambda>r   r4   )Tr   re   Úhandlerr’   Ú	show_leftÚcolumnsrØ   rÙ   Z
show_labelr   ZQGridLayoutrI   r   rP   rz   Z
AlignRightr{   r°   r³   Únamerµ   Ú_add_label_itemÚ_add_separator_itemÚ
all_digitsr	   Ú_add_spacer_itemrÜ   Zobject_rÝ   r"   Z
base_traitZtooltipÚdescrÎ   Z
get_editorÚ	trait_setZeditor_argsZtext_editorrå   Zformat_funcZ
format_strÚinvalidr˜   Ústyler   Úpreparer    rÈ   rÉ   rÕ   Ú_create_labelÚ_add_widgetÚlabel_controlÚ
emphasizedÚ_add_emphasisZ	has_focusZ_focus_controlr„   r†   r±   r²   ZminimumSizeHintr…   ÚmaxZsetMinimumWidthZsetMinimumHeightZsetMaximumWidthZsetMaximumHeightÚ_set_item_size_policyrÏ   rÐ   Z_scrollableri   Z_editorsr�   Zadd_definedrÃ   rÑ   rÄ   rÒ   r:   ÚvaluesZon_trait_changerÚ   )$r.   rn   rÊ   r   re   rè   r’   ré   rê   Úshow_labelsr�   rÌ   ÚrowÚlabel_alignmentÚcolrë   rµ   r   Ztraitrð   Zeditor_factoryrå   Zfactory_methodrÎ   r    ÚstretchZ
item_widthZitem_heightZis_horizontalZmin_sizer„   r†   Zforce_widthZforce_heightrÏ   Zdefinedr   r-   r   rÇ   á  s   




ÿ


ÿ

ÿÿþ	
ÿ
ÿ"

"






þÿ
z_GroupPanel._add_itemsc                 C   s€   |j }|jdkrt |¡}ntd |d�j}|  |||||¡ |jrL|  |¡ |j	rd| j
 |j	|f¡ |jr|| j |j|f¡ d S )NÚsimpler©   )rµ   ró   r   rÔ   rG   r    rö   rø   rù   rÃ   rÙ   r�   rÄ   rØ   )r.   r�   rÌ   rþ   r   rý   rµ   r   r   r   rì   Ú  s    

z_GroupPanel._add_label_itemc           
      C   sÄ   |}|dkr$|dkrd}|r$|d9 }t |ƒD ]’}t ¡ }	| jtjjjkr||	 tjjj	¡ |dk rl| 
|	¡ q®| 
|	||¡ n2|	 tjjj¡ |dk r | 
|	¡ n| 
|	||¡ |	 tjjj¡ q,d S )Nr   r3   )Úranger   rJ   r³   r°   r±   r²   ZsetFrameShaperM   ZVLinerF   rN   ZsetFrameShadowrK   rL   )
r.   r�   rê   rÌ   rþ   r   rý   Úcolsr§   Úliner   r   r   rí   ì  s$    z_GroupPanel._add_separator_itemc           	      C   sH   t |ƒ}| jtjjjkr&t |d¡}nt d|¡}|  |||||¡ d S )Nr   )r…   r³   r   r°   r±   r²   ZQSpacerItemrö   )	r.   r�   rë   rÌ   rþ   r   rý   ÚnZspacerr   r   r   rï     s
    z_GroupPanel._add_spacer_itemc           	      C   sØ   | j j}|jdu p |jtu o |j}|j}|j ¡  ¡ }|dur¢|s¢|t	j
jjkr¢| jt	jjjkrz|rzd}|  ||ptd¡ n(| jt	jjjkr¢|r¢d}|  ||pžd¡ |r¶|p¬d}d| _n|rÂ|pÀd}| | j|||¡ |S )ag  Set size policy of an item and its label (if any).

        How it is set:

        1) The general rule is that we obey the item.resizable and
           item.springy settings. An item is considered resizable also if
           resizable is Undefined but the item is scrollable

        2) However, if the labels are on the right, and the item is of a
           kind that cannot be stretched in horizontal (e.g. a checkbox),
           we make the label stretchable instead (to avoid big gaps
           between element and label)

        If the item is resizable, the _GroupPanel is set to be resizable.
        TNFr«   )r’   ré   Z	resizabler   ri   Zspringyr    r·   ZhorizontalPolicyr   r¹   rº   ZMinimumr³   r°   r±   r²   Ú_make_label_h_stretchabler´   Zset_size_policy)	r.   rÎ   r�   rµ   r  Zis_label_leftZis_item_resizableZis_item_springyZitem_policyr   r   r   rû     sB    
ÿÿþý	ÿþÿþ
ÿz!_GroupPanel._set_item_size_policyc                 C   s0   |  ¡ }| |¡ | tjjj¡ | |¡ dS )z¾Set size policies of a QLabel to be stretchable horizontally.

        :attr:`stretch` is the stretch factor that Qt uses to distribute the
        total size to individual elements
        N)r·   r¸   r¼   r   r¹   rº   r»   r½   )r.   rµ   r  Zlabel_policyr   r   r   r  W  s    
z%_GroupPanel._make_label_h_stretchabler   c                 C   s  t |tjƒr,| ¡ }|dur,| dddd¡ |dk rpt |tjƒrL| |¡ n"t |tjƒrd| |¡ n
| |¡ nž| j	tj
jjkrŠ|| }}|r¾|d9 }|dkr¦| jjr¶|dkr¾| jjr¾|d7 }t |tjƒrÜ| ||||¡ n2t |tjƒrú| ||||¡ n| |||dd|¡ dS )znAdds a widget to a layout taking into account the orientation and
        the position of any labels.
        Nr   r3   r   )r?   r   rC   rW   rE   rF   rH   rI   r}   r³   r°   r±   r²   r’   ré   )r.   rW   rV   rþ   Úcolumnrý   rÿ   Zwlr   r   r   rö   b  s2    
ÿÿz_GroupPanel._add_widgetú:c                 C   sj   |  |¡}|dkr.|d tvr.| jjr.|| }t |¡}|jrH|  |¡ | |¡|_	|dkrf| 
|¡ |S )a  Creates an item label.

        When the label is on the left of its component,
        it is not empty, and it does not end with a
        punctuation character (see :attr:`LABEL_PUNCTUATION_CHARS`),
        we append a suffix (by default a colon ':') at the end of the
        label text.

        We also set the help on the QLabel control (from item.help) and the
        tooltip (if the ``tooltip`` metadata on the edited trait exists, then
        it will be used as-is; otherwise, if the ``desc`` metadata exists, the
        string "Specifies " will be prepended to the start of ``desc``).

        Parameters
        ----------
        item : Item
            The item for which we want to create a label
        ui : UI
            Current ui object
        desc : string
            Description of the item, to create an appropriate tooltip
        suffix : string
            Characters to at the end of the label

        Returns
        -------
        label_control : QLabel
            The control for the label

        r1   r¢   )rs   ÚLABEL_PUNCTUATION_CHARSr’   ré   r   rÔ   rø   rù   r�   r<   Z
setToolTip)r.   r�   r   rð   Úsuffixrµ   r÷   r   r   r   rõ   •  s     
ÿ
þý


z_GroupPanel._create_labelc                 C   sh   t  | ¡ ¡}| t jjjt  ddd¡¡ | |¡ t  | 	¡ ¡}| 
d¡ | | ¡ ¡ | |¡ dS )z,Adds emphasis to a specified control's font.r   é   TN)r   ZQPaletteZpaletteZsetColorZ	ColorRoleZ
WindowTextZQColorZ
setPaletteZQFontÚfontZsetBoldZsetPointSizeZ	pointSizeZsetFont)r.   r    Zpalr  r   r   r   rù   Ð  s    

z_GroupPanel._add_emphasis)F)N)r	  )r`   ra   rb   rc   r6   rÀ   r¿   rÁ   rÆ   rÚ   r×   rÇ   rì   rí   rï   rû   r  r   rP   rz   rö   rõ   rù   r   r   r   r   rg   ã  s(   
 
 z!=
ù
3
;rg   c                   @   s   e Zd ZdZdd„ ZdS )rÅ   z2A pseudo-editor that allows a group to be managed.c                 K   s&   t j| fi |¤Ž | jf i |¤Ž dS )r(   N)r   r6   rñ   )r.   Ztraitsr   r   r   r6   á  s    zGroupEditor.__init__N©r`   ra   rb   rc   r6   r   r   r   r   rÅ   Þ  s   rÅ   c                   @   s(   e Zd ZdZeeƒZdd„ Zdd„ ZdS )r¾   zHA pseudo-editor that allows a group with a 'split' layout to be managed.c                 C   s2   t |tƒr| d¡}n|}d| j_| j |¡ dS )ú[Restores any saved user preference information associated with the
        editor.
        Ú	structureTN)r?   Údictr#   r¬   rž   ZrestoreState)r.   Úprefsr  r   r   r   r&   ò  s
    
z!SplitterGroupEditor.restore_prefsc                 C   s   d| j  ¡  ¡ iS )úCReturns any user preference information associated with the editor.r  )r¬   Z	saveStateÚdatar-   r   r   r   Ú
save_prefsþ  s    zSplitterGroupEditor.save_prefsN)	r`   ra   rb   rc   r   r›   r¬   r&   r  r   r   r   r   r¾   ê  s   r¾   c                   @   s&   e Zd ZdZeƒ Zdd„ Zdd„ ZdS )rÂ   z\A pseudo-editor that allows a group with a 'tabbed' or 'fold' layout to
    be managed.
    c                 C   s.   t |tƒr| d¡}n|}| j t|ƒ¡ dS )r  Úcurrent_indexN)r?   r  r#   r¯   r~   r…   )r.   r  r  r   r   r   r&     s    
z#TabbedFoldGroupEditor.restore_prefsc                 C   s   dt | j ¡ ƒiS )r  r  )Ústrr¯   ZcurrentIndexr-   r   r   r   r    s    z TabbedFoldGroupEditor.save_prefsN)r`   ra   rb   rc   r   r¯   r&   r  r   r   r   r   rÂ     s   rÂ   c                   @   s   e Zd ZdZdd„ ZdS )r‘   zBWindow for displaying Traits-based help text with HTML formatting.c           	      C   s°   ddl m} tj | |¡ t | ¡}| dddd¡ | ¡ }| tj	j
jtj	j
j¡ | |¡ | |¡ t tjjjtjjj¡}|j | j¡ | |¡ t| |d� |  ¡  dS )zInitializes the object.r   )ÚQtWebKit)r   N)Ú	pyface.qtr  r   rA   r6   rD   rE   ZQWebViewr½   r¹   rº   r»   ZsetHtmlrF   rO   ZStandardButtonZOkr   rP   rQ   rR   ÚacceptedÚconnectÚacceptr   Úshow)	r.   r   r–   Zscale_dxZscale_dyr  rW   Zhtml_controlrY   r   r   r   r6   %  s"    
ÿ

ÿ
zHTMLHelpWindow.__init__Nr  r   r   r   r   r‘   "  s   r‘   F)Úcreatec                 O   s2   t du rddlm a  t |d| i|¤Ž}| ¡  |S )z$Create a Pyface HeadingText control.Nr   )ÚHeadingTextr  )r  Z
pyface.apir  )r  ÚargsÚkwrx   r   r   r   rG   I  s
    rG   )N)5rc   Úhtmlr   Úrer  r   r   Z
traits.apir   r   r   r   Ztraits.observation.apir	   rà   r
   Ztraitsui.undor   Ztraitsui.help_templater   Ztraitsui.menur   r   r   Úhelperr   Zui_baser   rÎ   r   r
  Úcompilerî   r   r   r   r   r=   rh   rT   r—   rš   rœ   r›   r   rg   rÅ   r¾   rÂ   rA   r‘   r  rG   r   r   r   r   Ú<module>   sL   
  %
3Y      $