3
8Ad]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   ún/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/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   ÚGetValueÚSetValue)r   Ú	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   ÚEnableÚRefreshÚlabel_control)r   Ú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   Ú	GetParentZGetSizerZpyface.dock.apir'   Ú
isinstanceZGetContentsZget_controlsÚvisibleÚ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GetBackgroundColourr0   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)r7   )r   r4   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/   r7   r8   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)r>   r   )Úfactoryr   r   Ú<lambda>  s    z%EditorWithList.init.<locals>.<lambda>z[]Úui)ÚdispatchN)r?   r   Zparse_extended_nameÚlist_objectÚ	list_nameÚ
list_valueÚon_trait_changeÚ_list_updated)r   r,   r   r   )r?   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)rC   rF   rG   rD   Úsuperr=   Údispose)r   )Ú	__class__r   r   rK     s    zEditorWithList.disposec             C   s   | j | jƒ ƒ dS )z4 Handles the monitored trait being updated.
        N)Úlist_updatedrE   )r   r   r   r   rG   +  s    zEditorWithList._list_updatedc             C   s   t ‚dS )z3 Handles the monitored list being updated.
        N)ÚNotImplementedError)r   r>   r   r   r   rM   4  s    zEditorWithList.list_updated)r9   r:   r;   r<   r   r   rC   r   rD   r   rE   rH   rK   rG   rM   Ú__classcell__r   r   )rL   r   r=   ö   s   	r=   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ÚhistoryrA   r   )r   r,   rA   r   r   r   rH   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)rN   )r   r,   r   r   r   rQ   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)rR   rK   rJ   rP   )r   )rL   r   r   rK   j  s    
zEditorFromView.dispose)	r9   r:   r;   r<   rH   rQ   r   rK   rO   r   r   )rL   r   rP   >  s
   
rP   )r<   Ú
__future__r   r   Z
traits.apir   r   r   r   r   Ztraitsui.editorr   ZUIEditorÚ	constantsr
   r   r   r=   rP   r   r   r   r   Ú<module>   s    DH