3
8ßL]Ë  ã               @   sh   d Z ddlm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.
é    )Úabsolute_importN)Ú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 jddƒt jddƒ| jt jd� | _}t j||j	ƒ | j
ƒ t j|| jƒ t j||j	ƒ | jƒ | jr„t j||j	ƒ | jƒ |S )z Creates the control.
        r
   r   )Ústyleéÿÿÿÿr   r   )ÚwxZComboBoxÚvalueZPointÚSizeÚhistoryZCB_DROPDOWNÚcontrolÚEVT_COMBOBOXÚGetIdÚ_update_valueÚEVT_KILL_FOCUSÚ_kill_focusÚEVT_TEXT_ENTERÚ_update_text_valueÚauto_setZEVT_TEXTÚ_update_value_only)ÚselfÚparentr   © r!   úA/tmp/pip-install-5sebvq2j/traitsui/traitsui/wx/history_control.pyÚcreate_controlA   s    zHistoryControl.create_controlc             C   sJ   | j d }| _ |jƒ }tj||jƒ dƒ tj||jƒ dƒ tj|dƒ dS )z? Disposes of the control at the end of its life cycle.
        N)r   Z	GetParentr   r   r   r   r   )r   r   r    r!   r!   r"   ÚdisposeP   s
    zHistoryControl.disposec             C   s   | j |ƒ dS )z> Sets the specified value and adds it to the history.
        N)Ú_update)r   r   r!   r!   r"   Ú	set_valueY   s    zHistoryControl.set_valuec             C   s(   | j s$| j}|dk	r$|j|ƒ d| _dS )z2 Handles the 'value' trait being changed.
        NF)Ú
_no_updater   ÚSetValueÚ_restore)r   r   r   r!   r!   r"   Ú_value_changed`   s
    
zHistoryControl._value_changedc             C   sJ   | j sF| jdk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_changedi   s    
zHistoryControl._history_changedc             C   s,   |r| j jtƒ n| j jtƒ | j jƒ  dS )z2 Handles the 'error' trait being changed.
        N)r   ZSetBackgroundColourr   r   ZRefresh)r   Úerrorr!   r!   r"   Ú_error_changedt   s    zHistoryControl._error_changedc             C   s   | j |jƒ ƒ dS )zc Handles the user selecting something from the drop-down list of the
            combobox.
        N)r%   Ú	GetString)r   Úeventr!   r!   r"   r   €   s    zHistoryControl._update_valuec             C   s   d| _ |jƒ | _d| _ dS )zI Handles the user typing into the text field in 'auto_set' mode.
        TFN)r'   r2   r   )r   r3   r!   r!   r"   r   †   s    
z!HistoryControl._update_value_onlyTc             C   s   | j s| j| jjƒ |ƒ dS )z\ Handles the user typing something into the text field of the
            combobox.
        N)r'   r%   r   ÚGetValue)r   r3   r,   r!   r!   r"   r   �   s    z!HistoryControl._update_text_valuec             C   s   | j |dƒ |jƒ  dS )z, Handles the combobox losing focus.
        FN)r   ZSkip)r   r3   r!   r!   r"   r   ”   s    zHistoryControl._kill_focusc             C   sv   d| _ |jƒ dkrf| j}t|ƒdks0||d krf||krB|j|ƒ |jd|ƒ || jd…= | j||ƒ || _d| _ dS )zH Updates the value and history list based on a specified value.
        Tr+   r   NF)	r'   Ústripr   r-   ÚremoveÚinsertÚentriesr.   r   )r   r   r,   r   r!   r!   r"   r%   œ   s    
zHistoryControl._updateNc             C   sX   | j }|jƒ  |dkr|jƒ }|jƒ  x| jD ]}|j|ƒ q.W d| _t| j||ƒ dS )z: Loads the current history list into the control.
        NT)	r   ZFreezer4   ZClearr   ZAppendr)   r	   Ú_thaw_value)r   Úrestorer,   r   r   r!   r!   r"   r.   ®   s    zHistoryControl._load_historyc             C   s>   | j }|dk	r:| jr2|j|ƒ |r2|jdt|ƒƒ |jƒ  dS )z5 Restores the value of the combobox control.
        Nr   )r   r)   r(   ZSetMarkr-   ZThaw)r   r:   r,   r   r!   r!   r"   r9   ¾   s    
zHistoryControl._thaw_value)T)T)NT)Ú__name__Ú
__module__Ú__qualname__r   r   ZWindowr   r   r   r   r   r   r   r   r8   r0   r#   r$   r&   r*   r/   r1   r   r   r   r   r%   r.   r9   r!   r!   r!   r"   r   +   s&   
		


r   )Ú__doc__Ú
__future__r   r   Z
traits.apir   r   r   r   r   r   Zpyface.timer.apir	   Ú	constantsr   r   r   r!   r!   r!   r"   Ú<module>   s    