3
8ßL]Ã  ã               @   sV   d dl mZ d dlmZmZ ddlmZ d dlZG dd„ dejƒZ	G dd	„ d	eƒZ
dS )
é    )Úabsolute_import)ÚQtCoreÚQtGuié   )ÚEditorNc                   s<   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„Zdd„ Z‡  ZS )	ÚSearchWidgetc                s&   t t| ƒjƒ  tj|ƒ| _| jƒ  dS )z4 Store the descriptive text for the widget.
        N)Úsuperr   Ú__init__ÚsixÚ	text_typeÚ_descÚ_set_descriptive_text)ÚselfÚdesc)Ú	__class__© ú@/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/search_editor.pyr	      s    zSearchWidget.__init__c                sL   t jjƒ jƒ }| j|ƒ | jƒ | jkr8| jdƒ | jƒ  t	t
| ƒj|ƒ dS )z” Handles accepting focus.

        If the text box contains the default description string, reset the text
        color and clear the box.
        Ú N)r   ÚQApplicationÚinstanceÚpaletteÚ
setPaletteÚtextr   ÚsetTextÚupdater   r   ÚfocusInEvent)r   Úeventr   )r   r   r   r   $   s    

zSearchWidget.focusInEventc                s,   t | jƒ ƒdkr| jƒ  tt| ƒj|ƒ dS )z¯ Handles losing focus.

        When focus is lost, if the user had typed something, keep that text,
        otherwise replace it with the default description string.
        r   N)Úlenr   r   r   r   ÚfocusOutEvent)r   r   )r   r   r   r   3   s    zSearchWidget.focusOutEventc             C   sJ   t jjƒ jƒ }|jt jj|jt jjƒƒ | j	|ƒ | j
| jƒ | jƒ  dS )z/ Sets the greyed-out descriptive text.
        N)r   r   r   r   ZsetColorZQPaletteÚTextÚcolorZDarkr   r   r   r   )r   r   r   r   r   r   >   s    

z"SearchWidget._set_descriptive_text)Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   Ú__classcell__r   r   )r   r   r      s   r   c               @   s&   e Zd Zdd„ Zddd„Zdd„ ZdS )	ÚSearchEditorc             C   sj   t jdk rt| jjƒ }| _ntjƒ  }| _|j| jjƒ | jj	rP|j
j| jƒ | jjrf|jj| jƒ dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        é   é   r   N)r&   r'   r   )r   Ú__version_info__r   Úfactoryr   Úcontrolr   Ú	QLineEditZsetPlaceholderTextZauto_setZ
textEditedÚconnectÚupdate_objectZ	enter_setZeditingFinished)r   Úparentr*   r   r   r   ÚinitK   s    
zSearchEditor.initNc             C   s8   | j s4t| jjƒ ƒ| _| jjdkr4t| j| jjdƒ dS )zC Handles the user entering input data in the edit control.
        r   TN)	Ú
_no_updateÚstrr*   r   Úvaluer)   Zsearch_event_traitÚsetattrÚobject)r   r   r   r   r   r-   Z   s    zSearchEditor.update_objectc             C   s2   t | jjƒ ƒ| jkr.d| _| jj| jƒ d| _dS )z` Updates the editor when the object trait changes externally to the
            editor.
        TFN)r1   r*   r   r2   r0   r   Z	str_value)r   r   r   r   Úupdate_editorb   s    zSearchEditor.update_editor)N)r!   r"   r#   r/   r-   r5   r   r   r   r   r%   I   s   
r%   )Ú
__future__r   Z	pyface.qtr   r   Úeditorr   r
   r+   r   r%   r   r   r   r   Ú<module>   s
   1