3
8ßL]ú  ã               @   s‚   d Z ddlm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.
é    )Úabsolute_import)ÚQtGuiÚQtCore)ÚToolkitEditorFactoryé   )ÚSimpleEditor)Ú	DropColor)Ú
PyMimeDataÚ	clipboardc                   s4   e Zd ZdZe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ƒ| _| jjdƒ | jƒ  ntt	| ƒj
|ƒ tj| jjƒ ƒ}|jtjj| jƒ | jj|ƒ t| jƒ}| jj|ƒ | | j_dS )za Finishes initializing the editor by creating the underlying toolkit
            widget.
        TN)ÚfactoryÚreadonlyr   Z	QLineEditÚ	str_valueÚcontrolZsetReadOnlyZset_tooltipÚsuperr   ÚinitZQPaletteZpaletteZsetColorZBaseÚok_colorZ
setPaletteÚ_DropEventFilterZinstallEventFilterÚ_qt4_editor)ÚselfÚparentZpalZdrop_event_filter)Ú	__class__© ú>/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/drop_editor.pyr   3   s    

zSimpleEditor.initc             C   s   |dkrdS t |ƒS )zL Returns the text representation of a specified object trait value.
        NÚ )Ústr)r   Úvaluer   r   r   Ústring_valueL   s    zSimpleEditor.string_valuec             C   s   dS )zN Handles an error that occurs while setting the object's trait value.
        Nr   )r   Zexcpr   r   r   ÚerrorW   s    zSimpleEditor.error)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__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   |j ƒ }|tjjkr | j|ƒ n|tjjkr6| j|ƒ tt| ƒj	||ƒS )N)
Útyper   ZQEventZDropÚ	dropEventZ	DragEnterÚdragEnterEventr   r   ÚeventFilter)r   ÚsourceÚeventÚtyp)r   r   r   r&   _   s    
z_DropEventFilter.eventFilterc             C   s¤   | j ƒ j}|jj}|jjr(ttddƒ}n|jƒ jƒ }|dksFt	||ƒr d|_
zBt|dƒrd|jƒ |_n||_t|dƒr€|j| ƒ n| j|jƒ W dd|_
X |jƒ  dS )z< Handles 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Úeditorr-   r   r   r   r   r$   k   s     


z_DropEventFilter.dropEventc          
   C   sx   | j ƒ j}|jjr ttddƒ}n|jƒ }t|tƒs6dS |j	ƒ }y(|j
j|jƒj|j
|j|ƒ |jƒ  W n   Y nX dS )z> Handles a Python object being dragged over the tree.
        r*   N)r   r   r   r.   r/   r
   r0   r2   r	   r1   ÚobjectZ
base_traitÚnameÚvalidater4   )r   r5   r6   ÚdataZmdr   r   r   r%   ‹   s    


z_DropEventFilter.dragEnterEvent)r   r   r    r&   r$   r%   r"   r   r   )r   r   r   ]   s    r   N)r!   Ú
__future__r   Z	pyface.qtr   r   Ztraitsui.editors.drop_editorr   Ztext_editorr   ZEditorÚ	constantsr   r
   r	   ZQObjectr   Z
TextEditorZReadonlyEditorr   r   r   r   Ú<module>   s   7F