a
    §ˆc  ã                   @   sh   d Z ddlZddlZ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 )z A Layered panel. é    N)ÚDictÚStr)ÚImageé   )ÚExpandableHeader)ÚImageResource)ÚLayoutWidgetc                       s€   e Zd ZdZejZeedƒƒZ	eedƒƒZ
eeƒZeeƒZd‡ fdd„	Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚExpandablePanelz An expandable panel. Zmycarat1Zmycarat2Nc                    s>   |  dd¡}tƒ jf d|i|¤Ž |r:|  ¡  t dt¡ dS )z Creates a new LayeredPanel. Ú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 behaviourN)ÚpopÚsuperÚ__init__r
   ÚwarningsÚwarnÚPendingDeprecationWarning)Úselfr   Ztraitsr
   ©Ú	__class__© ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/ui/wx/expandable_panel.pyr   *   s    üzExpandablePanel.__init__c                 C   sX   | j }| j  ¡ }| j||d�}| |dtj¡ | |dtj¡ | |d¡ || j|< |S )z— Adds a layer with the specified name.

        All layers are hidden when they are added.  Use 'show_layer' to make a
        layer visible.

        )Útextr   r   F)ÚcontrolÚGetSizerÚ_create_headerÚAddÚwxÚEXPANDÚShowÚ_layers)r   ÚnameZlayerr   ÚsizerÚheaderr   r   r   Ú	add_panel?   s    

zExpandablePanel.add_panelc                 C   sH   || j vrdS | j ¡ }| j | }| j| }| ¡  | ¡  | ¡  dS )z3 Removes a layer and its header from the container.N)r   r   r   Ú_headersZDestroyÚLayout)r   r    r!   Úpanelr"   r   r   r   Úremove_panelZ   s    



zExpandablePanel.remove_panelc                 C   s6   t j|d| jd�}t  t j¡}| |¡ | d¡ |S )zA Create the toolkit-specific control that represents the widget. éÿÿÿÿ©ÚstyleT)r   ÚPanelÚSTYLEÚBoxSizerZVERTICALÚSetSizerÚSetAutoLayout)r   r   r&   r!   r   r   r   Ú_create_controln   s
    

zExpandablePanel._create_controlc                 C   sŽ   t  t j¡}t j|dt jd�}| |¡ | d¡ t||dd�}| ¡  | 	|j
dt j¡ | | jd¡ | | jd¡ | |¡ || j|< |S )	z Creates a panel header. r(   r)   TF)Útitler
   r   Zpanel_expandedZpanel_closed)r   r-   Z
HORIZONTALr+   ÚCLIP_CHILDRENr.   r/   r   r
   r   r   r   ZobserveÚ
_on_buttonÚ_on_panel_closedZFitr$   )r   r   r   r!   r&   Úheadingr   r   r   r   x   s    



zExpandablePanel._create_headerc                 C   st   |j }|j}|j}| j ¡ }| | j| |¡ | ¡  | j ¡  	¡ \}}| j 
|d |d f¡ | j 
||f¡ dS )z< called when one of the expand/contract buttons is pressed. r   N)Únewr1   Ústater   r   r   r   r%   ZGetSizeZGetZSetSize)r   Úeventr"   r    Zvisibler!   ÚwÚhr   r   r   r3   “   s    
zExpandablePanel._on_buttonc                 C   s   |j }|j}|  |¡ dS )z6 Called when the close button is clicked in a header. N)r6   r1   r'   )r   r8   r"   r    r   r   r   r4   £   s    z ExpandablePanel._on_panel_closed)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r2   r,   r   r   Zcollapsed_imageZexpanded_imager   r   r   r$   r   r#   r'   r0   r   r3   r4   Ú__classcell__r   r   r   r   r	      s   
r	   )r>   r   r   Z
traits.apir   r   Zpyface.ui_traitsr   Zexpandable_headerr   Zimage_resourcer   Zlayout_widgetr   r	   r   r   r   r   Ú<module>   s   