a
    §ˆc‚  ã                   @   sB   d dl mZmZ ddlmZ G dd„ dejƒZG dd„ deƒZdS )	é    )ÚQtCoreÚQtGuié   )ÚEditorc                       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|ƒ| _|  ¡  dS )z*Store the descriptive text for the widget.N)ÚsuperÚ__init__ÚstrÚ_descÚ_set_descriptive_text)ÚselfÚdesc©Ú	__class__© ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/search_editor.pyr      s    

zSearchWidget.__init__c                    sH   t j ¡  ¡ }|  |¡ |  ¡ | jkr8|  d¡ |  ¡  t	ƒ  
|¡ 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   ÚfocusInEvent)r   Úeventr   r   r   r   r      s    

zSearchWidget.focusInEventc                    s(   t |  ¡ ƒdkr|  ¡  tƒ  |¡ 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   ÚfocusOutEvent©r   r   r   r   r   r   ,   s    zSearchWidget.focusOutEventc                 C   sN   t j ¡  ¡ }| t jjj| t jjj	¡¡ |  
|¡ |  | j¡ |  ¡  dS )z%Sets the greyed-out descriptive text.N)r   r   r   r   ZsetColorZQPaletteZ	ColorRoleÚTextÚcolorZDarkr   r   r
   r   )r   r   r   r   r   r   7   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	rP|j
 | j¡ | jjrf|j | j¡ dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        )é   é   r   N)r   Ú__version_info__r   Úfactoryr   Úcontrolr   Ú	QLineEditZsetPlaceholderTextZauto_setZ
textEditedÚconnectÚupdate_objectZ	enter_setZeditingFinished)r   Úparentr*   r   r   r   ÚinitC   s    
zSearchEditor.initNc                 C   s8   | j s4t| j ¡ ƒ| _| jjdkr4t| j| jjdƒ dS )z9Handles the user entering input data in the edit control.r   TN)	Ú
_no_updater	   r*   r   Úvaluer)   Zsearch_event_traitÚsetattrÚobjectr   r   r   r   r-   R   s    zSearchEditor.update_objectc                 C   s2   t | j ¡ ƒ| jkr.d| _| j | j¡ d| _dS )z[Updates the editor when the object trait changes externally to the
        editor.
        TFN)r	   r*   r   r1   r0   r   Z	str_value)r   r   r   r   Úupdate_editorY   s    zSearchEditor.update_editor)N)r!   r"   r#   r/   r-   r4   r   r   r   r   r%   B   s   
r%   N)Z	pyface.qtr   r   Zeditorr   r+   r   r%   r   r   r   r   Ú<module>   s   0