a
    §ˆc¦  ã                   @   s˜   d Z ddlmZmZ ddlmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZeZdS )zG Defines the various text editors for the PyQt user interface toolkit.
é    )ÚQtCoreÚQtGui)ÚAnyÚCallableÚListÚ
TraitErrorÚTuple)Úevaluate_traité   )ÚEditor)ÚReadonlyEditor)ÚOKColorc                       sl   e Zd ZdZejZeZe	Z
eee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 )ÚSimpleEditorz6Simple style text editor, which displays a text field.c                 C   s¦  | j }| j}|j| _|  |jdd¡ |jr6|js6|jr<tj	}|tj	u}|rPd| _
|| jƒ}|jrj| d¡ |jr€| tj	jj¡ |tjkr®|j | j¡ | j |j| jf¡ nR|jrÞ|jsÞ|j | j¡ | j |j| jf¡ n"|j | j¡ | j |j| jf¡ | j j}|tju�s tjdk�r*| |¡ |tju�rPtjdk�rP| | j j¡ || _ | j!j"�s�| j!j#�s�| j  $¡ }| %tj&j'j(¡ | j  )|¡ |  *d¡ |  +¡  dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        ÚevaluateÚfromT)é   é   FN),ÚfactoryÚ
base_styler   Z
sync_valueZevaluate_nameÚ
multi_lineZis_grid_cellÚpasswordr   Ú	QLineEditZ
scrollableÚ	str_valueZ	read_onlyZsetReadOnlyZsetEchoModeZEchoModeZPasswordÚ	QTextEditZtextChangedÚconnectÚupdate_objectÚ_connections_to_removeÚappendZauto_setZ
textEditedZeditingFinishedÚplaceholderr   Ú__version_info__ZsetPlaceholderTextZsetClearButtonEnabledZcancel_buttonÚcontrolÚitemZ	resizableZspringyZ
sizePolicyZsetHorizontalPolicyZQSizePolicyÚPolicyZMinimumZsetSizePolicyÚset_error_stateZset_tooltip)ÚselfÚparentr   Zwtyper   r    r   Úpolicy© r'   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/text_editor.pyÚinit=   sP    




ÿ
ÿ
ÿ


zSimpleEditor.initc                    s.   | j r | j  ¡ \}}| |¡ q tƒ  ¡  dS )z&Disposes of the contents of an editor.N)r   ÚpopZ
disconnectÚsuperÚdispose)r$   ÚsignalÚhandler©Ú	__class__r'   r(   r,   z   s    zSimpleEditor.disposec              
   C   sr   | j sn| jdurnz8|  ¡ | _| jdur<d| _| j jd8  _|  d¡ W n$ tyl } zW Y d}~n
d}~0 0 dS )z9Handles the user entering input data in the edit control.Nr
   F)	Ú
_no_updater    Ú_get_user_valueÚvalueÚ_errorÚuiÚerrorsr#   r   ©r$   Zexcpr'   r'   r(   r   ‚   s    

zSimpleEditor.update_objectc                 C   s~   |   ¡ }zt|| jkƒ}W n ty0   d}Y n0 |rPd| _| j | j¡ d| _| jdurzd| _| j	 j
d8  _
|  d¡ dS )ú[Updates the editor when the object trait changes externally to the
        editor.
        TFNr
   )r2   Úboolr3   Ú
ValueErrorr1   r    ÚsetTextr   r4   r5   r6   r#   )r$   Z
user_valueZunequalr'   r'   r(   Úupdate_editor‘   s    

zSimpleEditor.update_editorc                 C   s€   z| j  ¡ }W n ty*   | j  ¡ }Y n0 t|ƒ}z|  |¡}W n   Y n0 z| jj ||¡}W n t	yz   |}Y n0 |S )z;Gets the actual value corresponding to what the user typed.)
r    ÚtextÚAttributeErrorZtoPlainTextÚstrr   r   ÚmappingÚgetÚ	TypeError)r$   r3   Úretr'   r'   r(   r2   ¦   s    
zSimpleEditor._get_user_valuec                 C   s.   | j du r d| _ | j jd7  _|  d¡ dS )zDHandles an error that occurs while setting the object's trait value.NTr
   )r4   r5   r6   r#   r7   r'   r'   r(   Úerror¼   s    
zSimpleEditor.errorc                 C   s   | j p
| jS )z7Returns whether or not the editor is in an error state.)Úinvalidr4   )r$   r'   r'   r(   Úin_error_stateÄ   s    zSimpleEditor.in_error_state)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Zok_colorr	   r   r   r   r   r   r   r)   r,   r   r<   r2   rD   rF   Ú__classcell__r'   r'   r/   r(   r   '   s   =r   c                   @   s   e Zd ZdZejZdS )ÚCustomEditorzDCustom style of text editor, which displays a multi-line text field.N)rG   rH   rI   rJ   r   r   r   r'   r'   r'   r(   rL   É   s   rL   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r   zFRead-only style of text editor, which displays a read-only text field.c                    s8   t ƒ  |¡ | jjr4| j ¡ tjjj	B }| j 
|¡ d S )N)r+   r)   r   Zreadonly_allow_selectionr    ZtextInteractionFlagsr   ZQtZTextInteractionFlagZTextSelectableByMouseZsetTextInteractionFlags)r$   r%   Úflagsr/   r'   r(   r)   Ô   s    ÿÿzReadonlyEditor.initc                 C   s*   | j }| jjrdt|ƒ }| j |¡ dS )r8   Ú*N)r   r   r   Úlenr    r;   )r$   Ú	new_valuer'   r'   r(   r<   Þ   s    zReadonlyEditor.update_editor)rG   rH   rI   rJ   r)   r<   rK   r'   r'   r/   r(   r   Ñ   s   
r   N)rJ   Z	pyface.qtr   r   Z
traits.apir   r   r   r   r   Ztraitsui.editors.text_editorr	   Zeditorr   Zeditor_factoryr   ZBaseReadonlyEditorÚ	constantsr   r   rL   Z
TextEditorr'   r'   r'   r(   Ú<module>   s    #