a
    §ˆc‚  ã                   @   s4   d Z ddlmZmZ ddlmZ G dd„ deƒZdS )zf A renderer which displays a checked-box for a True value and an unchecked
    box for a false value.
é    )ÚQtCoreÚQtGui)ÚTableDelegatec                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCheckboxRendererziA renderer which displays a checked-box for a True value and an
    unchecked box for a false value.
    c                 C   sp   |  ¡ tjjjkrh| ¡ tjjjkrh| 	¡ j
j| ¡  }| tjjj¡}t| |¡ƒ}| || ¡ dS dS dS )z,Reimplemented to handle mouse button clicks.TFN)Útyper   ZQEventÚTypeZMouseButtonReleaseÚbuttonÚQtZMouseButtonZ
LeftButtonÚmodelÚ_editorÚcolumnsÚcolumnÚdataÚItemDataRoleÚUserRoleÚboolÚget_raw_valueÚ	set_value)ÚselfÚeventr
   ÚoptionÚindexr   ÚobjÚchecked© r   úg/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/extra/checkbox_renderer.pyÚeditorEvent   s    ÿþzCheckboxRenderer.editorEventc                 C   sL  |  ¡ jj| ¡  }| tjjj¡}| 	|¡}| 
¡  |j ¡ |j ¡ g}|jtjjj@ r–|jtjjj@ rvtjjj}n
tjjj}|j |tjjj¡}	nH| tjjj¡}	|	tks¶|	du rÞ|  ¡ jjjrÖ|| ¡ d  }	n|d }	|  |j!|	¡ tj" #¡  $¡ }
t %¡ }|j|_|j!|_!|
 &tjj'j(|t )¡ d¡}|j! *| +¡ ¡ |
 ,tjj-j.|¡}|j/}|dk�rv|j! 0|j! 1¡ | ¡ n^|dk�r |j! 0|j! 2¡ | +¡  | ¡ n4|j! 0|j! 1¡ |j! +¡ d  | +¡ d  | d ¡ |jtjjj3@ �rütjjj3tjjjB |_|�r| jtjjj4O  _n| jtjjj5O  _|
 6tjj7j8||¡ | 9¡  dS )z$Reimplemented to paint the checkbox.Né   r   ÚleftÚright):r
   r   r   r   r   r   r	   r   r   r   ÚsaveZpaletteÚbaseZalternateBaseÚstater   ÚQStyleZ	StateFlagZState_SelectedZState_ActiveZQPaletteZ
ColorGroupZActiveZInactiveZbrushZ	ColorRoleZ	HighlightZBackgroundRoleÚNotImplementedÚfactoryZalternate_bg_colorÚrowZfillRectZrectÚQApplicationÚinstanceÚstyleÚQStyleOptionButtonÚsizeFromContentsÚContentsTypeÚCT_CheckBoxÚQSizeZsetWidthÚwidthZpixelMetricZPixelMetricZPM_ButtonMarginZhorizontal_alignmentZsetLeftr   r   ZState_EnabledZState_OnZ	State_OffZdrawControlZControlElementZCE_CheckBoxÚrestore)r   Zpainterr   r   r   r   r   Zrow_brushesZcolor_groupZbg_brushr)   ÚboxÚsizeÚmarginÚ	alignmentr   r   r   Úpaint-   sd    


ÿÿ

 ÿ
þýüÿ
zCheckboxRenderer.paintc                 C   s0   t  ¡ }t j ¡  ¡ }| t jjj|t	 
¡ d¡S )z6Reimplemented to provide size hint based on a checkboxN)r   r*   r'   r(   r)   r+   r#   r,   r-   r   r.   )r   r   r   r1   r)   r   r   r   ÚsizeHinto   s
    ÿzCheckboxRenderer.sizeHintN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r5   r6   r   r   r   r   r      s   Br   N)r:   Z	pyface.qtr   r   Ztraitsui.qt4.table_editorr   r   r   r   r   r   Ú<module>   s   