3
>©ý[e  ã               @   s   d dl Z G dd„ deƒZdS )é    Nc                   s¤   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zd&d	d
„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zd'dd„Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Z‡  ZS )(ÚRemoteWidgetaR  An abstract remote widget which talks to the bridge but has no toolkit
    specific code.

    This is similar to the QVTKRenderWindowInteractor but instead of actually
    setting things on a local render window interactor, passes them off to a
    remote server to do the job and simply renders a PNG sent by the remote
    server.
    c                s`   t t| ƒjf |Ž || _|| _|j|j| ƒ d| _d| _d| _	d| _
d| _d| _d| _d| _d S )NÚnoner   F)FF)Úsuperr   Ú__init__Úscene_proxyÚbridgeZ
add_widgetÚidÚ_ActiveButtonÚ_saveXÚ_saveYÚ_saveModifiersÚ_saveButtonsÚ_wheelDeltaÚ_is_resizingÚ_move_count)Úselfr   r   Úkw)Ú	__class__© úd/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/tools/remote/remote_widget.pyr      s    zRemoteWidget.__init__c             C   s0   |dkr| j s,| j|ƒ n|dkr,| j|ƒ d S )NÚRenderEventÚCursorChangedEvent)r   Ú	on_renderÚon_cursor_changed)r   Úobj_nameZ	vtk_eventÚdatar   r   r   Úhandle_vtk_event$   s
    zRemoteWidget.handle_vtk_eventc             G   s   | j j|f| Ž  d S )N)r   Zcall_rwi)r   ÚmethodÚargsr   r   r   Úsend+   s    zRemoteWidget.sendÚPNGc             C   s   d S )Nr   )r   r   Úformatr   r   r   Ú
show_image.   s    zRemoteWidget.show_imagec             C   s.   | j jƒ }tjd|d�}| j||jƒ d� d S )NÚ )Úh)r!   )r   Zget_raw_imageÚimghdrÚwhatr"   Úupper)r   r   r!   r   r   r   Ú_update_image3   s    
zRemoteWidget._update_imagec             C   s   d S )Nr   )r   r   r   r   r   r   9   s    zRemoteWidget.on_renderc             C   s   d S )Nr   )r   r   r   r   r   r   <   s    zRemoteWidget.on_cursor_changedc             C   s*   | j s&| jd||ƒ | jdƒ | jƒ  d S )NÚSetSizeÚConfigureEvent)r   r   r(   )r   Úwr$   r   r   r   Ú	on_resizeA   s    
zRemoteWidget.on_resizec             C   s   | j j| jj| ƒ d S )N)r   Zremove_widgetr   r   )r   r   r   r   Úon_closeG   s    zRemoteWidget.on_closec          	   C   s.   | j d| j| j||tdƒdd ƒ | j dƒ d S )NÚSetEventInformationFlipYr   Ú
EnterEvent)r   r
   r   Úchr)r   ÚctrlÚshiftr   r   r   Úon_enterJ   s    zRemoteWidget.on_enterc          	   C   s.   | j d| j| j||tdƒdd ƒ | j dƒ d S )Nr.   r   Ú
LeaveEvent)r   r
   r   r0   )r   r1   r2   r   r   r   Úon_leaveO   s    zRemoteWidget.on_leaver   c          	   C   s`   | j d||||tdƒ|dƒ d| _|dkr6| j dƒ n&|dkrJ| j dƒ n|dkr\| j d	ƒ dS )
zï
        ctrl, shift are bools indicating if the modifiers are pressed.
        x, y are screen relative coordinates.
        button is one of 'left', 'right', 'middle' or 'none'
        repeate is for repeat clicks (double click)
        r.   r   NÚleftÚLeftButtonPressEventÚrightÚRightButtonPressEventÚmiddleÚMiddleButtonPressEvent)r   r0   r	   )r   r1   r2   ÚxÚyÚbuttonÚrepeatr   r   r   Úon_mouse_pressT   s    
zRemoteWidget.on_mouse_pressc          	   C   s`   | j d||||tdƒdd ƒ | j}|dkr6| j dƒ n&|dkrJ| j dƒ n|dkr\| j dƒ d S )	Nr.   r   r6   ÚLeftButtonReleaseEventr8   ÚRightButtonReleaseEventr:   ÚMiddleButtonReleaseEvent)r   r0   r	   )r   r1   r2   r<   r=   r>   r   r   r   Úon_mouse_releaseg   s    
zRemoteWidget.on_mouse_releasec          	   C   sh   |  j d7  _ | j d dkrd||f| _|| _|| _|| _| jd||||tdƒdd ƒ | jdƒ d| _ d S )Né   é   r   r.   ÚMouseMoveEvent)r   r   r   r
   r   r   r0   )r   r1   r2   r>   r<   r=   r   r   r   Úon_mouse_mover   s    


zRemoteWidget.on_mouse_movec          	   C   s4   | j d| j| j|||d|ƒ | j dƒ | j dƒ dS )z& React to key pressed event.

        r.   r   ÚKeyPressEventÚ	CharEventN)r   r
   r   )r   r1   r2   ÚkeyZkey_symr   r   r   Úon_key_press€   s    
zRemoteWidget.on_key_pressc          	   C   s*   | j d| j| j|||dd ƒ | j dƒ d S )Nr.   r   ÚKeyReleaseEvent)r   r
   r   )r   r1   r2   rK   r   r   r   Úon_key_release‰   s    zRemoteWidget.on_key_releasec             C   sH   |  j |7  _ | j dkr*| jdƒ d| _ n| j dkrD| jdƒ d| _ d S )Né<   ÚMouseWheelForwardEventr   ÚMouseWheelBackwardEventiÄÿÿÿ)r   r   )r   Údeltar   r   r   Úon_wheelŽ   s    



zRemoteWidget.on_wheel)r    )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   r(   r   r   r,   r-   r3   r5   r@   rD   rH   rL   rN   rS   Ú__classcell__r   r   )r   r   r      s$   

	r   )r%   Úobjectr   r   r   r   r   Ú<module>   s   