a
    §ˆc   ã                   @   sh   d Z ddlmZmZ ddlmZ ddlmZmZm	Z	m
Z
 ddlmZ G dd„ deƒZG d	d
„ d
eƒZdS )zI Defines the various button editors for the PyQt user interface toolkit.
é    )ÚQtCoreÚQtGui)ÚImage)ÚListÚStrÚobserveÚon_trait_changeé   )ÚEditorc                       s^   e Zd ZdZeƒ Zeƒ Zdd„ Z‡ fdd„Zdd„ Z	dd	d
„Z
dd„ Zdd„ Zdd„ Z‡  ZS )ÚSimpleEditorz!Simple style editor for a button.c                 C   sÞ   | j jp| j | j¡}| j jr‚t ¡ | _t	j
jj| j_| j |  |¡¡ | j | j| j jd ¡ t ¡ | _|  ¡  | j | j¡ n$t |  |¡¡| _d| _| j d¡ |  | j jdd¡ | jjj| jt	j
jjd� |  ¡  dS )ú\Finishes initializing the editor by creating the underlying toolkit
        widget.
        ú.itemsNFÚlabelÚfrom)Útype) Úfactoryr   ÚitemÚ	get_labelÚuiÚvalues_traitr   ÚQToolButtonÚcontrolr   ZQtZToolButtonStyleZToolButtonTextOnlyZtoolButtonStyleÚsetTextÚstring_valueÚobjectr   Ú_update_menuZQMenuÚ_menuZsetMenuÚQPushButtonZsetAutoDefaultÚ
sync_valueÚlabel_valueÚclickedÚconnectÚupdate_objectZConnectionTypeZQueuedConnectionÚset_tooltip)ÚselfÚparentr   © r&   ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/button_editor.pyÚinit3   s(    
ÿ
þzSimpleEditor.initc                    sL   | j jr$| jj| j| j jd dd� | jdur>| jj | j¡ t	ƒ  
¡  dS )ú&Disposes of the contents of an editor.r   T)ÚremoveN)r   r   r   r   r   r   r    Ú
disconnectr"   ÚsuperÚdispose©r$   ©Ú	__class__r&   r'   r-   U   s    
ý
zSimpleEditor.disposec                 C   s   | j  |  |¡¡ d S ©N)r   r   r   )r$   r   r&   r&   r'   Ú_label_changedc   s    zSimpleEditor._label_changedNc                    sf   ˆ j  d¡ ˆ j  ¡  tˆ jˆ jjƒD ](}ˆ j  |¡}|j 	|f‡ fdd„	¡ q&dˆ _
ˆ j  d¡ d S )NTc                    s
   ˆ   |¡S r1   )Ú_menu_selected)ÚeventÚnamer.   r&   r'   Ú<lambda>l   ó    z+SimpleEditor._update_menu.<locals>.<lambda>Ú F)r   ZblockSignalsÚclearÚgetattrr   r   r   Z	addActionZ	triggeredr!   Úselected_item)r$   r4   r   Úactionr&   r.   r'   r   f   s    
ÿzSimpleEditor._update_menuc                 C   s   || _ || _d S r1   )r;   r   )r$   Z	item_namer&   r&   r'   r3   q   s    zSimpleEditor._menu_selectedc                 C   s\   | j du rdS | jdkr"| j| _n
| jj| _| jdurX| jjdurX| jj| jj| j d� dS )zaHandles the user clicking the button by setting the factory value
        on the object.
        Nr8   )Úviewr%   )r   r;   Úvaluer   r=   r   Zedit_traitsr.   r&   r&   r'   r"   u   s    




ÿzSimpleEditor.update_objectc                 C   s   dS )z[Updates the editor when the object trait changes externally to the
        editor.
        Nr&   r.   r&   r&   r'   Úupdate_editor†   s    zSimpleEditor.update_editor)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r;   r(   r-   r2   r   r3   r"   r?   Ú__classcell__r&   r&   r/   r'   r   #   s   "
r   c                   @   sH   e Zd ZdZeƒ Zejejej	dœZ
dd„ Zedƒdd„ ƒZdd	„ Zd
S )ÚCustomEditorz=Custom style editor for a button, which can contain an image.)ZcheckboxZradioZtoolbarc                 C   sª   | j }|jr|j}n| j | j¡}| j |jtj	¡}|ƒ | _
| j
 |  |¡¡ |jdurj| j
 |j ¡ ¡ |  | j jdd¡ |  | j jdd¡ | j
j | j¡ |  ¡  dS )r   Nr   r   Úimage)r   r   r   r   r   Ú
_STYLE_MAPÚgetÚstyler   r   r   r   r   rF   ÚsetIconÚcreate_iconr   r   Zimage_valuer    r!   r"   r#   )r$   r%   r   r   Zbtyper&   r&   r'   r(   š   s    
zCustomEditor.initrF   c                 C   s   |j }| j | ¡ ¡ d S r1   )Únewr   rJ   rK   )r$   r4   rF   r&   r&   r'   Ú_image_updated±   s    zCustomEditor._image_updatedc                 C   s(   | j dur| j j | j¡ t | ¡ dS )r)   N)r   r    r+   r"   r
   r-   r.   r&   r&   r'   r-   ¶   s    
zCustomEditor.disposeN)r@   rA   rB   rC   r   rF   r   Z	QCheckBoxZQRadioButtonr   rG   r(   r   rM   r-   r&   r&   r&   r'   rE   �   s   ý
rE   N)rC   Z	pyface.qtr   r   Z
pyface.apir   Z
traits.apir   r   r   r   Zeditorr
   r   rE   r&   r&   r&   r'   Ú<module>   s   j