a
    §ˆcë(  ã                   @   s–   d Z ddlmZ ddlZG dd„ deƒZeƒ Zde_de_de_	G dd„ dej
ƒZG dd	„ d	ejƒZe d
¡ZG dd„ dej
ƒZG dd„ dejƒZdS )z Drag and drop utilities. é    )ÚgetfullargspecNc                   @   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   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/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                    sp   d| _ d| _|t_|t_| t_t ¡ }t|t	ƒr6|g}|D ]}| 
|¡ q:tƒ  |¡ |  |¡ |  d¡| _dS )z! Initializes the object.
        NT)ÚhandlerÚ
allow_moveÚ	clipboardÚdataÚsourceÚdrop_sourceÚwxÚFileDataObjectÚ
isinstanceÚstrZAddFileÚsuperÚ__init__ÚSetDataÚ
DoDragDropÚresult)Úselfr   ÚfilesÚdata_objectÚfile©Ú	__class__r   r	   r   %   s    

zFileDropSource.__init__c                 C   s   dS )ú( Called when the data has been dropped. Nr   )r   Údrag_resultr   r   r	   Ú
on_dropped<   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 | ¡ || _dS )z Constructor. N)r   r$   r   r   ©r   r   r   r   r	   r   C   s    zFileDropTarget.__init__c                 C   s   |D ]}|   |||¡ qdS )z* Called when the files have been dropped. T)r   )r   ÚxÚyÚ	filenamesÚfilenamer   r   r	   ÚOnDropFilesK   s    zFileDropTarget.OnDropFilesN)r   r   r   r   r   r*   r   r   r   r	   r$   @   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 t¡}| 	d¡ tj
 | |¡ |  	|¡ |r\tjtjB }nt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.
        s   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   \   s    


zPythonDropSource.__init__c                 C   s†   | j dur‚t| j dƒrPt| j jƒd }t|ƒdkrD| j  tj|¡ q‚| j  ¡  n2t| j ƒd }t|ƒdkrz|   tj|¡ n|   ¡  dS )r    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,   Y   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                    s`   t ƒ  ¡  || _t ¡ | _t t¡| _| jj	| jdd� t 
¡ | _| 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   r   r   r   ZDataObjectCompositer   r-   r+   r   ÚAddr   Ú	file_dataZSetDataObjectr%   r   r   r	   r   œ   s    


zPythonDropTarget.__init__c                 C   s$  t jdurt jjstj}nŽt jdu r¨|  ¡ r¨zhddlm} ddlm	} | j
 ¡ }g }g }|D ](}	||	ƒ}
| |
¡ | ||	|
d�¡ q\|t _|t _W n ty¦   Y n0 t| jdƒrÊ| j ||t j|¡}n6t| jdƒrì| j ||t j|¡}n|  ||t j¡ |}t j}|du�r| |¡ 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·   sH    ÿþ




ÿ
ÿ

zPythonDropTarget.OnDatac                 C   sœ   t j}t jdu r&t| jdƒs |S d}nt jjs4tj}t| jdƒrT| j ||||¡}nDt| jdƒrt| j 	||||¡}n$t| jdƒr”| 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 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	   ÚOnLeave$  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   Úinspectr   r   Úobjectr   r   r   r   r   r.   r
   r$   Z
DataFormatr+   r,   Z
DropTargetr5   r   r   r   r	   Ú<module>   s   
@