a
    §ˆc  ã                   @   sT   d dl mZmZ d dlmZ d dlmZ d dlmZ ddl	m
Z
 G dd„ deƒZd	S )
é    )ÚQtCoreÚQtGui)Ú	HasBorder)ÚInt)ÚAbstractTreeNodeRendereré   )Úwrap_text_with_elisionc                   @   s@   e Zd ZdZedƒZedƒZedƒZedƒZ	dd„ Z
dd	„ Zd
S )ÚWordWrapRendererz;A renderer that wraps the label text across multiple lines.r   éd   é   é   c              
   C   s$  |\}}}|   |||¡}	|jjr<|j ¡ | j }
|j ¡ }nd}
d}|j ¡ |
 | j	j }|j 
¡ | j	j
 }|j ¡ |
 | j	j | j	j }|j ¡ | j	j
 | j	j }t|	|j||ƒ}| ¡ }t|jtjjj@ ƒrè| t |j ¡ d¡¡ z*| |||||jd |¡¡}W | |¡ n| |¡ 0 dS )z%Paint word-wrapped text with elision.r   Ú
N)Ú	get_labelÚfactoryÚ
show_iconsÚdecorationSizeÚwidthÚextra_spaceÚheightÚrectÚleftÚpaddingÚtopÚrightÚbottomr   ÚfontZpenÚboolÚstater   ZQStyleZ	StateFlagZState_SelectedZsetPenZQPenZpaletteZhighlightedTextZdrawTextZdisplayAlignmentÚjoin)ÚselfÚeditorÚnodeÚcolumnÚobjectZpaint_contextZpainterÚoptionÚindexÚtextÚ
icon_widthÚicon_heightÚxÚyr   r   ÚlinesZold_penr   © r,   úc/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/tree_node_renderers.pyÚpaint$   s6    
ÿþýÿÿzWordWrapRenderer.paintc                 C   s¼   |\}}t  |j¡}|  |||¡}	|jjrB|j}
|
 ¡ }|
 ¡ }nd}d}| j	| | j
j | j
j }| j| ¡  }t|	|j||ƒ}t|ƒ| ¡  }t||ƒ| j
j | j
j | j }| j	|fS )aý  Return the preferred size for the word-wrapped text

        Parameters
        ----------
        node : ITreeNode instance
            The tree node to render.
        column : int
            The column in the tree that should be rendererd.
        object : object
            The underlying object being edited.
        size_context : object
            A toolkit-dependent context for performing sizing operations.

        Returns
        -------
        size : tuple of (width, height) or None
        r   )r   ZQFontMetricsr   r   r   r   r   r   r   Ú
width_hintr   r   r   Ú	max_linesZlineSpacingr   ÚlenÚmaxr   r   r   )r   r    r!   r"   r#   Zsize_contextr$   r%   Zfont_metricsr&   Z	icon_sizer'   r(   r   Z
max_heightr+   Ztext_heightr   r,   r,   r-   ÚsizeG   s:    
ÿþýÿÿþýÿzWordWrapRenderer.sizeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r/   r0   r   r.   r3   r,   r,   r,   r-   r	      s   #r	   N)Z	pyface.qtr   r   Zpyface.ui_traitsr   Z
traits.apir   Ztraitsui.tree_node_rendererr   Úhelperr   r	   r,   r,   r,   r-   Ú<module>   s
   