3
7ßL]_  ã               @   sh   d Z ddlmZ ddl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 G d	d
„ d
eƒZdS )z™ A header for an entry in a collection of expandables. The header
provides a visual indicator of the current state, a text label, and a
'remove' button. é    )Úabsolute_importN)ÚInstanceÚEventÚStrÚBool)Únew_font_likeé   )ÚImageResource)ÚWidgetc                   sÚ   e Zd ZdZedƒZeeedƒƒZeeedƒƒZ	eeedƒƒZ
eeedƒƒZeeedƒƒZedƒZeZd	Zd
ZdZdZ‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Z‡  Z S )#ÚExpandableHeaderz¡ A header for an entry in a collection of expandables. The header
    provides a visual indicator of the current state, a text label, and a
    'remove' button. ÚPanelZcarat_closedZ
carat_openZpanel_gradientZpanel_gradient_overÚcloseFé   é   r   é
   c                s(   t t| ƒjf |Ž | j|ƒ| _|| _dS )z Creates the panel. N)Úsuperr   Ú__init__Ú_create_controlÚcontrolÚ
_container)ÚselfÚparentÚ	containerZtraits)Ú	__class__© úB/tmp/pip-install-5sebvq2j/pyface/pyface/ui/wx/expandable_header.pyr   G   s    zExpandableHeader.__init__c             C   sv  | j jƒ }|jƒ | _| jjƒ | _| jjƒ }|jƒ | _| jjƒ }|jƒ | _	| j
jƒ }|jƒ | _| j	| _| jjƒ }|jƒ | _tjtjƒ}tj|d	tjd�}|j|ƒ |jdƒ |jtjƒ tj|d
| jddd�}	|j|	dtjdƒ ttjtjjƒ d d�| _| j|| j | jƒ}
|j!d|
fƒ tj"|| j#ƒ tj$|| j%ƒ tj&|| j%ƒ tj'|| j(ƒ tj)|| j(ƒ tj*||	j+ƒ | j,ƒ |S )zA Create the toolkit-specific control that represents the widget. r   )ÚstyleTr   é   )r   Úposé   )Z
point_sizeéÿÿÿÿr    r    )r    r   r    )-Úcollapsed_carat_imageZcreate_imageZConvertToBitmapÚ_collapsed_bmpÚGetWidthÚ_carat_wÚexpanded_carat_imageÚ_expanded_bmpÚheader_bar_imageÚ_header_bmpÚheader_mouseover_imageÚ_header_mouseover_bmpÚ_background_bmpÚremove_imageZ_remove_bmpÚwxZBoxSizerZVERTICALr   ZCLIP_CHILDRENZSetSizerZSetAutoLayoutZSetBackgroundStyleZBG_STYLE_CUSTOMZBitmapButtonÚAddZALIGN_RIGHTr   ZNORMAL_FONTZGetPointSizeÚ_fontÚ_get_preferred_heightÚtitleZSetSizeZEVT_ERASE_BACKGROUNDÚ_on_erase_backgroundZEVT_ENTER_WINDOWÚ_on_enter_leaveZEVT_LEAVE_WINDOWZEVT_LEFT_DOWNÚ_on_downZEVT_RIGHT_DOWNZ
EVT_BUTTONZGetIdÚ
_on_remove)r   r   Zcollapsed_caratZexpanded_caratZ
header_barZheader_bar_overZclose_imageZsizerZpanelÚremoveÚheightr   r   r   r   W   s>    











z ExpandableHeader._create_controlc             C   sD   t jƒ }|j|ƒ |j|ƒ\}}|| j }| jjƒ | j }t||ƒS )z0 Calculates the preferred height of the widget. )	r-   ZMemoryDCÚSetFontZGetTextExtentÚ_TEXT_Yr"   Ú	GetHeightÚ_CARAT_YÚmax)r   r   ÚtextÚfontÚdcZtext_wZtext_hZcarat_hr   r   r   r0   ‹   s    

z&ExpandableHeader._get_preferred_heightc             C   s,   | j r| j}n| j}|j|| j| jdƒ dS )z. Draws the button at the correct coordinates. TN)Ústater&   r"   Ú
DrawBitmapÚ_CARAT_Xr;   )r   r?   Zbmpr   r   r   Ú_draw_carat_button™   s
    z#ExpandableHeader._draw_carat_buttonc             C   s\   | j jƒ }| j jƒ }d}x>||k rVd}x$||k rJ|j| j ||ƒ || }q(W || }qW dS )z Tiles the background image. r   N)r+   r#   r:   rA   )r   r?   Úwidthr7   ÚwÚhÚxÚyr   r   r   Ú_tile_background_image¥   s    



z'ExpandableHeader._tile_background_imagec             C   s*   |j | jƒ |j| j| j| j | jƒ dS )z& Draws the text label for the header. N)r8   r/   ZDrawTextr1   r$   Ú_TEXT_X_OFFSETr9   )r   r?   r   r   r   Ú_draw_title·   s    zExpandableHeader._draw_titlec             C   s4   | j jƒ }| j||j|jƒ | j|ƒ | j|ƒ dS )z Draws the control. N)r   ZGetClientSizerI   rD   r7   rK   rC   )r   r?   Úsizer   r   r   Ú_draw¿   s
    


zExpandableHeader._drawc             C   s   |j ƒ }| j|ƒ dS )z4 Called when the background of the panel is erased. N)ZGetDCrM   )r   Úeventr?   r   r   r   r2   Ò   s    
z%ExpandableHeader._on_erase_backgroundc             C   s0   |j ƒ r| j| _n| j| _| jjƒ  |jƒ  dS )z  Called when button is pressed. N)ZEnteringr*   r+   r(   r   ÚRefreshÚSkip)r   rN   r   r   r   r3   Ú   s
    

z ExpandableHeader._on_enter_leavec             C   s&   | j  | _ | jjƒ  | | _|jƒ  dS )z  Called when button is pressed. N)r@   r   rO   Úpanel_expandedrP   )r   rN   r   r   r   r4   æ   s    

zExpandableHeader._on_downc             C   s   | j j| jƒ dS )z' Called when remove button is pressed. N)r   Zremove_panelr1   )r   rN   r   r   r   r5   ñ   s    zExpandableHeader._on_remove)!Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r   r	   r!   r%   r'   r)   r,   r   r@   r   rQ   rB   r;   r9   rJ   r   r   r0   rC   rI   rK   rM   r2   r3   r4   r5   Ú__classcell__r   r   )r   r   r      s4   

4r   )rU   Ú
__future__r   r-   Z
traits.apir   r   r   r   Zpyface.wx.util.font_helperr   Zimage_resourcer	   Zwidgetr
   r   r   r   r   r   Ú<module>   s   