a
    §ˆca  ã                   @   sv   d Z ddlmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ G dd	„ d	eƒZG d
d„ dejƒZe ZZdS )z‹ Defines a drop target editor for the PyQt user interface toolkit. A drop
target editor handles drag and drop operations as a drop target.
é    )ÚQtGuiÚQtCoreé   )ÚEditor)ÚSimpleEditor)Ú	DropColor)Ú
PyMimeDataÚ	clipboardc                       s@   e Zd ZdZeZ‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Z	‡  Z
S )
r   z�Simple style of drop editor, which displays a read-only text field that
    contains the string representation of the object trait's value.
    c                    sŠ   | j jr,t | j¡| _| j d¡ |  ¡  ntƒ  	|¡ t 
| j ¡ ¡}| tj
jj| j¡ | j |¡ t| jƒ}| j |¡ | | j_dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        TN)ÚfactoryÚreadonlyr   Z	QLineEditÚ	str_valueÚcontrolZsetReadOnlyZset_tooltipÚsuperÚinitZQPaletteZpaletteZsetColorZ	ColorRoleZBaseÚok_colorZ
setPaletteÚ_DropEventFilterZinstallEventFilterÚ_qt4_editor)ÚselfÚparentZpalZdrop_event_filter©Ú	__class__© ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/drop_editor.pyr   ,   s    

zSimpleEditor.initc                    s"   | j jrt | ¡ n
tƒ  ¡  dS )z%Disposes of the content of an editor.N)r
   r   Ú_BaseEditorÚdisposer   )r   r   r   r   r   A   s    zSimpleEditor.disposec                 C   s   |du rdS t |ƒS )zBReturns the text representation of a specified object trait value.NÚ )Ústr)r   Úvaluer   r   r   Ústring_valueI   s    zSimpleEditor.string_valuec                 C   s   dS )zDHandles an error that occurs while setting the object's trait value.Nr   )r   Zexcpr   r   r   ÚerrorO   s    zSimpleEditor.error)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   Ú__classcell__r   r   r   r   r   $   s   r   c                       s,   e Zd Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )r   c                    sH   |  ¡ }|tjjjkr"|  |¡ n|tjjjkr:|  |¡ tƒ  	||¡S )N)
Útyper   ZQEventÚTypeZDropÚ	dropEventZ	DragEnterÚdragEnterEventr   ÚeventFilter)r   ÚsourceÚeventÚtypr   r   r   r)   U   s    
z_DropEventFilter.eventFilterc                 C   sª   |   ¡ j}|jj}|jjr(ttddƒ}n| ¡  ¡ }|du sFt	||ƒr¦d|_
zHt|dƒrd| ¡ |_n||_t|dƒr€| | ¡ n|  |j¡ W d|_
nd|_
0 | ¡  dS )z2Handles a Python object being dropped on the tree.ÚnodeNTÚdrop_editor_valueÚdrop_editor_updateF)r   r   r
   ÚklassÚbindingÚgetattrr	   ÚmimeDataÚinstanceÚ
isinstanceZ
_no_updateÚhasattrr.   r   r/   ZsetTextr   ÚacceptProposedAction)r   ÚeÚeditorr0   r   r   r   r   r'   ]   s     


z_DropEventFilter.dropEventc                 C   sx   |   ¡ j}|jjr ttddƒ}n| ¡ }t|tƒs6dS | 	¡ }z(|j
 |j¡ |j
|j|¡ | ¡  W n   Y n0 dS )z4Handles a Python object being dragged over the tree.r-   N)r   r   r
   r1   r2   r	   r3   r5   r   r4   ÚobjectZ
base_traitÚnameÚvalidater7   )r   r8   r9   ÚdataZmdr   r   r   r(   x   s    


ÿz_DropEventFilter.dragEnterEvent)r    r!   r"   r)   r'   r(   r$   r   r   r   r   r   T   s   r   N)r#   Z	pyface.qtr   r   r9   r   r   Ztext_editorr   Ú	constantsr   r	   r   ZQObjectr   Z
TextEditorZReadonlyEditorr   r   r   r   Ú<module>   s   0<