a
    §ˆc  ã                   @   s\   d Z ddlZddlmZmZmZmZmZmZ ddl	m
Z
 ddlmZmZ G dd„ deƒZdS )	z€ Defines the a text entry field (actually a combo-box) with a drop-down list
    of values previously entered into the control.
é    N)ÚHasPrivateTraitsÚInstanceÚStrÚListÚIntÚBool)Údo_lateré   )ÚOKColorÚ
ErrorColorc                   @   sª   e Zd ZeejƒZeƒ Ze	dƒZ
eeƒZedƒ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 dd„Zd!dd„Zdd„ ZdS )"ÚHistoryControlFé
   c              	   C   s–   t j|d| jt  dd¡t  dd¡| jt jd� | _}|jt j	| j
| ¡ d� | t j| j¡ |jt j| j| ¡ d� | jr’|jt j| j| ¡ d� |S )zCreates the control.éÿÿÿÿr   )Ústyle©Úid)ÚwxZComboBoxÚvalueZPointÚSizeÚhistoryZCB_DROPDOWNÚcontrolÚBindÚEVT_COMBOBOXÚ_update_valueÚGetIdÚEVT_KILL_FOCUSÚ_kill_focusÚEVT_TEXT_ENTERÚ_update_text_valueÚauto_setZEVT_TEXTÚ_update_value_only)ÚselfÚparentr   © r#   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/history_control.pyÚcreate_control3   s&    

ù	ÿÿzHistoryControl.create_controlc                 C   sR   | j d }| _ | ¡ }|jtjd| ¡ d� |jtjd| ¡ d� | tj¡ dS )z5Disposes of the control at the end of its life cycle.Nr   )	r   Z	GetParentr   r   r   r   r   ZUnbindr   )r!   r   r"   r#   r#   r$   ÚdisposeJ   s
    zHistoryControl.disposec                 C   s   |   |¡ dS )z4Sets the specified value and adds it to the history.N)Ú_update)r!   r   r#   r#   r$   Ú	set_valueR   s    zHistoryControl.set_valuec                 C   s(   | j s$| j}|dur$| |¡ d| _dS )z(Handles the 'value' trait being changed.NF)Ú
_no_updater   ÚSetValueÚ_restore)r!   r   r   r#   r#   r$   Ú_value_changedX   s
    
zHistoryControl._value_changedc                 C   sJ   | j sF| jdu r:d| _| jdkr:t| jƒdkr:| jd | _| jdd� dS )z$Handles the 'history' being changed.NFÚ r   )Úselect)r)   Z_first_timer   Úlenr   Ú_load_history)r!   r#   r#   r$   Ú_history_changed`   s    
zHistoryControl._history_changedc                 C   s,   |r| j  t¡ n| j  t¡ | j  ¡  dS )z(Handles the 'error' trait being changed.N)r   ZSetBackgroundColourr   r
   ZRefresh)r!   Úerrorr#   r#   r$   Ú_error_changedj   s    zHistoryControl._error_changedc                 C   s   |   | ¡ ¡ dS )z^Handles the user selecting something from the drop-down list of the
        combobox.
        N)r'   Ú	GetString©r!   Úeventr#   r#   r$   r   u   s    zHistoryControl._update_valuec                 C   s   d| _ | ¡ | _d| _ dS )z?Handles the user typing into the text field in 'auto_set' mode.TFN)r)   r4   r   r5   r#   r#   r$   r    {   s    
z!HistoryControl._update_value_onlyTc                 C   s   | j s|  | j ¡ |¡ dS )zWHandles the user typing something into the text field of the
        combobox.
        N)r)   r'   r   ÚGetValue)r!   r6   r.   r#   r#   r$   r   �   s    z!HistoryControl._update_text_valuec                 C   s   |   |d¡ | ¡  dS )z"Handles the combobox losing focus.FN)r   ZSkipr5   r#   r#   r$   r   ˆ   s    zHistoryControl._kill_focusc                 C   sv   d| _ | ¡ dkrf| j}t|ƒdks0||d krf||v rB| |¡ | d|¡ || jd…= |  ||¡ || _d| _ dS )z>Updates the value and history list based on a specified value.Tr-   r   NF)	r)   Ústripr   r/   ÚremoveÚinsertÚentriesr0   r   )r!   r   r.   r   r#   r#   r$   r'   �   s    
zHistoryControl._updateNc                 C   sT   | j }| ¡  |du r| ¡ }| ¡  | jD ]}| |¡ q,d| _t| j||ƒ dS )z0Loads the current history list into the control.NT)	r   ZFreezer7   ZClearr   ZAppendr+   r   Ú_thaw_value)r!   Úrestorer.   r   r   r#   r#   r$   r0       s    
zHistoryControl._load_historyc                 C   s>   | j }|dur:| jr2| |¡ |r2| dt|ƒ¡ | ¡  dS )z+Restores the value of the combobox control.Nr   )r   r+   r*   ZSetTextSelectionr/   ZThaw)r!   r=   r.   r   r#   r#   r$   r<   ¯   s    
zHistoryControl._thaw_value)T)T)NT)Ú__name__Ú
__module__Ú__qualname__r   r   ZWindowr   r   r   r   r   r   r   r   r;   r2   r%   r&   r(   r,   r1   r3   r   r    r   r   r'   r0   r<   r#   r#   r#   r$   r      s&   




r   )Ú__doc__r   Z
traits.apir   r   r   r   r   r   Zpyface.timer.apir   Ú	constantsr
   r   r   r#   r#   r#   r$   Ú<module>   s
    