3
8ßL]  ã               @   st   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 ddl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.
é    )Úabsolute_import)ÚQtCoreÚQtGui)ÚUnicodeÚListÚStrÚon_trait_change)ÚToolkitEditorFactoryé   )ÚEditorc                   sX   e Zd ZdZeZeZdd„ Z‡ fdd„Z	dd„ Z
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 jr”tjƒ | _t	j
j| j_| jj| j|ƒƒ | jj| j| j jƒ | jj| j| j jd ƒ tjƒ | _| jƒ  | jj| jƒ n$tj| j|ƒƒ| _d| _| jjdƒ | j| j jddƒ | jjj| jƒ | jƒ  dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        Z_itemsNFÚlabelÚfrom)Úfactoryr   ÚitemÚ	get_labelÚuiÚvalues_traitr   ÚQToolButtonÚcontrolr   ZQtZToolButtonTextOnlyZtoolButtonStyleÚsetTextÚstring_valueÚobjectr   Ú_update_menuZQMenuÚ_menuZsetMenuÚQPushButtonZsetAutoDefaultÚ
sync_valueÚlabel_valueÚclickedÚconnectÚupdate_objectÚset_tooltip)ÚselfÚparentr   © r$   ú@/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/button_editor.pyÚinit<   s&    

zSimpleEditor.initc                s,   | j dk	r| j jj| jƒ tt| ƒjƒ  dS )z0 Disposes of the contents of an editor.
        N)r   r   Z
disconnectr    Úsuperr   Údispose)r"   )Ú	__class__r$   r%   r(   X   s    
zSimpleEditor.disposec             C   s   | j j| j|ƒƒ d S )N)r   r   r   )r"   r   r$   r$   r%   Ú_label_changed_   s    zSimpleEditor._label_changedc                sj   ˆ j jdƒ ˆ j jƒ  x<tˆ jˆ jjƒD ](}ˆ j j|ƒ}|jj	|f‡ fdd„	ƒ q(W dˆ _
ˆ j jdƒ d S )NTc                s
   ˆ j |ƒS )N)Ú_menu_selected)ÚeventÚname)r"   r$   r%   Ú<lambda>h   s    z+SimpleEditor._update_menu.<locals>.<lambda>Ú F)r   ZblockSignalsÚclearÚgetattrr   r   r   Z	addActionZ	triggeredr   Úselected_item)r"   r   Úactionr$   )r"   r%   r   b   s    
zSimpleEditor._update_menuc             C   s   || _ || _d S )N)r2   r   )r"   Z	item_namer$   r$   r%   r+   l   s    zSimpleEditor._menu_selectedc             C   s\   | j dkrdS | jdkr"| j| _n
| jj| _| jdk	rX| jjdk	rX| jj| jj| j d� dS )zf Handles the user clicking the button by setting the factory value
            on the object.
        Nr/   )Úviewr#   )r   r2   Úvaluer   r4   r   Zedit_traits)r"   r$   r$   r%   r    p   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)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r2   r&   r(   r*   r   r+   r    r6   Ú__classcell__r$   r$   )r)   r%   r   &   s   
r   c               @   s*   e Zd ZdZejejejdœZdd„ Z	dS )ÚCustomEditorzC 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j|jtj	ƒ}|ƒ | _
| j
j| j|ƒƒ |jdk	rj| j
j|jjƒ ƒ | j| j jddƒ | j
jj| jƒ | jƒ  dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        Nr   r   )r   r   r   r   r   Ú
_STYLE_MAPÚgetÚstyler   r   r   r   r   ÚimageZsetIconZcreate_iconr   r   r   r   r    r!   )r"   r#   r   r   Zbtyper$   r$   r%   r&   ›   s    
zCustomEditor.initN)
r7   r8   r9   r:   r   Z	QCheckBoxZQRadioButtonr   r=   r&   r$   r$   r$   r%   r<   ‹   s
   
r<   N)r:   Ú
__future__r   Z	pyface.qtr   r   Z
traits.apir   r   r   r   Ztraitsui.editors.button_editorr	   Úeditorr   r   r<   r$   r$   r$   r%   Ú<module>   s   e