3
8Ad]0°  ã               @   sx  d Z ddlmZmZ ddlZddlZddlmZ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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jdƒZdd„ Z dd„ Z!dd„ Z"G dd„ deƒZ#dd„ Z$d0d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-ƒZ/G d,d-„ d-ej0ƒZ1da2d.d/„ Z3dS )1zECreates a panel-based PyQt user interface for a specified UI object.
é    )Úabsolute_importÚdivisionN)ÚQtCoreÚQtGui)ÚAnyÚInstanceÚ	Undefined)ÚGroup)ÚUndoHistory)Úhelp_template)Ú
UndoButtonÚRevertButtonÚ
HelpButtoné   )Úposition_window)Ú	BasePanel)ÚEditorz?=:;,.<>/\"'-+#|z\d+c             C   s   t | |dƒ dS )zICreates a panel-based PyQt user interface for a specified UI object.
    FN)Ú_ui_panel_for)ÚuiÚparent© r   úq/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/qt4/ui_panel.pyÚui_panelC   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.
    TN)r   )r   r   r   r   r   Úui_subpanelI   s    r   c          	   C   st   t | ||ƒj | _}||_| jjdƒ|_| |_y| jƒ  W n&   |jdƒ ~d| _d| _	‚ Y nX | j
ƒ  d| _	dS )zICreates a panel-based PyQt user interface for a specified UI object.
    ÚobjectNFT)Ú_PanelÚcontrolZ_parentÚcontextÚgetZ_objectZ_uiZ
prepare_uiZ	setParentÚresultÚrestore_prefs)r   r   Úis_subpanelr   r   r   r   r   Q   s    
r   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r   z@PyQt user interface panel for Traits-based user interfaces.
    c                sp  |ˆ _ |j}|j}|dk	rP|jˆ jddd� |jˆ jddd� |jˆ jddd� ‡ fdd„|jD ƒ}t|ƒ}| oŠ|dkpŠˆ j	|d	 d
ƒ }|d	krÊ|j
r¦ˆ j|tƒ |jr¸ˆ j|tƒ |jrÊˆ j|tƒ | oÖ|dk�rx2|D ]*}	ˆ j	|	dƒsüˆ j	|	dƒràtƒ  }|_P qàW t|ƒˆ _|j}
|�sTt|tjƒ�rFt|jƒ tjƒ �sTt|tjƒ�rXd
}
tˆ jtjƒ �sz|
d
k�sz|�rPtjƒ }tj|ƒ}|jd	d	d	d	ƒ |
d
k�r¼|jtd|jd�jƒ tˆ jtjƒ�rÚ|jˆ jƒ ntˆ jtj ƒ�rö|j!ˆ jƒ |ˆ _|�rPtj"ƒ }|j#tj"j$tj"j%B ƒ |j&dƒ |j|ƒ tj't(j)j*ƒ}�x |D ]ø}	tj'j+}ˆ j	|	dƒ�rºˆ j,|	||ˆ j-ddƒˆ _
ˆ j,|	||ˆ j.ddƒˆ _/|jˆ jddd� |jˆ jddd� n†ˆ j	|	dƒ�rútj'j0}ˆ j,|	||ˆ j1dƒˆ _|jˆ jddd� nFˆ j	|	dƒ�r$tj'j2}ˆ j,|	||ˆ j3ƒ nˆ j	|	d
ƒ�sJˆ j,|	||ƒ �qJW |j|ƒ ˆ j4|ƒ t5ˆ jj6|ƒˆ j_6dS )zInitialise the object.
        NZundoableT)ÚremoveZredoablec                s   g | ]}ˆ j |ƒ‘qS r   )Zcoerce_button)Ú.0Úbutton)Úselfr   r   ú
<listcomp>z   s    z#_Panel.__init__.<locals>.<listcomp>r   r   Ú ZUndoZRevert)Útexté   FZRedor   )ÚdispatchZHelp)7r   ÚhistoryÚviewZon_trait_changeZ_on_undoableZ_on_redoableZ_on_revertableÚbuttonsÚlenZ	is_buttonZundoZcheck_buttonr   Zrevertr   Úhelpr   r
   Úpanelr   ÚtitleÚ
isinstancer   ÚQMainWindowr   ÚQDialogÚ
QTabWidgetÚQWidgetÚQVBoxLayoutÚsetContentsMarginsÚ	addWidgetÚheading_textÚQLayoutÚ	addLayoutÚQFrameZsetFrameStyleÚSunkenÚHLineZsetFixedHeightÚQDialogButtonBoxr   ÚQtÚ
HorizontalZ
ActionRoleZ
add_buttonZ_on_undoZ_on_redoZredoZ	ResetRoleZ
_on_revertZHelpRoleZ_on_helpÚ_add_toolbarÚ_size_hint_wrapperÚsizeHint)r%   r   r   r!   r+   r,   r-   Z
nr_buttonsZhas_buttonsr$   r1   ÚwÚlayoutÚ	separatorÚbboxZroler   )r%   r   Ú__init__k   s¤    
















z_Panel.__init__c             C   s^   t |tjƒsdS | jjj}|dk	rZd | _| _|j|| ƒ}|j	dƒ |j
|ƒ d | _| _dS )z3 Adds a toolbar to the `parent` (QtWindow)
        NF)r2   r   r3   r   r,   ÚtoolbarZ_last_groupZ_last_parentZcreate_tool_barZ
setMovableZ
addToolBar)r%   r   rK   Z
qt_toolbarr   r   r   rC   á   s    


z_Panel._add_toolbarc             C   s   |j dkrdS | jj|j ƒS )z_Returns whether the toolbar action should be defined in the user
           interface.
        r'   T)Zdefined_whenr   Z	eval_when)r%   Úactionr   r   r   Úcan_add_to_toolbarð   s    
z_Panel.can_add_to_toolbarN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rJ   rC   rM   r   r   r   r   r   g   s   vr   c             C   s´   | j jƒ  | j}t|ƒ}|dkr$d}|dkr>t|d | ƒj}n"|dkr`tjƒ }t||| ƒ | |_	| j
r°|dk	r°t|tjƒr�tjƒ }|j|ƒ |}tjƒ }|j|ƒ |j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   r5   Ú_fill_panelr   Ú
scrollabler2   r;   r6   Ú	setLayoutZQScrollAreaZ	setWidgetZsetWidgetResizable)r   ÚcontentZ	nr_groupsr0   rF   Úsar   r   r   r0   ú   s*    



r0   c             C   s\  d}�xFt |ƒD �]8\}}|j|ƒ}|dkr4d| }t|tƒrö|jrH|}t||dd�}|j}	|j}
t|
t| ƒƒrª|
j	ƒ dkrª|
j
dƒ}t| tjƒrž|
jdƒ qÎ|
jdƒ n$t|	tjƒr¼|	}ntjƒ }|j|	ƒ |jƒ }|dk	rô|jtjjtjjB ƒ n,tjƒ }tj|ƒ}|jddddƒ |||ƒ t| tjƒ�r>| j||ƒ q| j||ƒ qW | j|ƒ dS )z4Fill a page based container panel with content.
    r   r'   zPage %dT)Úsuppress_labelr   N)Ú	enumerateÚ	get_labelr2   r	   ÚselectedrT   r   Úsub_controlÚtypeÚcountÚwidgetr   r5   Z	removeTabZ
removeItemr6   rW   rG   ÚsetAlignmentr   rA   Ú	AlignLeftÚAlignTopr7   r8   ZaddTabÚaddItemÚsetCurrentIndex)r0   rX   r   Zitem_handlerÚactiveÚindexÚitemZ	page_nameÚgpÚpageZsub_pageÚnewrG   r   r   r   rU     s>    





rU   c                s   ‡ ‡fdd„}|S )zBWrap an existing sizeHint method with sizes from a UI object.
    c                 s>   ˆ ƒ } ˆj jdkr | jˆj jƒ ˆj jdkr:| jˆj jƒ | S )Nr   )r,   ÚwidthZsetWidthÚheightZ	setHeight)Úsize)Úfr   r   r   rE   U  s    z$_size_hint_wrapper.<locals>.sizeHintr   )rp   r   rE   r   )rp   r   r   rD   R  s    rD   c             C   s¨   | j | j }tƒ }|jdkr0|jtj|jƒ }n|j}g }xF|jdƒD ]8}|j	ƒ sF|j
|jtj|j| ƒƒtj|j| ƒƒf ƒ qFW |j|dj|ƒf }t||ddƒ dS )zA Displays a help window for the specified UI's active Group.
    r'   FÚ
g      Ð?g…ëQ¸Õ?N)rS   Z_active_groupr   r/   Z
group_helpÚcgiÚescapeZno_group_helpÚget_contentZ	is_spacerÚappendÚ	item_helpr\   Úget_helpZ
group_htmlÚjoinÚHTMLHelpWindow)r   r$   ÚgroupÚtemplateÚheaderÚfieldsri   Úhtmlr   r   r   Ú	show_helpc  s    
r   c             C   sF   | j ƒ }tƒ }t|ddƒ}|dk	rB|j|jƒ |f }t||ddƒ dS )z7 Displays a pop-up help window for a single trait.
    r/   Ng      Ð?g¤p=
×£À?)ZGetEventObjectr   ÚgetattrZ	item_htmlÚGetLabelry   )Úeventr   r{   r/   r~   r   r   r   Úshow_help_popupz  s    rƒ   c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú_GroupSplitterz; A splitter for a Traits UI Group with layout='split'.
    c             C   s   t jj| ƒ || _d| _dS )z Store the group.
        FN)r   Ú	QSplitterrJ   Ú_groupÚ_initialized)r%   rz   r   r   r   rJ   �  s    z_GroupSplitter.__init__c             C   sH   t jj| |ƒ | jƒ }| j rD|rD| jƒ s6t|t jƒrDd| _| jƒ  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	isVisibler2   r3   Ú_resize_items)r%   r‚   r   r   r   r   rˆ   ”  s    z_GroupSplitter.resizeEventc             C   s&   t jj| |ƒ | js"d| _| jƒ  dS )z? Wait 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$  | j ƒ tjjk}g }x.| jjD ]"}|r4|j|jƒ q|j|jƒ qW |rR| jƒ }n| jƒ }|}d}xdt	|ƒD ]X\}}|dkr~P |dkr¼|dkršt
||ƒ}n||9 }t|ƒ}|||< ||8 }ql|d7 }qlW |dk�rt|| ƒ}x6t	|ƒD ]\}}|dk rè|||< qèW n|d  |7  < | j|ƒ dS )zs Size the splitter based on the 'width' or 'height' attributes
            of the Traits UI view elements.
        r   r   Néÿÿÿÿ)Úorientationr   rA   rB   r†   rX   ru   rm   rn   r[   ÚminÚintZsetSizes)	r%   Z
use_widthsÚsizesri   ÚtotalÚavailZremainÚiÚszr   r   r   r‰   ¬  s:    


z_GroupSplitter._resize_itemsN)rN   rO   rP   rQ   rJ   rˆ   rŠ   r‰   r   r   r   r   r„   ‰  s
   r„   c               @   sz   e Zd ZdZd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ejjdƒfdd„Zddd„Zdd„ ZdS )rT   z\A sub-panel for a single group of items.  It may be either a layout or a
       widget.
    Fc             C   sJ  |j ƒ }|| _|| _|jdkr*tjj| _n
tjj| _d } }}|rJd}n|j	}|j
rptj|ƒ}tj| j|ƒ}n,|dkrœtj| jƒ }}|jtd|d�jƒ t|ƒdkr¬�nH|jdkrÂtdƒ‚�n2|jdk�r�t|ƒ}	|	jd	ƒ | jtjjkrü|	jtjjƒ |	jƒ }
|
jd
ƒ |
jd
ƒ |jdk�r4|
jtjjƒ n|
jtjjƒ |	j|
ƒ |dk�r\|	}n
|j|	ƒ t ||	|d�}| j!||ƒ | j"||	ƒ �nd|jdk�r(|jdk�r²tj#ƒ }ntj$ƒ }|jƒ }
|
jd
ƒ |
jd
ƒ |j|
ƒ t%||| j| j&ƒ |dk�r|}n
|j|ƒ t'|||d�}| j!||ƒ nÌ|j(dk�s@|j)dk�r�|dk�rZtj| jƒ }}t*|tj+ƒ�r~tj,ƒ }|j-|ƒ |}| j!|t.|d�ƒ t*|d t/ƒ�r®| j0||ƒ}n| j1||ƒ}|j2tjj3tjj4B ƒ |dk�rà|}n||k	�rô|j5|ƒ |j6�r:t*|tj+ƒ�r |}tj,ƒ }|j-|ƒ t*|tj,ƒ�r:|j7|j6ƒ || _|| _8dS )zInitialise the object.
        Ú
horizontalNr'   )r(   r   Zflowz$'the 'flow' layout isn't implementedÚsplitFé2   )r   Úsplitterr   ÚtabbedÚfold)Ú	containerr   r   )r   )r˜   r™   )9rt   rz   r   rŒ   r   Ú
QBoxLayoutÚLeftToRightÚ	directionÚTopToBottomÚlabelZshow_borderZ	QGroupBoxr9   r:   r   r.   rG   ÚNotImplementedErrorr„   ZsetOpaqueResizeZsetOrientationr   rA   ZVerticalÚ
sizePolicyÚsetHorizontalStretchZsetVerticalStretchZsetVerticalPolicyÚQSizePolicyÚ	ExpandingÚsetHorizontalPolicyÚsetSizePolicyÚSplitterGroupEditorÚ_setup_editorÚ_add_splitter_itemsr5   ZQToolBoxrU   Ú_add_page_itemÚTabbedFoldGroupEditorÚvisible_whenÚenabled_whenr2   r;   r6   rW   ÚGroupEditorr	   Ú_add_groupsÚ
_add_itemsrb   rc   rd   r<   Ústyle_sheetÚsetStyleSheetr^   )r%   rz   r   rZ   rX   ÚouterÚsubÚinnerrŸ   r—   ÚpolicyÚeditorra   rG   r   r   r   rJ   ç  sœ    





















z_GroupPanel.__init__c             C   s¦   x |D ]˜}t |tƒr(t|| jdd�j}n| j|gƒ}|dk	rt |tjƒrntjƒ }|j	ddddƒ |j
|ƒ |}|jƒ }|dk	r”|jtjjtjjB ƒ |j|ƒ qW dS )zBAdds a set of groups or items separated by splitter bars.
        T)rZ   Nr   )r2   r	   rT   r   r   r°   r   r;   r6   r8   rW   rG   rb   r   rA   rc   rd   r9   )r%   rX   r—   ri   r0   rF   rG   r   r   r   r©   u  s    


z_GroupPanel._add_splitter_itemsc             C   sT   |j dkr| jjj|j |ƒ |jdkr6| jj|j|ƒ |jdkrP| jj|j|ƒ dS )z&Setup the editor for a group.
        r'   N)Úidr   rR   Úbindr¬   Úadd_visibler­   Úadd_enabled)r%   rz   r·   r   r   r   r¨   �  s    


z_GroupPanel._setup_editorc             C   s   | j |g|ƒ dS )z2Adds a single Item to a page based panel.
        N)r°   )r%   ri   rG   r   r   r   rª   œ  s    z_GroupPanel._add_page_itemc             C   st   |dkrt j| jƒ}xZ|D ]R}t|| jƒj}t|t jƒrD|j|ƒ qt|t j	ƒr\|j
|ƒ q|jt jdƒƒ qW |S )zyAdds a list of Group objects to the panel, creating a layout if
           needed.  Return the outermost layout.
        Nú )r   r›   r�   rT   r   r   r2   r6   r9   r;   r<   ÚQLabel)r%   rX   r³   Zsubgroupr0   r   r   r   r¯   ¡  s    
z_GroupPanel._add_groupsNc       )      C   s  | j }|j}|j}| j}|j}|j}d}	x|D ]}
|	|
jO }	q.W |	sL|dkrˆtjƒ }|dkrb|}n
|j	|ƒ d}|r~t
jj}q¨t
jj}n |dkrœtj| jƒ}|}d}d}d}�xb|D �]X}
|d7 }|dkrÞ||krÞd}|d7 }|
j}|dk�rF|
j}|dkr´|
jdk�rtj|ƒ}ntd|d�j}| j|||||	ƒ |
jr´| j|ƒ q´|dk�r,|}|dk�rŠ|dk�rtd}|d7 }|d7 }|	�rŠ|d	9 }xžt|ƒD ]’}tjƒ }| jtjjk�rä|jtjjƒ |dk �rÔ|j|ƒ n|j|||ƒ n2|jtjjƒ |dk �r|j|ƒ n|j|||ƒ |j tjj!ƒ �q”W q´|d
k�r:d}t"j#|ƒ�rŒt$|ƒ}| jtjjk�rltj%|dƒ}ntj%d|ƒ}| j|||||	ƒ q´t&|
j't(ƒ |j)ƒ}|j*|ƒ}|j+}|dk�rÎ|j,�rÊd|j, nd}|
j-}|dk�rH|j.ƒ j/f |
j0Ž}|dk�rddl1m2} |ƒ }|
j3dk	�r |
j3|_3|
j4dk�r4|
j4|_4|
j5dk�rH|
j5|_5t6||
jd ƒ}|||||
j+dƒj/|
|
j7d�}|j8|ƒ |j}|
j9�rš|j:|
j9ƒ |j;|_;|
j�rÎ| j<|
||ƒ}| j|||||	|ƒ nd}||_=|
j�rê| j|ƒ |
j>�rú|j?ƒ  d}|
j@}|
jA} |dk�s| dk�r\| jtjjk}!|jBƒ }"|"j@ƒ }#|"jAƒ }$d}%d}&d|  k �o`dkn  �rz|!�rzt$d| ƒ}t$|ƒ}|dk �r˜| }d}%n
tC||#ƒ}d|   k �o¶dkn  �rÒ|! �rÒt$d|  ƒ}t$| ƒ} | dk �rð|  } d}&n
tC| |$ƒ} |jDtC|dƒƒ |jEtC| dƒƒ |dk�s,|! �r<|%�r<|jF|ƒ |dk�sL|!�r\|&�r\|jG| ƒ | jH||
||ƒ | j|||||	ƒ |
jI�pˆ|}'|jJ|'||
jIƒ | j  jK|jLO  _K|jMjN|ƒ t6||'d dƒ}(|(dk	�rÜ|jO|(ƒ |
jPdk�rö|jQ|
jP|ƒ |
jRdkr´|jS|
jR|ƒ q´W |S )zkAdds a list of Item objects, creating a layout if needed.  Return
           the outermost layout.
        Fr   Nr   r'   Zsimple)r(   Ú_r)   r¼   Ú5z
Specifies )ÚToolkitEditorFactoryZ_editor)ri   Zobject_nameg        g      ð?éd   TZ_definedr‹   r‹   r‹   r‹   r‹   r‹   )Tr   rR   Úhandlerrz   Ú	show_leftÚcolumnsZ
show_labelr   ZQGridLayoutr<   r   rA   Ú
AlignRightrc   r›   r�   ÚnamerŸ   Ústyler½   r:   r   Ú_add_widgetÚ
emphasizedÚ_add_emphasisÚranger=   rœ   ZsetFrameShapeZVLiner9   r?   ZsetFrameShadowr>   Ú
all_digitsÚmatchrŽ   ZQSpacerItemÚevalÚobject_Úglobalsr   Z
base_traitZtooltipÚdescr·   Z
get_editorÚ	trait_setZeditor_argsZtext_editorrÀ   Zformat_funcZ
format_strÚinvalidr€   r   Zpreparer±   r²   ÚenabledÚ_create_labelÚlabel_controlZ	has_focusZsetFocusrm   rn   ZminimumSizeHintÚmaxZsetMinimumWidthZsetMinimumHeightZsetMaximumWidthZsetMaximumHeightÚ_set_item_size_policyr¸   r¹   Z_scrollablerV   Z_editorsru   Zadd_definedr¬   rº   r­   r»   ))r%   rX   r³   r   rR   rÂ   rz   rÃ   rÄ   Úshow_labelsri   rµ   ÚrowÚlabel_alignmentÚcolrÆ   rŸ   Úcolsr’   ÚlineÚnÚspacerr   ZtraitrÑ   Zeditor_factoryrÀ   Zfactory_methodr·   r   ÚstretchZ
item_widthZitem_heightZis_horizontalZmin_sizerm   rn   Zforce_widthZforce_heightr¸   Zdefinedr   r   r   r°   ¸  s0   


















"

$






z_GroupPanel._add_itemsc       	      C   sÔ   | j j}|jdkp |jtko |j}|j}|jjƒ jƒ }|dk	rž| rž|t	j
jkrž| jt	jjkrx|rxd}| j||prdƒ n&| jt	jjkrž|ržd}| j||pšdƒ |r²|p¨d}d| _n|r¾|p¼d}|j| j|||ƒ |S )ah   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–   )rz   rÃ   Z	resizabler   rV   Zspringyr   r¡   ZhorizontalPolicyr   r£   ZMinimumr�   r›   rœ   Ú_make_label_h_stretchablerž   Zset_size_policy)	r%   r·   ri   rŸ   rá   Zis_label_leftZis_item_resizableZis_item_springyZitem_policyr   r   r   rØ   Ú  s0    

z!_GroupPanel._set_item_size_policyc             C   s.   |j ƒ }|j|ƒ |j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á   Zlabel_policyr   r   r   râ     s
    

z%_GroupPanel._make_label_h_stretchabler   c             C   s  t |tjƒr,|jƒ }|dk	r,|jddddƒ |dk rpt |tjƒrL|j|ƒ n"t |tjƒrd|j|ƒ n
|j|ƒ nž| j	tj
jkrˆ|| }}|r¾|d9 }|dkr¦| jj s¶|dkr¾| jjr¾|d7 }t |tjƒrÜ|j||||ƒ n2t |tjƒrú|j||||ƒ n|j|||dd|ƒ dS )zqAdds a widget to a layout taking into account the orientation and
           the position of any labels.
        Nr   r)   r   )r2   r   r6   rG   r8   r9   r;   r<   re   r�   r›   rœ   rz   rÃ   )r%   rG   rF   rÚ   ÚcolumnrÙ   rÛ   Zwlr   r   r   rÈ     s,    
z_GroupPanel._add_widgetú:c             C   sj   |j |ƒ}|dkr.|d tkr.| jjr.|| }tj|ƒ}|jrH| j|ƒ |j|ƒ|_	|dkrf|j
|ƒ |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

        r'   r   r‹   )r\   ÚLABEL_PUNCTUATION_CHARSrz   rÃ   r   r½   rÉ   rÊ   rw   r/   Z
setToolTip)r%   ri   r   rÑ   ÚsuffixrŸ   rÖ   r   r   r   rÕ   H  s     



z_GroupPanel._create_labelc             C   sf   t j|jƒ ƒ}|jt jjt jdddƒƒ |j|ƒ t j|jƒ ƒ}|j	dƒ |j
|jƒ ƒ |j|ƒ dS )z5Adds emphasis to a specified control's font.
        r   é   TN)r   ZQPaletteZpaletteZsetColorZ
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ä   )rN   rO   rP   rQ   rJ   r©   r¨   rª   r¯   r°   rØ   râ   r   rA   ZAlignmentFlagrÈ   rÕ   rÊ   r   r   r   r   rT   â  s   
 
  $7*
9rT   c               @   s   e Zd ZdZdd„ ZdS )r®   z8 A pseudo-editor that allows a group to be managed.
    c             K   s   | j f |Ž dS )z  Initialise the object.
        N)rÒ   )r%   Útraitsr   r   r   rJ   ”  s    zGroupEditor.__init__N)rN   rO   rP   rQ   rJ   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§   zN A pseudo-editor that allows a group with a 'split' layout to be managed.
    c             C   s2   t |tƒr|jdƒ}n|}d| j_| jj|ƒ dS )z` Restores any saved user preference information associated with the
            editor.
        Ú	structureTN)r2   Údictr   r—   r‡   ZrestoreState)r%   Úprefsrê   r   r   r   r    £  s
    
z!SplitterGroupEditor.restore_prefsc             C   s   d| j jƒ jƒ iS )zM Returns any user preference information associated with the editor.
        rê   )r—   Z	saveStateÚdata)r%   r   r   r   Ú
save_prefs¯  s    zSplitterGroupEditor.save_prefsN)	rN   rO   rP   rQ   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«   za A pseudo-editor that allows a group with a 'tabbed' or 'fold' layout to
        be managed.
    c             C   s.   t |tƒr|jdƒ}n|}| jjt|ƒƒ dS )z` Restores any saved user preference information associated with the
            editor.
        Úcurrent_indexN)r2   rë   r   rš   rf   rŽ   )r%   rì   rï   r   r   r   r    ¿  s    
z#TabbedFoldGroupEditor.restore_prefsc             C   s   dt | jjƒ ƒiS )zM Returns any user preference information associated with the editor.
        rï   )Ústrrš   ZcurrentIndex)r%   r   r   r   rî   Ê  s    z TabbedFoldGroupEditor.save_prefsN)rN   rO   rP   rQ   r   rš   r    rî   r   r   r   r   r«   µ  s   r«   c               @   s   e Zd ZdZdd„ ZdS )ry   zH Window for displaying Traits-based help text with HTML formatting.
    c       	      C   s¨   ddl m} tjj| |ƒ tj| ƒ}|jddddƒ |jƒ }|jtj	j
tj	j
ƒ |j|ƒ |j|ƒ tjtjjtjjƒ}|jj| jƒ |j|ƒ t| |d� | jƒ  dS )z! Initializes the object.
        r   )ÚQtWebKit)r   N)Ú	pyface.qtrñ   r   r4   rJ   r7   r8   ZQWebViewr¦   r£   r¤   ZsetHtmlr9   r@   ZOkr   rA   rB   ZacceptedÚconnectÚacceptr   Úshow)	r%   r   r~   Zscale_dxZscale_dyrñ   rG   Zhtml_controlrI   r   r   r   rJ   Ü  s    







zHTMLHelpWindow.__init__N)rN   rO   rP   rQ   rJ   r   r   r   r   ry   Ô  s   ry   c              O   s   t dkrddlm a  t | |ŽS )z)Create a PyFace HeadingText control.
    Nr   )ÚHeadingText)rö   Z
pyface.api)ÚargsÚkwr   r   r   r:   þ  s    r:   )N)4rQ   Ú
__future__r   r   rr   Úrerò   r   r   Z
traits.apir   r   r   Ztraitsui.apir	   Ztraitsui.undor
   Ztraitsui.help_templater   Ztraitsui.menur   r   r   Úhelperr   Zui_baser   r·   r   rå   ÚcompilerÌ   r   r   r   r   r0   rU   rD   r   rƒ   r…   r„   r   rT   r®   r§   r«   r4   ry   rö   r:   r   r   r   r   Ú<module>   sJ   

 %
3Y     3
'