a
    §ˆc  ã                   @   s|   d 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.
é    N)Ú	HasTraitsÚIntÚInstanceÚStrÚCallable)ÚEditoré   )ÚWindowColorÚOKColorÚ
ErrorColorc                   @   st   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„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )r   z5Base class for wxPython editors for Traits-based UIs.é   c                 C   s   |dur| |_ dS )z(Handles the **control** trait being set.N)Z_editor)ÚselfÚcontrol© r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/editor.pyÚ_control_changed.   s    zEditor._control_changedc                 C   s   | j dur| j  ¡  dS )z8Assigns focus to the editor's underlying toolkit widget.N)r   ZSetFocus©r   r   r   r   Ú	set_focus3   s    
zEditor.set_focusc                 C   s$   | j }| j ¡ |kr | j |¡ dS ©z[Updates the editor when the object trait changes externally to the
        editor.
        N)Z	str_valuer   ZGetValueZSetValue)r   Ú	new_valuer   r   r   Úupdate_editor8   s    zEditor.update_editorc                 C   s   |  |¡ dS )z)Sets the tooltip for a specified control.N)Z
SetToolTip)r   r   Útextr   r   r   Úset_tooltip_text@   s    zEditor.set_tooltip_textc                 C   sD   | j }|dur | |¡ | ¡  | jdur@| j |¡ | j ¡  dS )z:Handles the **enabled** state of the editor being changed.N)r   ZEnableÚRefreshÚlabel_control)r   Zenabledr   r   r   r   Ú_enabled_changedD   s    

zEditor._enabled_changedc                 C   sœ   | j }| ¡ }| ¡ }ddlm} t||ƒr^| ¡  d¡}|D ]}|j |u r>||_q>| 	¡  n:| j
durt| j
 |¡ | |¡ |du r�| 	¡  n| 	¡  dS )z: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_changedN   s     





zEditor._visible_changedc                 C   s   | j S )z9Returns the editor's control for indicating error status.)r   r   r   r   r   Úget_error_controlk   s    zEditor.get_error_controlc                 C   s   dS )z7Returns whether or not the editor is in an error state.Fr   r   r   r   r   Úin_error_stateo   s    zEditor.in_error_stateNc                 C   sª   |du r| j }|p|  ¡ }|du r.|  ¡ p,g }t|tƒs>|g}|D ]b}|rjt}t|ddƒdu r’| ¡ |_n(t|ddƒ}|du r’t	}t|t
jƒr’t}| |¡ | ¡  qBdS )z&Sets the editor's current error state.NÚ	_ok_color)Úinvalidr"   r!   r   Úlistr   ÚgetattrZGetBackgroundColourr#   r
   ÚwxZPanelr	   ZSetBackgroundColourr   )r   Ústater   ÚitemÚcolorr   r   r   Úset_error_states   s&    

zEditor.set_error_statec                 C   s   |   ¡  dS )z,Handles the editor's invalid state changing.N)r+   )r   r(   r   r   r   Ú_invalid_changedŽ   s    zEditor._invalid_changed)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   ZEXPANDZlayout_styleZborder_sizer   r   r   r   r   r    r!   r"   r+   r,   r   r   r   r   r   !   s   


r   c                       sL   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 )
ÚEditorWithListz*Editor for an object that contains a list.c                    sn   | j ‰ ˆ j}|dkr,|  |¡\| _| _| _nˆ d | _| _‡ fdd„| _| jj| j| jd dd� |  ¡  dS )	úInitializes the object.Ú Úvaluesc                      s   ˆ j S )N)r4   r   ©Úfactoryr   r   Ú<lambda>¯   ó    z%EditorWithList.init.<locals>.<lambda>ú[]Úui)ÚdispatchN)r6   ÚnameZparse_extended_nameÚlist_objectÚ	list_nameÚ
list_valueÚon_trait_changeÚ_list_updated)r   r   r<   r   r5   r   Úinit£   s    üýÿzEditorWithList.initc                    s(   | j j| j| jd dd� tƒ  ¡  dS )z4Disconnects the listeners set up by the constructor.r9   T)ÚremoveN)r=   r@   rA   r>   ÚsuperÚdisposer   ©Ú	__class__r   r   rE   ·   s    ÿzEditorWithList.disposec                 C   s   |   |  ¡ ¡ dS )z*Handles the monitored trait being updated.N)Úlist_updatedr?   r   r   r   r   rA   ¿   s    zEditorWithList._list_updatedc                 C   s   t ‚dS )z)Handles the monitored list being updated.N©ÚNotImplementedError)r   r4   r   r   r   rH   Ã   s    zEditorWithList.list_updated)r-   r.   r/   r0   r   r   r=   r   r>   r   r?   rB   rE   rA   rH   Ú__classcell__r   r   rF   r   r1   “   s   r1   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du r$| jj|_|j| _dS )r2   N)Úinit_uiÚ_uiÚhistoryr:   r   )r   r   r:   r   r   r   rB   Ë   s    

zEditorFromView.initc                 C   s   t ‚dS )znCreates and returns the traits UI defined by this editor.
        (Must be overridden by a subclass).
        NrI   )r   r   r   r   r   rM   Ó   s    zEditorFromView.init_uic                 C   s   dS r   r   r   r   r   r   r   Ù   s    zEditorFromView.update_editorc                    s   | j  ¡  tƒ  ¡  dS )zDisposes of the editor.N)rN   rE   rD   r   rF   r   r   rE   á   s    
zEditorFromView.dispose)	r-   r.   r/   r0   rB   rM   r   rE   rK   r   r   rF   r   rL   È   s
   rL   )r0   r'   Z
traits.apir   r   r   r   r   Ztraitsui.editorr   ZUIEditorÚ	constantsr	   r
   r   r1   rL   r   r   r   r   Ú<module>   s   r5