a
    ¦ˆcòA  ã                   @   s€   d Z ddlZddlmZmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZdS )z³ Pyface 'FeatureBar' support.

    Defines the 'FeatureBar' class which displays and allows the user to
    interact with a set of DockWindowFeatures for a specified DockControl.
é    N)ÚHasPrivateTraitsÚInstanceÚBoolÚEvent)ÚPythonDropTargetÚPythonDropSource)ÚTraitsUIColoré   )ÚDockControlÚFEATURE_EXTERNAL_DRAG)ÚIFeatureToolc                   @   sÎ   e Zd ZeejƒZeeƒZeejƒZ	e
ƒ Zeddd�Zeddd�Ze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„ Z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%S )&Ú
FeatureBari÷îÛ T)Ú
allow_nonei¯ƒ% c                 C   s   | j dur| j  ¡  dS )z  Hides the feature bar.
        N)ÚcontrolZHide©Úself© r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/dock/feature_bar.pyÚhide@   s    
zFeatureBar.hidec                 C   sÐ  | j | j }}|du s|du r"dS | j}|du rØtjdddtjd� | _}| tj| j¡ | tj	| j
¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | t| ƒ¡ t dd¡}d }}| j}|jD ]V}|j}	|	durø|�r0||	 ¡ d 7 }t||	 ¡ ƒ}qøt||	 ¡ ƒ}||	 ¡ d 7 }qø|dk�rŠ|�rvt |d |d	 ¡}nt |d	 |d ¡}|  |¡ | !¡ \}
}|j"\}}| #t $|
| || ¡¡ | %¡  dS )
z  Shows the feature bar.
        NéÿÿÿÿÚ )Ústyleé    r   é   é   é   )&Údock_controlÚparentr   ÚwxZFrameZBORDER_NONEZBindZEVT_ERASE_BACKGROUNDÚ_erase_backgroundZ	EVT_PAINTÚ_paintZEVT_LEFT_DOWNÚ
_left_downZEVT_LEFT_UPÚ_left_upZEVT_RIGHT_DOWNÚ_right_downZEVT_RIGHT_UPÚ	_right_upZ
EVT_MOTIONÚ_mouse_moveZEVT_ENTER_WINDOWÚ_mouse_enterZSetDropTargetr   ÚSizeÚ
horizontalÚactive_featuresÚbitmapÚGetWidthÚmaxÚ	GetHeightZSetSizeÚGetScreenPositionZfeature_popup_positionZSetPositionZPointZShow)r   r   r   r   ÚsizeÚwidthÚheightr(   Úfeaturer*   ZpxÚpyZfxZfyr   r   r   ÚshowJ   sJ    
ÿ



zFeatureBar.showc                 C   s.  | j }| ¡  ¡ \}}t |¡}| j}| j}|dus<|dur¢|du rR| tj¡ n| t 	|dtj
¡¡ |du r~| tj¡ n| t |tj
¡¡ | dd||¡ | jrêd}| jjD ]2}	|	j}
|
dur´| |
|dd¡ ||
 ¡ d 7 }q´n@d}| jjD ]2}	|	j}
|
durö| |
d|d¡ ||
 ¡ d 7 }qödS )z( Handles repainting the window.
        Nr	   r   é   Tr   )r   ÚGetSizeÚGetr   ZPaintDCÚbg_colorÚborder_colorZSetPenZTRANSPARENT_PENZPenZSOLIDZSetBrushZBrushZDrawRectangler(   r   r)   r*   Z
DrawBitmapr+   r-   )r   ÚeventZwindowÚdxÚdyÚdcr8   r9   Úxr2   r*   Úyr   r   r   r    ‰   s4    
zFeatureBar._paintc                 C   s   dS )z0 Handles erasing the window background.
        Nr   ©r   r:   r   r   r   r   ²   s    zFeatureBar._erase_backgroundc                 C   s(   |   |¡| _d| _| ¡ | ¡ f| _dS )z6 Handles the left mouse button being pressed.
        FN©Ú_feature_atÚ_featureÚ	_draggingÚGetXÚGetYÚ_xyr@   r   r   r   r!   »   s    zFeatureBar._left_downc                 C   sP   d| _ | jd }| _|durL||  |¡u rL| j ¡  d| _| |¡ | ¡  dS )z7 Handles the left mouse button being released.
        NT)rD   rC   rB   r   ÚReleaseMouseÚ	completedÚ
_set_eventZclick©r   r:   r2   r   r   r   r"   Ç   s    

zFeatureBar._left_upc                 C   s(   |   |¡| _d| _| ¡ | ¡ f| _dS )z7 Handles the right mouse button being pressed.
        FNrA   r@   r   r   r   r#   Ø   s    zFeatureBar._right_downc                 C   sP   d| _ | jd }| _|durL||  |¡u rL| j ¡  d| _| |¡ | ¡  dS )z8 Handles the right mouse button being released.
        NT)rD   rC   rB   r   rH   rI   rJ   Zright_clickrK   r   r   r   r$   ä   s    

zFeatureBar._right_upc                 C   s¼  | j du r¾|  |¡}|| jur`|| _d}|dur6|j}tj d¡ tj d¡ | j t |¡¡ | 	¡ | 
¡  }}| j ¡  ¡ \}}|dk s¤|dk s¤||ks¤||krº| j ¡  d| _d| _dS | j �s¸| j\}}t|| 	¡  ƒt|| 
¡  ƒ dk rødS d| _ | j}|du�r¸| |¡ d }}	| ¡ �r.d}	| ¡ �r>d}n| ¡ �rNd	}n| ¡ �r\d
}t|d||	f ƒƒ }
|
du�r¸| j ¡  d| _d| _| j |
¡ t| j|
ƒ | j ¡  d| _ dS )z3 Handles the mouse moving over the window.
        Nr   FTr   r   Zright_Zcontrol_Zalt_Zshift_z%s%sdrag)rD   rB   Z_tooltip_featureÚtooltipr   ZToolTipZEnabler   Z
SetToolTiprE   rF   r6   r7   rH   rI   rG   ÚabsrC   rJ   ZRightIsDownZControlDownZAltDownZ	ShiftDownÚgetattrr   Zpre_drag_allr   Zpost_drag_all)r   r:   r2   rL   r>   r?   r;   r<   ÚprefixÚbuttonÚobjectr   r   r   r%   õ   sV    


 

$








zFeatureBar._mouse_movec                 C   s   | j  ¡  dS )z0 Handles the mouse entering the window.
        N)r   ZCaptureMouser@   r   r   r   r&   4  s    zFeatureBar._mouse_enterc           	      C   sˆ   |   |||¡}d| _| j t¡ |dur‚t|tƒrP|j}| |¡ | |j	¡ n.| j
 ¡ \}}|j|| || d� | |¡ |S |jS )z> Handles a Python object being dropped on the window.
        TN©r>   r?   )Ú_can_drop_on_featurerI   r   Ú	post_dragr   Ú
isinstancer   Zfeature_dropped_on_dock_controlZfeature_dropped_onrQ   r   r.   Z	trait_setZdropÚDragNone)	r   r>   r?   ÚdataÚdrag_resultr2   r   r   Zwyr   r   r   Úwx_dropped_on?  s    


zFeatureBar.wx_dropped_onc                 C   s   |   |||¡dur|S tjS )zA Handles a Python object being dragged over the control.
        N)rS   r   rV   )r   r>   r?   rW   rX   r   r   r   Úwx_drag_over`  s    zFeatureBar.wx_drag_overc                 C   s   d| _ | j t¡ dS )z= Handles a dragged Python object leaving the window.
        TN)rI   r   rT   r   )r   rW   r   r   r   Úwx_drag_leavem  s    zFeatureBar.wx_drag_leavec                 C   s*   |   t||ƒ¡}|dur&| |¡r&|S dS )zi Returns a feature that the pointer is over and which can accept the
            specified data.
        N)rB   Ú	FakeEventZcan_drop)r   r>   r?   rW   r2   r   r   r   rS   }  s    zFeatureBar._can_drop_on_featurec              	   C   s°   | j rZd}| jjD ]D}|j}|dur| ¡ }|  ||d|| ¡ ¡rJ|  S ||d 7 }qnRd}| jjD ]D}|j}|durf| ¡ }|  |d|| ¡ |¡rž|  S ||d 7 }qfdS )z\ Returns the DockWindowFeature (if any) at a specified window
            position.
        r5   Nr   )r(   r   r)   r*   r+   Ú_is_inr-   )r   r:   r>   r2   r*   Zbdxr?   Zbdyr   r   r   rB   ‹  s$    zFeatureBar._feature_atc                 C   s@   ||  ¡   ko|| k n  o>|| ¡   ko:|| k S   S )zG Returns whether or not an event is within a specified bounds.
        )rE   rF   )r   r:   r>   r?   r;   r<   r   r   r   r]   ª  s     ÿzFeatureBar._is_inN)!Ú__name__Ú
__module__Ú__qualname__r   r   ZWindowr   r
   r   r   r   rI   ÚColorr8   r9   r   r(   r   r4   r    r   r!   r"   r#   r$   r%   r&   rY   rZ   r[   rS   rB   r]   r   r   r   r   r   !   s.   


?)	?!r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )r\   c                 C   s   || | _ | _d S ©NrR   )r   r>   r?   r   r   r   Ú__init__¸  s    zFakeEvent.__init__c                 C   s   | j S rb   )r>   r   r   r   r   rE   »  s    zFakeEvent.GetXc                 C   s   | j S rb   )r?   r   r   r   r   rF   ¾  s    zFakeEvent.GetYN)r^   r_   r`   rc   rE   rF   r   r   r   r   r\   ·  s   r\   )Ú__doc__r   Z
traits.apir   r   r   r   Zpyface.wx.drag_and_dropr   r   Zpyface.ui_traitsr   ra   Z
dock_sizerr
   r   Zifeature_toolr   r   rQ   r\   r   r   r   r   Ú<module>   s      