3
8ßL]s5  ã               @   sˆ   d Z ddlmZ ddlZddlmZmZmZmZm	Z	 ddl
mZ ddlmZmZmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZdS )z. Defines the base class for wxPython editors.
é    )Úabsolute_importN)Ú	HasTraitsÚIntÚInstanceÚStrÚCallable)ÚEditoré   )ÚWindowColorÚOKColorÚ
ErrorColorc               @   s~   e Zd ZdZeejƒZedƒZdd„ Z	dd„ Z
dd„ Zd	d
„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )r   z; Base class for wxPython editors for Traits-based UIs.
    é   c             C   s   |dk	r| |_ dS )z2 Handles the **control** trait being set.
        N)Z_editor)ÚselfÚcontrol© r   ú8/tmp/pip-install-5sebvq2j/traitsui/traitsui/wx/editor.pyÚ_control_changedE   s    zEditor._control_changedc             C   s   | j dk	r| j jƒ  dS )zB Assigns focus to the editor's underlying toolkit widget.
        N)r   ZSetFocus)r   r   r   r   Ú	set_focusO   s    
zEditor.set_focusc             C   s$   | j }| jjƒ |kr | jj|ƒ dS )z` Updates the editor when the object trait changes externally to the
            editor.
        N)Z	str_valuer   ZGetValueZSetValue)r   Z	new_valuer   r   r   Úupdate_editorY   s    zEditor.update_editorc             C   s8   t j| jt|ƒ| jd t jt jB ƒ}|jƒ  |jƒ  dS )zN Handles an error that occurs while setting the object's trait value.
        z value errorN)	ÚwxZMessageDialogr   ÚstrÚdescriptionÚOKZICON_INFORMATIONZ	ShowModalZDestroy)r   ZexcpZdlgr   r   r   Úerrore   s
    zEditor.errorNc             C   sf   | j }|dkrJ| jj| jƒj}|dkrJ| jj| jƒj}|dkrBdS d| }|dkrX| j}|j|ƒ dS )z3 Sets the tooltip for a specified control.
        Ú NFz
Specifies T)r   ÚobjectZ
base_traitÚnameZtooltipÚdescr   ZSetToolTipString)r   r   r   r   r   r   Úset_tooltipr   s    
zEditor.set_tooltipc             C   sD   | j }|dk	r |j|ƒ |jƒ  | jdk	r@| jj|ƒ | jjƒ  dS )zD Handles the **enabled** state of the editor being changed.
        N)r   ZEnableÚRefreshÚlabel_control)r   Zenabledr   r   r   r   Ú_enabled_changedŠ   s    

zEditor._enabled_changedc             C   s    | j }|jƒ }|jƒ }ddlm} t||ƒrb|jƒ jdƒ}x|D ]}|j |kr@||_q@W |j	ƒ  n:| j
dk	rx| j
j|ƒ |j|ƒ |dkr”|j	ƒ  n|j	ƒ  dS )zD Handles the **visible** state of the editor being changed.
        r   )Ú	DockSizerFN)r   Z	GetParentZGetSizerZpyface.dock.apir"   Ú
isinstanceZGetContentsZget_controlsÚvisibleZLayoutr    ZShow)r   r$   r   ÚparentZsizerr"   Zdock_controlsZdock_controlr   r   r   Ú_visible_changed™   s     







zEditor._visible_changedc             C   s   | j S )zC Returns the editor's control for indicating error status.
        )r   )r   r   r   r   Úget_error_controlº   s    zEditor.get_error_controlc             C   s   dS )zA Returns whether or not the editor is in an error state.
        Fr   )r   r   r   r   Úin_error_stateÃ   s    zEditor.in_error_statec             C   s®   |dkr| j }|p| jƒ }|dkr.| jƒ p,g }t|tƒs>|g}xj|D ]b}|rlt}t|ddƒdkr”|jƒ |_n(t|ddƒ}|dkr”t	}t|t
jƒr”t}|j|ƒ |jƒ  qDW dS )z0 Sets the editor's current error state.
        NÚ	_ok_color)Úinvalidr(   r'   r#   Úlistr   ÚgetattrZGetBackgroundColourr)   r   r   ZPanelr
   ZSetBackgroundColourr   )r   Ústater   ÚitemÚcolorr   r   r   Úset_error_stateÌ   s&    


zEditor.set_error_statec             C   s   | j ƒ  dS )z6 Handles the editor's invalid state changing.
        N)r0   )r   r-   r   r   r   Ú_invalid_changedì   s    zEditor._invalid_changed)N)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ZEXPANDZlayout_styleZborder_sizer   r   r   r   r   r!   r&   r'   r(   r0   r1   r   r   r   r   r   3   s   



!		
 r   c                   sH   e Zd ZdZeeƒZeZe	Z
dd„ Z‡ fdd„Zdd„ Zdd	„ Z‡  ZS )
ÚEditorWithListz0 Editor for an object that contains a list.
    c                sn   | j ‰ ˆ j}|dkr,| j|ƒ\| _| _| _nˆ d | _| _‡ fdd„| _| jj| j| jd dd� | jƒ  dS )	z! Initializes the object.
        r   Úvaluesc                  s   ˆ j S )N)r7   r   )Úfactoryr   r   Ú<lambda>  s    z%EditorWithList.init.<locals>.<lambda>z[]Úui)ÚdispatchN)r8   r   Zparse_extended_nameÚlist_objectÚ	list_nameÚ
list_valueÚon_trait_changeÚ_list_updated)r   r%   r   r   )r8   r   Úinit
  s    zEditorWithList.initc                s,   | j j| j| jd dd� tt| ƒjƒ  dS )z> Disconnects the listeners set up by the constructor.
        z[]T)ÚremoveN)r<   r?   r@   r=   Úsuperr6   Údispose)r   )Ú	__class__r   r   rD     s    zEditorWithList.disposec             C   s   | j | jƒ ƒ dS )z4 Handles the monitored trait being updated.
        N)Úlist_updatedr>   )r   r   r   r   r@   +  s    zEditorWithList._list_updatedc             C   s   t ‚dS )z3 Handles the monitored list being updated.
        N)ÚNotImplementedError)r   r7   r   r   r   rF   4  s    zEditorWithList.list_updated)r2   r3   r4   r5   r   r   r<   r   r=   r   r>   rA   rD   r@   rF   Ú__classcell__r   r   )rE   r   r6   ö   s   	r6   c                   s8   e Zd ZdZdd„ Zdd„ Zdd„ Z‡ fdd	„Z‡  ZS )
ÚEditorFromViewz- An editor generated from a View object.
    c             C   s0   | j |ƒ | _}|jdkr$| jj|_|j| _dS )z! Initializes the object.
        N)Úinit_uiÚ_uiÚhistoryr:   r   )r   r%   r:   r   r   r   rA   F  s    

zEditorFromView.initc             C   s   t ‚dS )zs Creates and returns the traits UI defined by this editor.
            (Must be overridden by a subclass).
        N)rG   )r   r%   r   r   r   rJ   T  s    zEditorFromView.init_uic             C   s   dS )z` Updates the editor when the object trait changes externally to the
            editor.
        Nr   )r   r   r   r   r   ^  s    zEditorFromView.update_editorc                s   | j jƒ  tt| ƒjƒ  dS )z! Disposes of the editor.
        N)rK   rD   rC   rI   )r   )rE   r   r   rD   j  s    
zEditorFromView.dispose)	r2   r3   r4   r5   rA   rJ   r   rD   rH   r   r   )rE   r   rI   >  s
   
rI   )r5   Ú
__future__r   r   Z
traits.apir   r   r   r   r   Ztraitsui.editorr   ZUIEditorÚ	constantsr
   r   r   r6   rI   r   r   r   r   Ú<module>   s    DH