3
8ßL]C+  ã               @   sœ   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ dd	lmZ ejZejZG d
d„ de
ƒZG dd„ deƒZG dd„ deƒZeZdS )zK Defines the various text editors for the wxPython user interface toolkit.
é    )Úabsolute_importN)Ú
TraitError)ÚToolkitEditorFactoryÚevaluate_traité   )ÚEditor)ÚReadonlyEditor)ÚOKColorc               @   sL   e Zd ZdZdZeZeZdd„ Z	dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ ZdS )ÚSimpleEditorz< Simple style text editor, which displays a text field.
    r   c             C   sú   | j }| j}|j| _| j|jddƒ |j s2|jr>|tj M }|jrN|tj	O }|tj@ dk}|rfd| _
|jr¢| r¢tj|d	| j|tjB d�}tj||jƒ | jƒ ntj|d
| j|d�}tj|| jƒ |jrÞtj||jƒ | jƒ || _| jdƒ | jƒ  dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        ÚevaluateÚfromr   Tr   )ÚstyleFNéÿÿÿÿr   )ÚfactoryÚ
base_styler   Z
sync_valueZevaluate_nameÚ
multi_lineÚpasswordÚwxÚTE_MULTILINEZTE_PASSWORDZ
scrollableZ	enter_setZTextCtrlÚ	str_valueZTE_PROCESS_ENTERZEVT_TEXT_ENTERZGetIdÚupdate_objectZEVT_KILL_FOCUSZauto_setZEVT_TEXTÚcontrolÚset_error_stateZset_tooltip)ÚselfÚparentr   r   r   r   © r   ú=/tmp/pip-install-5sebvq2j/traitsui/traitsui/wx/text_editor.pyÚinitQ   s,    

zSimpleEditor.initc             C   s†   t |tjƒr|jƒ  | j r‚| jdk	r‚y8| jƒ | _| jdk	rRd| _| j	 j
d8  _
| jdƒ W n" tk
r€ } zW Y dd}~X nX dS )zC Handles the user entering input data in the edit control.
        Nr   F)Ú
isinstancer   Z
FocusEventZSkipÚ
_no_updater   Ú_get_user_valueÚvalueÚ_errorÚuiÚerrorsr   r   )r   ÚeventÚexcpr   r   r   r   x   s    

zSimpleEditor.update_objectc             C   s€   | j ƒ }yt|| jkƒ}W n tk
r2   d}Y nX |rRd| _| jj| jƒ d| _| jdk	r|d| _| j	 j
d8  _
| jdƒ dS )z` Updates the editor when the object trait changes externally to the
            editor.
        TFNr   )r    Úboolr!   Ú
ValueErrorr   r   ÚSetValuer   r"   r#   r$   r   )r   Z
user_valueZunequalr   r   r   Úupdate_editor‘   s    

zSimpleEditor.update_editorc             C   sX   | j jƒ }y| j|ƒ}W n   Y nX y| jjj||ƒ}W n tk
rR   |}Y nX |S )zE Gets the actual value corresponding to what the user typed.
        )r   ÚGetValuer   r   ÚmappingÚgetÚ	TypeError)r   r!   Úretr   r   r   r    ª   s    

zSimpleEditor._get_user_valuec             C   s.   | j dkr d| _ | j jd7  _| jdƒ dS )zN Handles an error that occurs while setting the object's trait value.
        NTr   )r"   r#   r$   r   )r   r&   r   r   r   Úerror¿   s    
zSimpleEditor.errorc             C   s   | j p
| jS )zA Returns whether or not the editor is in an error state.
        )Úinvalidr"   )r   r   r   r   Úin_error_stateÌ   s    zSimpleEditor.in_error_stateN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   Zok_colorr   r   r   r   r*   r    r0   r2   r   r   r   r   r
   ;   s   'r
   c               @   s   e Zd ZdZejZdS )ÚCustomEditorzJ Custom style of text editor, which displays a multi-line text field.
    N)r3   r4   r5   r6   r   r   r   r   r   r   r   r7   Ö   s   r7   c                   s\   e Zd ZdZ‡ fdd„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 )r   zL Read-only style of text editor, which displays a read-only text field.
    c                s^   t t| ƒj|ƒ | jjdk	rZ| j}tj|| jƒ tj	|| j
ƒ tj|| jƒ tj|| jƒ dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        N)Úsuperr   r   r   Úviewr   r   ÚEVT_ENTER_WINDOWÚ_enter_windowÚEVT_LEAVE_WINDOWÚ_leave_windowÚEVT_LEFT_DOWNÚ
_left_downÚEVT_LEFT_UPÚ_left_up)r   r   r   )Ú	__class__r   r   r   ë   s    zReadonlyEditor.initc             C   s~   | j }| j}t| jdƒr,| jjr,dt|ƒ }| jjdksD| jjdkrd|j	ƒ |krz|j
|ƒ |jƒ  n|jƒ |krz|j|ƒ dS )z` Updates the editor when the object trait changes externally to the
            editor.
        r   Ú*Tg      ð?Ng      ð¿)r   r   Úhasattrr   r   ÚlenÚitemZ	resizableÚheightr+   r)   ZSetInsertionPointEndZGetLabelZSetLabel)r   r   Z	new_valuer   r   r   r*   ü   s    

zReadonlyEditor.update_editorc                sT   | j jdk	rB| j}tj|dƒ tj|dƒ tj|dƒ tj|dƒ tt	| ƒj
ƒ  dS )z0 Disposes of the contents of an editor.
        N)r   r9   r   r   r:   r<   r>   r@   r8   r   Údispose)r   r   )rB   r   r   rH     s    zReadonlyEditor.disposec             C   s@   | j }| js|jƒ jƒ }n| jr&t}nt}|j|ƒ |jƒ  d S )N)	r   Ú
_in_windowZ	GetParentZGetBackgroundColourÚ_downÚ	DownColorÚ
HoverColorZSetBackgroundColourZRefresh)r   r   Úcolorr   r   r   Ú
_set_color   s    
zReadonlyEditor._set_colorc             C   s   d| _ | jƒ  d S )NT)rI   rN   )r   r%   r   r   r   r;   .  s    zReadonlyEditor._enter_windowc             C   s   d| _ | jƒ  d S )NF)rI   rN   )r   r%   r   r   r   r=   2  s    zReadonlyEditor._leave_windowc             C   s   | j jƒ  d| _| jƒ  d S )NT)r   ZCaptureMouserJ   rN   )r   r%   r   r   r   r?   6  s    
zReadonlyEditor._left_downc             C   sB   | j ƒ  | jsd S | jjƒ  d| _| jr>| jj| jj| jd� d S )NF)r9   r   )	rN   rJ   r   ZReleaseMouserI   ÚobjectZedit_traitsr   r9   )r   r%   r   r   r   rA   ;  s    
zReadonlyEditor._left_up)r3   r4   r5   r6   r   r*   rH   rN   r;   r=   r?   rA   Ú__classcell__r   r   )rB   r   r   â   s   r   )r6   Ú
__future__r   r   Z
traits.apir   Ztraitsui.editors.text_editorr   r   Úeditorr   Zeditor_factoryr   ZBaseReadonlyEditorÚ	constantsr	   Z
LIGHT_GREYrL   ÚWHITErK   r
   r7   Z
TextEditorr   r   r   r   Ú<module>   s    e