a
    §ˆc  ã                   @   sl   d Z ddlZddl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 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.
é    N)ÚEventÚStrÚBool)Únew_font_like)ÚImageé   )ÚImageResource)ÚWidgetc                       sÊ   e Zd ZdZedƒZeedƒƒZeedƒƒZ	eedƒƒZ
eedƒƒZeedƒƒZedƒZeƒ Zeƒ Zd	Zd	Zd
ZdZd‡ 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‡  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   é
   Nc                    sf   ˆ dur(t  dt¡ |  ‡ fdd„d¡ | dd¡}tƒ jf d|i|¤Ž |rb|  ¡  t  d	t¡ dS )
z Creates the panel. NzTthe container parameter is deprecated and will be removed in a future Pyface releasec                    s   ˆ   | j¡S )N)Zremove_panelÚnew)Úevent©Ú	container© úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/ui/wx/expandable_header.pyÚ<lambda>W   ó    z+ExpandableHeader.__init__.<locals>.<lambda>Úpanel_closedÚcreateTÚparentzšautomatic widget creation is deprecated and will be removed in a future Pyface version, use create=False and explicitly call create() for future behaviour)	ÚwarningsÚwarnÚDeprecationWarningZobserveÚpopÚsuperÚ__init__r   ÚPendingDeprecationWarning)Úselfr   r   Ztraitsr   ©Ú	__class__r   r   r   M   s"    ý
þüzExpandableHeader.__init__c                 C   sþ   | j  ¡ }| ¡ | _| j ¡ | _| j ¡ }| ¡ | _t 	tj
¡}tj|dtjtjB d�}| |¡ | d¡ tj |d¡}| |dtjd¡ ttjtj ¡ d d�| _|  || j| j¡}| d|d f¡ | tj| j¡ | tj| j¡ | tj | j!¡ |S )	zA Create the toolkit-specific control that represents the widget. éÿÿÿÿ)ÚstyleTr   é   r   )Z
point_sizeé   )"Úcollapsed_carat_imageZcreate_imageZConvertToBitmapÚ_collapsed_bmpZGetWidthÚ_carat_wÚexpanded_carat_imageÚ_expanded_bmpÚwxZBoxSizerZVERTICALr   ZCLIP_CHILDRENZBORDER_SIMPLEZSetSizerZSetAutoLayoutZBitmapButtonZNewCloseButtonÚAddZALIGN_RIGHTr   ZNORMAL_FONTZGetPointSizeÚ_fontÚ_get_preferred_heightÚtitleZ
SetMinSizeZBindZ	EVT_PAINTÚ	_on_paintZEVT_LEFT_DOWNÚ_on_downZ
EVT_BUTTONÚ
_on_remove)r!   r   Zcollapsed_caratZexpanded_caratZsizerZpanelÚremoveÚheightr   r   r   Ú_create_controlm   s(    





ÿz ExpandableHeader._create_controlc                 C   sH   t  ¡ }| |¡ | ¡ }|jd| j  }| j ¡ d| j  }t	||ƒS )z0 Calculates the preferred height of the widget. r'   )
r-   ZMemoryDCÚSetFontZGetFontMetricsr6   Ú_TEXT_Yr)   Z	GetHeightÚ_CARAT_YÚmax)r!   r   ÚtextÚfontÚdcZmetricsZtext_hZcarat_hr   r   r   r0   �   s    
z&ExpandableHeader._get_preferred_heightc                 C   s,   | j r| j}n| j}| || j| jd¡ dS )z. Draws the button at the correct coordinates. TN)Ústater,   r)   Z
DrawBitmapÚ_CARAT_Xr:   )r!   r>   Zbmpr   r   r   Ú_draw_carat_button�   s    z#ExpandableHeader._draw_carat_buttonc                 C   s*   |  | 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   s   |   |¡ |  |¡ dS )z Draws the control. N)rD   rA   rC   r   r   r   Ú_draw°   s    
zExpandableHeader._drawc                 C   s   t  | j¡}|  |¡ dS )z4 Called when the background of the panel is erased. N)r-   ZPaintDCÚcontrolrE   )r!   r   r>   r   r   r   r2   ½   s    zExpandableHeader._on_paintc                 C   s&   | j  | _ | j ¡  | | _| ¡  dS )z  Called when button is pressed. N)r?   rF   ZRefreshÚpanel_expandedZSkip©r!   r   r   r   r   r3   Ä   s    

zExpandableHeader._on_downc                 C   s
   | | _ dS )z' Called when remove button is pressed. N)r   rH   r   r   r   r4   Î   s    zExpandableHeader._on_remove)NN) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r1   r   r   r(   r+   Zheader_bar_imageZheader_mouseover_imageZremove_imager   r?   r   rG   r   r@   r:   r9   rB   r   r7   r0   rA   rD   rE   r2   r3   r4   Ú__classcell__r   r   r"   r   r
      s.    "
	
r
   )rL   r   r-   Z
traits.apir   r   r   Zpyface.wx.util.font_helperr   Zpyface.ui_traitsr   Zimage_resourcer   Zwidgetr	   r
   r   r   r   r   Ú<module>   s   