a
    §ˆcÁ  ã                   @   sH   d Z ddlZddlZddlmZmZmZ ddlmZ G dd„ deƒZ	dS )ú3 A clickable/draggable widget containing an image. é    N)ÚAnyÚBoolÚEventé   )ÚLayoutWidgetc                       s¬   e Zd ZdZeƒ ZedƒZeƒ Z	eƒ Z
eƒ Zeƒ Zeƒ Zeƒ Zeƒ Zeƒ Z‡ f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d„Zddd„Z‡  ZS )ÚImageWidgetr   Fc                    s>   |  dd¡}tƒ jf d|i|¤Ž |r:|  ¡  t dt¡ dS )z Creates a new widget. ÚcreateTÚparentzšautomatic widget creation is deprecated and will be removed in a future Pyface version, use create=False and explicitly call create() for future behaviourN)ÚpopÚsuperÚ__init__r	   ÚwarningsÚwarnÚPendingDeprecationWarning)Úselfr
   Ztraitsr	   ©Ú	__class__© ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/ui/wx/image_widget.pyr   @   s    üzImageWidget.__init__c                 C   sì   | j  ¡ d | j  ¡ d f}tj|d|d�| _d| j_d| _d| _| j 	tj
| j¡ | j 	tj| j¡ | j 	tj| j¡ | j 	tj| j¡ | j 	tj| j¡ | j 	tj| j¡ t tj tj¡dtj¡| _t tj tj¡dtj¡| _| jS )Né
   éÿÿÿÿ)ÚsizeZhackFr   )ÚbitmapÚGetWidthÚ	GetHeightÚwxZWindowÚcontrolÚ__tag__Ú_mouse_overÚ_button_downZBindZEVT_ENTER_WINDOWÚ_on_enter_windowZEVT_LEAVE_WINDOWÚ_on_leave_windowZEVT_LEFT_DCLICKÚ_on_left_dclickZEVT_LEFT_DOWNÚ_on_left_downZEVT_LEFT_UPÚ_on_left_upZ	EVT_PAINTÚ	_on_paintZPenZSystemSettingsZ	GetColourZSYS_COLOUR_3DSHADOWZSOLIDÚ_selectedPenDarkZSYS_COLOUR_3DHIGHLIGHTÚ_selectedPenLight)r   r
   r   r   r   r   Ú_create_controlS   s$    ÿÿzImageWidget._create_controlc                 C   s   | j dur| j  ¡  dS )z- Called when the widget's bitmap is changed. N)r   ÚRefresh)r   r   r   r   r   Ú_bitmap_changedx   s    
zImageWidget._bitmap_changedc                 C   sB   |r>|   ¡  ¡ D ],}t|dƒr4| ¡ r4| d¡  q>|  ¡  qdS )z: Called when the selected state of the widget is changed. r   FN)Z	GetParentZGetChildrenÚhasattrÚSelectedr*   )r   Úselectedr   r   r   r   Ú_selected_changed~   s    


zImageWidget._selected_changedc                 C   s   | j durd| _|  ¡  dS )z* Called when the mouse enters the widget. NT)Ú	_selectedr   r*   ©r   Úeventr   r   r   r!   Ž   s    
zImageWidget._on_enter_windowc                 C   s   | j rd| _ |  ¡  dS )z* Called when the mouse leaves the widget. FN)r   r*   r1   r   r   r   r"   •   s    zImageWidget._on_leave_windowc                 C   s   |  ¡  dS )z6 Called when the left mouse button is double-clicked. N)ÚSkipr1   r   r   r   r#   œ   s    zImageWidget._on_left_dclickNc                 C   s,   | j dur |  ¡  d| _|  ¡  | ¡  dS )z< Called when the left mouse button goes down on the widget. NT)r0   ZCaptureMouser    r*   r3   r1   r   r   r   r$   £   s
    
zImageWidget._on_left_downc                 C   s°   | j }|r|  ¡  d| _ | jdur˜|  ¡  ¡ \}}| ¡ }| ¡ }d|  krV|k r˜n n>d|  krn|k r˜n n&| jdkrˆ|  d¡ n|r”|  ¡  dS |r¤|  ¡  | 	¡  dS )z: Called when the left mouse button goes up on the widget. FNr   r   T)
r    ZReleaseMouser0   ÚGetClientSizeÚGetZGetXZGetYr-   r*   r3   )r   r2   Zneed_refreshÚwdxÚwdyÚxÚyr   r   r   r%   ¯   s"    
0
zImageWidget._on_left_upc           
      C   sä  t  | j¡}| j ¡  ¡ \}}| j}| ¡ }| ¡ }| ||| d || d d¡ | j	| j
g}| j}	| jrì| t j¡ | ||	 ¡ | dd|d¡ | ddd|¡ | |d|	  ¡ | |d d|d |¡ | d|d |d |d ¡ | j�rà| t j¡ | ||	 ¡ | dd|d d¡ | ddd|d ¡ | dd|d d¡ | ddd|d ¡ | |d|	  ¡ | |d d|d |d ¡ | d|d |d |d ¡ | |d d|d |d ¡ | d|d |d |d ¡ dS )z* Called when the widget needs repainting. é   Tr   r   é   N)r   ZPaintDCr   r4   r5   r   r   r   Z
DrawBitmapr(   r'   r    r   ZSetBrushZTRANSPARENT_BRUSHZSetPenZDrawLiner0   )
r   r2   Zwdcr6   r7   r   ZbdxZbdyZpensZbdr   r   r   r&   Ê   s:     zImageWidget._on_paint)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r.   r   Zkey_pressedZnode_activatedZnode_begin_dragZnode_collapsedZnode_expandedZnode_left_clickedZnode_right_clickedr0   r   r)   r+   r/   r!   r"   r#   r$   r%   r&   Ú__classcell__r   r   r   r   r      s*   %

r   )
r?   r   r   Z
traits.apir   r   r   Zlayout_widgetr   r   r   r   r   r   Ú<module>   s
   