a
    §ˆc¥M  ã                   @   s  d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZ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 ddlmZmZmZ dd	lmZmZ dd
lm Z  ddl!Z!e! "e#¡Z$dZ%G dd„ deƒZ&G dd„ de&ƒZ'G dd„ de'ƒZ(G dd„ de'ƒZ)G dd„ de&ƒZ*dS )zv Defines the table column descriptor used by the editor and editor factory
    classes for numeric and table editors.
é    N)ÚAnyÚBoolÚCallableÚConstantÚDictÚEnumÚ
ExpressionÚFloatÚHasPrivateTraitsÚInstanceÚIntÚPropertyÚStrÚUnion)Úuser_name_forÚxgetattré   )ÚEditorFactory)ÚMenu)ÚImageÚAViewÚEditorStyle)ÚColorÚFont)ÚViewz???c                   @   sº  e Zd ZdZeeƒZeddƒZe	dƒZ
edeƒZe	ddd�Ze	d	dd�Ze	d
ƒZedg d¢ƒZedg d¢ƒZedƒZedƒZeZeZedƒZedƒZedƒZedƒZedƒZe e!ƒZ"eƒ Z#e$dƒZ%e$dƒZ&e$dƒZ'eddddƒZ(e)Z*e$dd�Z+dd„ Z,dd„ Z-dd„ Z.dd„ Z/d d!„ Z0d"d#„ Z1d$d%„ Z2d&d'„ Z3d(d)„ Z4d*d+„ Z5d,d-„ Z6d.d/„ Z7d0d1„ Z8d2d3„ Z9d4d5„ Z:d6d7„ Z;d8d9„ Z<d:d;„ Z=d<d=„ Z>d>d?„ Z?d@dA„ Z@dBdC„ ZAdDdE„ ZBdFdG„ ZCdHdI„ ZDdS )JÚTableColumnz&Represents a column in a table editor.ÚtextÚboolÚblackNZwhiteT)Ú
allow_noneiîóô iÌÙÝ Úleft)r    ÚcenterÚrightr!   )Útopr!   Zbottomé   é   Fg      ð¿ÚinteractiveÚfixedZstretchZresize_to_contents)Ztrait_valuec                 C   s   |S )z'Returns the actual object being edited.© ©ÚselfÚobjectr(   r(   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/table_column.pyÚ
get_objectš   s    zTableColumn.get_objectc                 C   s   | j S )úGets the label of the column.)Úlabel©r*   r(   r(   r,   Ú	get_labelž   s    zTableColumn.get_labelc                 C   s   | j S )z Returns the width of the column.)Úwidthr0   r(   r(   r,   Ú	get_width¢   s    zTableColumn.get_widthc                 C   s   | j S )z%Returns the edit width of the column.)Ú
edit_widthr)   r(   r(   r,   Úget_edit_width¦   s    zTableColumn.get_edit_widthc                 C   s   | j S )zVReturns the height of the column cell's row while it is being
        edited.
        )Úedit_heightr)   r(   r(   r,   Úget_edit_heightª   s    zTableColumn.get_edit_heightc                 C   s   | j S )z<Gets the type of data for the column for a specified object.©Útyper)   r(   r(   r,   Úget_type°   s    zTableColumn.get_typec                 C   s   | j S )z=Returns the text color for the column for a specified object.)Útext_color_r)   r(   r(   r,   Úget_text_color´   s    zTableColumn.get_text_colorc                 C   s   | j S )z<Returns the text font for the column for a specified object.)Ú	text_fontr)   r(   r(   r,   Úget_text_font¸   s    zTableColumn.get_text_fontc                 C   s   |   |¡r| jS | jS )zYReturns the cell background color for the column for a specified
        object.
        )Úis_editableÚcell_color_Úread_only_cell_color_r)   r(   r(   r,   Úget_cell_color¼   s    
zTableColumn.get_cell_colorc                 C   s   | j S )z_Returns the cell background graph color for the column for a
        specified object.
        )Zgraph_color_r)   r(   r(   r,   Úget_graph_colorÄ   s    zTableColumn.get_graph_colorc                 C   s   | j S )zXReturns the horizontal alignment for the column for a specified
        object.
        ©Úhorizontal_alignmentr)   r(   r(   r,   Úget_horizontal_alignmentÊ   s    z$TableColumn.get_horizontal_alignmentc                 C   s   | j S )zVReturns the vertical alignment for the column for a specified
        object.
        ©Úvertical_alignmentr)   r(   r(   r,   Úget_vertical_alignmentÐ   s    z"TableColumn.get_vertical_alignmentc                 C   s   | j S )zCReturns the image to display for the column for a specified object.)Úimager)   r(   r(   r,   Ú	get_imageÖ   s    zTableColumn.get_imagec                 C   s   | j S )z:Returns the renderer for the column of a specified object.)Úrendererr)   r(   r(   r,   Úget_rendererÚ   s    zTableColumn.get_rendererc                 C   s   | j S )z>Returns whether the column is editable for a specified object.©Úeditabler)   r(   r(   r,   r?   Þ   s    zTableColumn.is_editablec                 C   s   | j S )zbReturns whether the column is automatically edited/viewed for a
        specified object.
        )Úauto_editabler)   r(   r(   r,   Úis_auto_editableâ   s    zTableColumn.is_auto_editablec                 C   s   | j S )únReturns whether a specified value is valid for dropping on the
        column for a specified object.
        ©Ú	droppable©r*   r+   Úvaluer(   r(   r,   Úis_droppableè   s    zTableColumn.is_droppablec                 C   s   | j S )zuReturns the context menu to display when the user right-clicks on
        the column for a specified object.
        ©Úmenur)   r(   r(   r,   Úget_menuî   s    zTableColumn.get_menuc                 C   s   | j S )zlReturns the tooltip to display when the user mouses over the column
        for a specified object.
        )Útooltipr)   r(   r(   r,   Úget_tooltipô   s    zTableColumn.get_tooltipc                 C   s   | j S )z>Returns the view to display when clicking a non-editable cell.)Úviewr)   r(   r(   r,   Úget_viewú   s    zTableColumn.get_viewc                 C   s   | j S )z4Returns the maximum value a numeric column can have.)Úmaximumr)   r(   r(   r,   Úget_maximumþ   s    zTableColumn.get_maximumc                 C   s   dS ©z*Called when the user clicks on the column.Nr(   r)   r(   r(   r,   Úon_click  s    zTableColumn.on_clickc                 C   s   dS ra   r(   r)   r(   r(   r,   Ú	on_dclick  s    zTableColumn.on_dclickc                 C   s(   |   |¡|   |¡k|   |¡|   |¡k  S )zjReturns the result of comparing the column of two different objects.

        This is deprecated.
        )Úkey)r*   Zobject1Zobject2r(   r(   r,   Úcmp
  s    ÿzTableColumn.cmpc                 C   s   |   ¡ S )z6Returns the string representation of the table column.)r1   r0   r(   r(   r,   Ú__str__  s    zTableColumn.__str__)EÚ__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚUndefinedLabelr/   r   r9   r   Z
text_colorr   r   r=   Z
cell_colorZread_only_cell_colorZgraph_colorrE   rH   r   Zhorizontal_marginZvertical_marginr   rJ   r   rL   r   ÚvisiblerO   rP   Zshow_checkboxrT   r   r   rY   r[   r	   r2   r4   r6   Zresize_moder   r]   r_   r-   r1   r3   r5   r7   r:   r<   r>   rB   rC   rF   rI   rK   rM   r?   rQ   rW   rZ   r\   r^   r`   rb   rc   re   rf   r(   r(   r(   r,   r   5   sh   


	r   c                   @   sÊ   e Zd ZdZeƒ Zeƒ Zee	ƒZ
eZedƒZeƒ Zeg d¢g d¢g d¢dgg d¢dgd	d
gdgddgddgƒ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 )'ÚObjectColumnzA column for editing objects.ú%s)Únamer/   r9   ú|[Column Information])z!horizontal_alignment{Horizontal}@zvertical_alignment{Vertical}@z|[Alignment])rO   Ú9rT   rq   rl   z-[Options]>z	|{Column})útext_color@úcell_color@zread_only_cell_color@ú|[UI Colors]z	|{Colors}z
text_font@z	|[Font]<>z|{Font}zmenu@z|{Menu}zeditor@z	|{Editor}c                 C   s   | j dur| j S t| jƒS ©r.   N)Ú_labelr   ro   r0   r(   r(   r,   Ú
_get_labelN  s    
zObjectColumn._get_labelc                 C   s(   | j | }| _ ||kr$|  d||¡ d S ©Nr/   ©rv   Ztrait_property_changed©r*   r/   Úoldr(   r(   r,   Ú
_set_labelT  s    zObjectColumn._set_labelc              
   C   sR   zt |  |¡| jƒW S  tyL } z ddlm} |ƒ  W Y d}~dS d}~0 0 dS )ú@Gets the unformatted value of the column for a specified object.r   )Úraise_to_debugN)r   r-   ro   Ú	ExceptionZtraitsui.apir~   )r*   r+   Úer~   r(   r(   r,   Úget_raw_valueY  s    zObjectColumn.get_raw_valuec                 C   sV   z0| j dur|   |  |¡¡W S | j|  |¡f W S    t d| jj ¡ Y dS 0 dS )z>Gets the formatted value of the column for a specified object.Nz*Error occurred trying to format a %s valueúFormat!)Úformat_funcr�   ÚformatÚloggerÚ	exceptionÚ	__class__rg   r)   r(   r(   r,   Ú	get_valuec  s    
ÿÿzObjectColumn.get_valuec                 C   s
   |   |¡S )z&Returns the drag value for the column.©r�   r)   r(   r(   r,   Úget_drag_valueq  s    zObjectColumn.get_drag_valuec                 C   s   |   |¡\}}t|||ƒ dS ©z4Sets the value of the column for a specified object.N)Útarget_nameÚsetattr©r*   r+   rV   Útargetro   r(   r(   r,   Ú	set_valueu  s    zObjectColumn.set_valuec                 C   s,   | j dur| j S |  |¡\}}| |¡ ¡ S ©z5Gets the editor for the column of a specified object.N)ÚeditorrŒ   Ú
base_traitÚ
get_editor)r*   r+   r�   ro   r(   r(   r,   r”   z  s    
zObjectColumn.get_editorc                 C   s   | j S )z;Gets the editor style for the column of a specified object.)Ústyler)   r(   r(   r,   Ú	get_styleƒ  s    zObjectColumn.get_stylec                 C   s
   |   |¡S ©z%Returns the value to use for sorting.r‰   r)   r(   r(   r,   rd   ‡  s    zObjectColumn.keyc                 C   s@   | j r<z(|  |¡\}}| |¡ |||¡ W dS    Y n0 dS )rR   TF)rT   rŒ   r“   ÚvalidaterŽ   r(   r(   r,   rW   ‹  s    zObjectColumn.is_droppablec                 C   sL   |   |¡}| j}| d¡}|dk r*||fS t||d|… ƒ||d d… fS )z2Returns the target object and name for the column.Ú.r   Nr   )r-   ro   Úrfindr   )r*   r+   ro   Úcolr(   r(   r,   rŒ   ™  s    

zObjectColumn.target_nameN)rg   rh   ri   rj   r   ro   r   r/   r   r   r’   r   r•   r„   r   rƒ   r   Útraits_viewrw   r|   r�   rˆ   rŠ   r�   r”   r–   rd   rW   rŒ   r(   r(   r(   r,   rm     s>   øù	
ê
	rm   c                   @   s*   e Zd ZdZeZedƒZeƒ Z	dd„ Z
dS )ÚExpressionColumnz(A column for displaying computed values.Fc                 C   s@   zt | j| jd|iƒW S  ty:   t d| j ¡ Y dS 0 dS )r}   r+   z,Error evaluating table column expression: %sN)ÚevalZexpression_Úglobalsr   r…   r†   Ú
expressionr)   r(   r(   r,   r�   µ  s    ÿÿzExpressionColumn.get_raw_valueN)rg   rh   ri   rj   r   r    r   rO   r   rŸ   r�   r(   r(   r(   r,   r�   ¤  s
   r�   c                       s¾   e Zd ZdZeƒ ZedƒZeZ	edƒZ
edƒZ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‡ fd d!„Zd"d#„ Zd$d%„ Z‡  ZS )&ÚNumericColumnz$A column for editing Numeric arrays.r   iØÿØ rn   r!   c                 C   s   | j dur| j S | jS ru   )rv   ro   r0   r(   r(   r,   rw   Û  s    
zNumericColumn._get_labelc                 C   s(   | j | }| _ ||kr$|  d||¡ d S rx   ry   rz   r(   r(   r,   r|   á  s    zNumericColumn._set_labelc                 C   s   | j S )z@Gets the type of data for the column for a specified object row.r8   r)   r(   r(   r,   r:   æ  s    zNumericColumn.get_typec                 C   s   |   |¡r| jS | jS )zAReturns the text color for the column for a specified object row.)Ú_is_selectedZselected_text_color_r;   r)   r(   r(   r,   r<   ê  s    
zNumericColumn.get_text_colorc                 C   s   |   |¡r| jS | jS )z@Returns the text font for the column for a specified object row.)r¢   Úselected_text_fontr=   r)   r(   r(   r,   r>   ð  s    
zNumericColumn.get_text_fontc                 C   s&   |   |¡r |  |¡r| jS | jS | jS )z]Returns the cell background color for the column for a specified
        object row.
        )r?   r¢   Zselected_cell_color_r@   rA   r)   r(   r(   r,   rB   ö  s
    

zNumericColumn.get_cell_colorc                 C   s   | j S )z\Returns the horizontal alignment for the column for a specified
        object row.
        rD   r)   r(   r(   r,   rF      s    z&NumericColumn.get_horizontal_alignmentc                 C   s   | j S )zZReturns the vertical alignment for the column for a specified
        object row.
        rG   r)   r(   r(   r,   rI     s    z$NumericColumn.get_vertical_alignmentc                 C   s   | j S )zBReturns whether the column is editable for a specified object row.rN   r)   r(   r(   r,   r?     s    zNumericColumn.is_editablec                 C   s   | j S )zrReturns whether a specified value is valid for dropping on the
        column for a specified object row.
        rS   )r*   r+   ÚrowrV   r(   r(   r,   rW     s    zNumericColumn.is_droppablec                 C   s   | j S )zyReturns the context menu to display when the user right-clicks on
        the column for a specified object row.
        rX   )r*   r+   r¤   r(   r(   r,   rZ     s    zNumericColumn.get_menuc                 C   sF   z2t || jƒ}z| j|f W W S    Y W dS 0 W n   Y dS 0 dS )z8Gets the value of the column for a specified object row.r‚   z
Undefined!N)Úgetattrro   r„   rU   r(   r(   r,   rˆ     s    zNumericColumn.get_valuec                 C   s"   |   |¡}t|| ƒ|ƒ||< dS )z8Sets the value of the column for a specified object row.N)Úget_data_columnr9   )r*   r+   r¤   rV   Úcolumnr(   r(   r,   r�   '  s    
zNumericColumn.set_valuec                    s   t ƒ  |¡S )z9Gets the editor for the column of a specified object row.)Úsuperr”   r)   ©r‡   r(   r,   r”   ,  s    zNumericColumn.get_editorc                 C   s   t || jƒS )z8Gets the entire contents of the specified object column.)r¥   ro   r)   r(   r(   r,   r¦   0  s    zNumericColumn.get_data_columnc                 C   s   t |dƒr|jdurdS dS )z3Returns whether a specified object row is selected.Úmodel_selectionNTF)Úhasattrrª   r)   r(   r(   r,   r¢   4  s    ÿþzNumericColumn._is_selected)rg   rh   ri   rj   r   r/   r   Zselected_text_colorr   r£   Zselected_cell_colorr   r„   rE   rw   r|   r:   r<   r>   rB   rF   rI   r?   rW   rZ   rˆ   r�   r”   r¦   r¢   Ú__classcell__r(   r(   r©   r,   r¡   Á  s.   
r¡   c                   @   sd   e Zd ZdZeƒ Zeƒ ZdZe	g d¢g d¢gƒZ
dd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ ZdS )Ú
ListColumnzA column for editing lists.F)Úindexr/   r9   rp   )rr   rs   rt   c                 C   s   | j dur| j S d| jd  S )r.   Nz	Column %dr   )rv   r®   r0   r(   r(   r,   rw   Y  s    
zListColumn._get_labelc                 C   s(   | j | }| _ ||kr$|  d||¡ d S rx   ry   rz   r(   r(   r,   r|   _  s    zListColumn._set_labelc                 C   s   t || j ƒS )z4Gets the value of the column for a specified object.)Ústrr®   r)   r(   r(   r,   rˆ   d  s    zListColumn.get_valuec                 C   s   ||| j < dS r‹   ©r®   rU   r(   r(   r,   r�   h  s    zListColumn.set_valuec                 C   s   dS r‘   r(   r)   r(   r(   r,   r”   l  s    zListColumn.get_editorc                 C   s
   || j  S r—   r°   r)   r(   r(   r,   rd   p  s    zListColumn.keyN)rg   rh   ri   rj   r   r/   r   r®   rO   r   rœ   rw   r|   rˆ   r�   r”   rd   r(   r(   r(   r,   r­   >  s   þÿr­   )+rj   ÚosZ
traits.apir   r   r   r   r   r   r   r	   r
   r   r   r   r   r   Ztraits.trait_baser   r   Zeditor_factoryr   rY   r   Z	ui_traitsr   r   r   Ztoolkit_traitsr   r   r]   r   ÚloggingÚ	getLoggerrg   r…   rk   r   rm   r�   r¡   r­   r(   r(   r(   r,   Ú<module>   s$   @
 d }