3
7ßL]T+  ã               @   s¸   d Z ddlZejr ddlmZ nddlmZ ddlZddlZG dd„ dƒZeƒ Zde_	de_
de_G dd„ dejƒZG d	d
„ d
ejƒZejdƒZG dd„ dejƒZG dd„ dejƒZdS )z Drag and drop utilities. é    N)Ú
getargspec)Úgetfullargspecc               @   s   e Zd ZdZdS )Ú	ClipboardzB The clipboard is used when dragging and dropping Python objects. N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r	   r	   ú;/tmp/pip-install-5sebvq2j/pyface/pyface/wx/drag_and_drop.pyr      s   r   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚFileDropSourcez" Represents a draggable file.
    c                sz   d| _ d| _|t_|t_| t_tjƒ }t|t	j
ƒr8|g}x|D ]}|j|ƒ q>W tt| ƒj|ƒ | j|ƒ | jdƒ| _dS )z! Initializes the object.
        NT)ÚhandlerÚ
allow_moveÚ	clipboardÚdataÚsourceÚdrop_sourceÚwxÚFileDataObjectÚ
isinstanceÚsixÚ	text_typeZAddFileÚsuperr   Ú__init__ÚSetDataÚ
DoDragDropÚresult)Úselfr   ÚfilesÚdata_objectÚfile)Ú	__class__r	   r
   r   /   s    

zFileDropSource.__init__c             C   s   dS )z( Called when the data has been dropped. Nr	   )r   Údrag_resultr	   r	   r
   Ú
on_droppedF   s    zFileDropSource.on_dropped)r   r   r   r   r   r"   Ú__classcell__r	   r	   )r    r
   r   +   s   r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚFileDropTargetz Drop target for files. c             C   s   t jj| ƒ || _dS )z Constructor. N)r   r$   r   r   )r   r   r	   r	   r
   r   N   s    zFileDropTarget.__init__c             C   s    x|D ]}| j |||ƒ qW dS )z* Called when the files have been dropped. T)r   )r   ÚxÚyÚ	filenamesÚfilenamer	   r	   r
   ÚOnDropFilesX   s    
zFileDropTarget.OnDropFilesN)r   r   r   r   r   r)   r	   r	   r	   r
   r$   K   s   
r$   ÚPythonObjectc               @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚPythonDropSourcez! Drop source for Python objects. NTc             C   sr   || _ || _|t_|t_| t_tjtƒ}|j	dƒ tj
j| |ƒ | j	|ƒ |r\tjtjB }ntj}| j|ƒ| _dS )zå Creates a new drop source.

        A drop source should be created for *every* drag operation.

        If allow_move is False then the operation will default to
        a copy and only copy operations will be allowed.
        ÚdummyN)r   r   r   r   r   r   r   ÚCustomDataObjectr*   r   Ú
DropSourcer   ZDrag_DefaultMoveZDrag_AllowMoveZDrag_CopyOnlyr   r   )r   r   r   r   r   r   Úflagsr	   r	   r
   r   i   s    


zPythonDropSource.__init__c             C   s†   | j dk	r‚t| j dƒrPt| j jƒd }t|ƒdkrD| j jtj|ƒ q‚| j jƒ  n2t| j ƒd }t|ƒdkrz| j tj|ƒ n| j ƒ  dS )z( Called when the data has been dropped. Nr"   r   é   é   )r   Úhasattrr   r"   Úlenr   r   )r   r!   Úargsr	   r	   r
   r"   �   s    
zPythonDropSource.on_dropped)NT)r   r   r   r   r   r"   r	   r	   r	   r
   r+   f   s   
$r+   c                   s@   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡  Z	S )ÚPythonDropTargetz! Drop target for Python objects. c                sd   t t| ƒjƒ  || _tjƒ | _tjtƒ| _	| jj
| j	dd� tjƒ | _| jj
| jƒ | j| jƒ dS )a   Constructor

        The handler can be either a function that will be called when
        *any* data is dropped onto the target, or an instance that supports
        the 'wx_drag_over' and 'wx_dropped_on' methods. The latter case
        allows the target to veto the drop.

        T)Ú	preferredN)r   r5   r   r   r   ZDataObjectCompositer   r-   r*   r   ÚAddr   Ú	file_dataZSetDataObject)r   r   )r    r	   r
   r   ­   s    

zPythonDropTarget.__init__c             C   s,  t jdk	rt jj rtj}n”t jdkr°| jƒ r°ylddlm} ddlm	} | j
jƒ }g }g }x0|D ](}	||	ƒ}
|j|
ƒ |j||	|
d�ƒ q`W |t _|t _W n tk
r®   Y nX t| jdƒrÒ| jj||t j|ƒ}n6t| jdƒrô| jj||t j|ƒ}n| j||t jƒ |}t j}|dk	�r"|j|ƒ dt _|S )z" Called when OnDrop returns True. Nr   )ÚFile)ÚBinding)ÚnameÚobjÚwx_dropped_onÚon_drop)r   r   r   r   ÚDragCopyZGetDataZapptools.ior9   Zapptools.naming.apir:   r8   ZGetFilenamesÚappendr   ÚnodeÚImportErrorr2   r   r=   r>   r"   )r   r%   r&   Údefault_drag_resultr9   r:   Únamesr   Zbindingsr;   Úfr!   r   r	   r	   r
   ÚOnDataÊ   s@    








zPythonDropTarget.OnDatac             C   sœ   t j}t jdkr&t| jdƒs |S d}nt jjs4tj}t| jdƒrT| jj||||ƒ}nDt| jdƒrt| jj	||||ƒ}n$t| jdƒr”| jj
||||ƒ}n|}|S )z= Called when a data object is being dragged over the target. NÚwx_drag_anyÚwx_drag_overÚon_drag_over)r   r   r   r2   r   r   r   r?   rG   rH   rI   )r   r%   r&   rC   r   r!   r	   r	   r
   Ú
OnDragOver  s$    
zPythonDropTarget.OnDragOverc             C   s   t | jdƒr| jjtjƒ dS )z/ Called when the mouse leaves the drop target. Úwx_drag_leaveN)r2   r   rK   r   r   )r   r	   r	   r
   ÚOnLeave5  s    zPythonDropTarget.OnLeavec             C   s   dS )zq Called when the user drops a data object on the target.

        Return 'False' to veto the operation.

        Tr	   )r   r%   r&   r	   r	   r
   ÚOnDrop=  s    zPythonDropTarget.OnDrop)
r   r   r   r   r   rF   rJ   rL   rM   r#   r	   r	   )r    r
   r5   ª   s   =.r5   )r   r   ÚPY2Úinspectr   r   r   r   r   r   r   r   r.   r   r$   ZCustomDataFormatr*   r+   ZPyDropTargetr5   r	   r	   r	   r
   Ú<module>   s     
D