a
    «ˆce  ã                   @   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                    sd   t t| ƒjf i |¤Ž || _|| _| |j| ¡ d| _d| _d| _	d| _
d| _d| _d| _d| _d S )NÚnoner   )FFF)Ú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/wcpy/lib/python3.9/site-packages/mayavi/tools/remote/remote_widget.pyr      s    zRemoteWidget.__init__c                 C   s0   |dkr| j s,|  |¡ n|dkr,|  |¡ d S )NZRenderEventZCursorChangedEvent)r   Ú	on_renderÚon_cursor_changed)r   Z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 r   r   ©r   r   Úformatr   r   r   Ú
show_image.   s    zRemoteWidget.show_imagec                 C   s.   | j  ¡ }tjd|d�}| j|| ¡ d� d S )NÚ )Úh)r!   )r   Zget_raw_imageÚimghdrÚwhatr"   Úupperr    r   r   r   Ú_update_image3   s    
zRemoteWidget._update_imagec                 C   s   d S r   r   ©r   r   r   r   r   r   9   s    zRemoteWidget.on_renderc                 C   s   d S r   r   r)   r   r   r   r   <   s    zRemoteWidget.on_cursor_changedc                 C   s*   | j s&|  d||¡ |  d¡ |  ¡  d S )NZSetSizeZConfigureEvent)r   r   r(   )r   Úwr$   r   r   r   Ú	on_resizeA   s    
zRemoteWidget.on_resizec                 C   s   | j  | jj| ¡ d S r   )r   Zremove_widgetr   r   )r   r   r   r   Úon_closeG   s    zRemoteWidget.on_closec              
   C   s.   |   d| j| j||tdƒdd ¡ |   d¡ d S )NÚSetEventInformationFlipYr   Z
EnterEvent©r   r
   r   Úchr©r   ÚctrlÚshiftr   r   r   Úon_enterJ   s    ÿzRemoteWidget.on_enterc              
   C   s.   |   d| j| j||tdƒdd ¡ |   d¡ d S )Nr-   r   Z
LeaveEventr.   r0   r   r   r   Úon_leaveO   s    ÿzRemoteWidget.on_leaver   c              
   C   s`   |   d||||tdƒ|d¡ d| _|dkr6|   d¡ n&|dkrJ|   d¡ n|dkr\|   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ÚleftZLeftButtonPressEventÚrightZRightButtonPressEventÚmiddleZMiddleButtonPressEvent©r   r/   r	   )r   r1   r2   ÚxÚyÚbuttonÚrepeatr   r   r   Úon_mouse_pressT   s    
ÿzRemoteWidget.on_mouse_pressc              
   C   s`   |   d||||tdƒdd ¡ | j}|dkr6|   d¡ n&|dkrJ|   d¡ n|dkr\|   d¡ d S )	Nr-   r   r5   ZLeftButtonReleaseEventr6   ZRightButtonReleaseEventr7   ZMiddleButtonReleaseEventr8   )r   r1   r2   r9   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| _|| _|| _|| _|  d||||tdƒdd ¡ |  d¡ d| _ d S )Né   é   r   r-   ZMouseMoveEvent)r   r   r   r
   r   r   r/   )r   r1   r2   r;   r9   r:   r   r   r   Úon_mouse_mover   s    

ÿ
zRemoteWidget.on_mouse_movec              
   C   s4   |   d| j| j|||d|¡ |   d¡ |   d¡ dS )z& React to key pressed event.

        r-   r   ZKeyPressEventZ	CharEventN©r   r
   r   )r   r1   r2   ÚkeyZkey_symr   r   r   Úon_key_press€   s
    
ÿ
zRemoteWidget.on_key_pressc              
   C   s*   |   d| j| j|||dd ¡ |   d¡ d S )Nr-   r   ZKeyReleaseEventrB   )r   r1   r2   rC   r   r   r   Úon_key_release‰   s    
ÿzRemoteWidget.on_key_releasec                 C   sH   |  j |7  _ | j dkr*|  d¡ d| _ n| j dkrD|  d¡ d| _ d S )Né<   ZMouseWheelForwardEventr   iÄÿÿÿZMouseWheelBackwardEvent)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   r4   r=   r>   rA   rD   rE   rH   Ú__classcell__r   r   r   r   r      s$   

	r   )r%   Úobjectr   r   r   r   r   Ú<module>   s   