3
7ßL]D  ã               @   sx   d Z ddlZddlmZmZmZmZmZ ddlm	Z	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ÚColor)ÚPythonDropTargetÚPythonDropSourceé   )Ú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k	r| j jƒ  dS )z  Hides the feature bar.
        N)ÚcontrolZHide)Úself© r   ú;/tmp/pip-install-5sebvq2j/pyface/pyface/dock/feature_bar.pyÚhideG   s    
zFeatureBar.hidec             C   sÄ  | j | j }}|dks|dkr"dS | j}|dk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ƒ |jt| ƒƒ tjddƒ}d }}| j}x`|jD ]V}|j}	|	dk	rê|�r"||	jƒ d 7 }t||	jƒ ƒ}qêt||	jƒ ƒ}||	jƒ d 7 }qêW |dk�r~|�rjtj|d |d	 ƒ}ntj|d	 |d ƒ}|j|ƒ |j ƒ \}
}|j!\}}|j"tj#|
| || ƒƒ |j$ƒ  dS )z  Shows the feature bar.
        Nr	   Ú )Ústyleé    r   é   é   é   éÿÿÿÿ)%Údock_controlÚparentr   ÚwxZFrameZBORDER_NONEZ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   ÚshowQ   sH    



zFeatureBar.showc             C   s2  | j }|jƒ \}}tj|ƒ}| j}| j}|dk	s8|dk	rž|dkrN|jtjƒ n|jtj|dtj	ƒƒ |dkrz|j
tjƒ n|j
tj|tj	ƒƒ |jdd||ƒ | jrêd}x„| jjD ]2}	|	j}
|
dk	r²|j|
|ddƒ ||
jƒ d 7 }q²W nDd}x>| jjD ]2}	|	j}
|
dk	rø|j|
d|dƒ ||
jƒ d 7 }qøW dS )z( Handles repainting the window.
        Nr	   r   é   Tr   )r   ÚGetSizeTupler   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Údcr6   r7   Úxr1   r)   Úyr   r   r   r   �   s4    
zFeatureBar._paintc             C   s   dS )z0 Handles erasing the window background.
        Nr   )r   r8   r   r   r   r   ¸   s    zFeatureBar._erase_backgroundc             C   s(   | j |ƒ| _d| _|jƒ |jƒ f| _dS )z6 Handles the left mouse button being pressed.
        FN)Ú_feature_atÚ_featureÚ	_draggingÚGetXÚGetYÚ_xy)r   r8   r   r   r   r    Á   s    zFeatureBar._left_downc             C   sP   d| _ | jd }| _|dk	rL|| j|ƒkrL| jjƒ  d| _|j|ƒ |jƒ  dS )z7 Handles the left mouse button being released.
        NT)r@   r?   r>   r   ÚReleaseMouseÚ	completedÚ
_set_eventZclick)r   r8   r1   r   r   r   r!   Í   s    

zFeatureBar._left_upc             C   s(   | j |ƒ| _d| _|jƒ |jƒ f| _dS )z7 Handles the right mouse button being pressed.
        FN)r>   r?   r@   rA   rB   rC   )r   r8   r   r   r   r"   Þ   s    zFeatureBar._right_downc             C   sP   d| _ | jd }| _|dk	rL|| j|ƒkrL| jjƒ  d| _|j|ƒ |jƒ  dS )z8 Handles the right mouse button being released.
        NT)r@   r?   r>   r   rD   rE   rF   Zright_click)r   r8   r1   r   r   r   r#   ê   s    

zFeatureBar._right_upc             C   s¸  | j dkrº| j|ƒ}|| jk	r`|| _d}|dk	r6|j}tjjdƒ tjjdƒ | jjtj|ƒƒ |j	ƒ |j
ƒ  }}| jjƒ \}}|dk s |dk s ||ks ||kr¶| jjƒ  d| _d| _dS | j �s´| j\}}t||j	ƒ  ƒt||j
ƒ  ƒ dk rôdS d| _ | j}|dk	�r´|j|ƒ d }}	|jƒ �r*d}	|jƒ �r:d}n|jƒ �rJd	}n|jƒ �rXd
}t|d||	f ƒƒ }
|
dk	�r´| jjƒ  d| _d| _| jj|
ƒ t| j|
ƒ | 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)r@   r>   Z_tooltip_featureÚtooltipr   ZToolTipZEnabler   Z
SetToolTiprA   rB   r5   rD   rE   rC   Úabsr?   rF   ZRightIsDownZControlDownZAltDownZ	ShiftDownÚgetattrr   Zpre_drag_allr   Zpost_drag_all)r   r8   r1   rG   r<   r=   r9   r:   ÚprefixÚbuttonÚobjectr   r   r   r$   û   sV    


 

$








zFeatureBar._mouse_movec             C   s   | j jƒ  dS )z0 Handles the mouse entering the window.
        N)r   ZCaptureMouse)r   r8   r   r   r   r%   :  s    zFeatureBar._mouse_enterc       	      C   sˆ   | j |||ƒ}d| _| jjtƒ |dk	r‚t|tƒrP|j}|j|ƒ |j|j	ƒ n.| j
jƒ \}}|j|| || d� |j|ƒ |S |jS )z> Handles a Python object being dropped on the window.
        TN)r<   r=   )Ú_can_drop_on_featurerE   r   Ú	post_dragr   Ú
isinstancer   Zfeature_dropped_on_dock_controlZfeature_dropped_onrL   r   r-   Z	trait_setZdropÚDragNone)	r   r<   r=   ÚdataÚdrag_resultr1   r   r   Zwyr   r   r   Úwx_dropped_onE  s    


zFeatureBar.wx_dropped_onc             C   s   | j |||ƒdk	r|S tjS )zA Handles a Python object being dragged over the control.
        N)rM   r   rP   )r   r<   r=   rQ   rR   r   r   r   Úwx_drag_overf  s    zFeatureBar.wx_drag_overc             C   s   d| _ | jjtƒ dS )z= Handles a dragged Python object leaving the window.
        TN)rE   r   rN   r   )r   rQ   r   r   r   Úwx_drag_leaves  s    zFeatureBar.wx_drag_leavec             C   s*   | j t||ƒƒ}|dk	r&|j|ƒr&|S dS )zi Returns a feature that the pointer is over and which can accept the
            specified data.
        N)r>   Ú	FakeEventZcan_drop)r   r<   r=   rQ   r1   r   r   r   rM   ƒ  s    zFeatureBar._can_drop_on_featurec             C   s°   | j rZd}x | jjD ]@}|j}|dk	r|jƒ }| j||d||jƒ ƒrH|S ||d 7 }qW nRd}xL| jjD ]@}|j}|dk	rh|jƒ }| j|d||jƒ |ƒrœ|S ||d 7 }qhW dS )z\ Returns the DockWindowFeature (if any) at a specified window
            position.
        r4   Nr   )r'   r   r(   r)   r*   Ú_is_inr,   )r   r8   r<   r1   r)   Zbdxr=   Zbdyr   r   r   r>   ‘  s$    zFeatureBar._feature_atc             C   s@   ||j ƒ   ko|| k n  o>||jƒ   ko:|| k S   S )zG Returns whether or not an event is within a specified bounds.
        )rA   rB   )r   r8   r<   r=   r9   r:   r   r   r   rW   °  s     zFeatureBar._is_inN)!Ú__name__Ú
__module__Ú__qualname__r   r   ZWindowr   r
   r   r   r   rE   r   r6   r7   r   r'   r   r3   r   r   r    r!   r"   r#   r$   r%   rS   rT   rU   rM   r>   rW   r   r   r   r   r   (   s.   


>)	?!r   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )rV   c             C   s   || | _ | _d S )N)r<   r=   )r   r<   r=   r   r   r   Ú__init__¼  s    zFakeEvent.__init__c             C   s   | j S )N)r<   )r   r   r   r   rA   ¿  s    zFakeEvent.GetXc             C   s   | j S )N)r=   )r   r   r   r   rB   À  s    zFakeEvent.GetYN)rX   rY   rZ   r[   rA   rB   r   r   r   r   rV   º  s   rV   )Ú__doc__r   Z
traits.apir   r   r   r   r   Zpyface.wx.drag_and_dropr   r   Z
dock_sizerr
   r   Zifeature_toolr   r   rL   rV   r   r   r   r   Ú<module>   s      