3
8ßL]g…  ã               @   s  d Z ddlmZm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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! ddl"Z"ddl#Z#e"j$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.
é    )Úabsolute_importÚprint_functionN)ÚAnyÚBoolÚCallableÚColorÚConstantÚEitherÚEnumÚ
ExpressionÚFloatÚFontÚHasPrivateTraitsÚInstanceÚIntÚPropertyÚStr)Úuser_name_forÚxgetattré   )ÚEditorFactory)ÚMenu)ÚImageÚAViewÚEditorStyle)ÚViewz???c               @   s¸  e Zd ZdZeeƒZedƒZe	dƒZ
eZee	dƒdƒZee	dƒdƒZe	dƒZeddd	d
gƒZed	dd	dgƒ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$dIƒZ%e$dJƒZ&e$dKƒ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.„ Z7d/d0„ Z8d1d2„ Z9d3d4„ Z:d5d6„ Z;d7d8„ Z<d9d:„ Z=d;d<„ Z>d=d>„ Z?d?d@„ Z@dAdB„ ZAdCdD„ ZBdEdF„ ZCdGdH„ ZDdS )LÚTableColumnz, Represents a column in a table editor.
    ÚtextÚblackZwhiteNiîóô iÌÙÝ ÚleftÚcenterÚrightÚtopZbottomé   é   TFg      ð?ÚinteractiveZfixedZstretchZresize_to_contents)Ztrait_valuec             C   s   |S )z1 Returns the actual object being edited.
        © )ÚselfÚobjectr&   r&   ú;/tmp/pip-install-5sebvq2j/traitsui/traitsui/table_column.pyÚ
get_object­   s    zTableColumn.get_objectc             C   s   | j S )z' 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.
        )Úwidth)r'   r&   r&   r)   Ú	get_width¿   s    zTableColumn.get_widthc             C   s   | j S )z/ Returns the edit width of the column.
        )Ú
edit_width)r'   r(   r&   r&   r)   Úget_edit_widthÈ   s    zTableColumn.get_edit_widthc             C   s   | j S )z[ Returns the height of the column cell's row while it is being
            edited.
        )Úedit_height)r'   r(   r&   r&   r)   Úget_edit_heightÑ   s    zTableColumn.get_edit_heightc             C   s   | j S )zF Gets the type of data for the column for a specified object.
        )Útype)r'   r(   r&   r&   r)   Úget_typeÛ   s    zTableColumn.get_typec             C   s   | j S )zG Returns the text color for the column for a specified object.
        )Útext_color_)r'   r(   r&   r&   r)   Úget_text_colorä   s    zTableColumn.get_text_colorc             C   s   | j S )zF Returns the text font for the column for a specified object.
        )Ú	text_font)r'   r(   r&   r&   r)   Úget_text_fontí   s    zTableColumn.get_text_fontc             C   s   | j |ƒr| jS | jS )z^ Returns the cell background color for the column for a specified
            object.
        )Úis_editableÚcell_color_Úread_only_cell_color_)r'   r(   r&   r&   r)   Úget_cell_colorö   s    
zTableColumn.get_cell_colorc             C   s   | j S )zd Returns the cell background graph color for the column for a
            specified object.
        )Zgraph_color_)r'   r(   r&   r&   r)   Úget_graph_color  s    zTableColumn.get_graph_colorc             C   s   | j S )z] Returns the horizontal alignment for the column for a specified
            object.
        )Úhorizontal_alignment)r'   r(   r&   r&   r)   Úget_horizontal_alignment  s    z$TableColumn.get_horizontal_alignmentc             C   s   | j S )z[ Returns the vertical alignment for the column for a specified
            object.
        )Úvertical_alignment)r'   r(   r&   r&   r)   Úget_vertical_alignment  s    z"TableColumn.get_vertical_alignmentc             C   s   | j S )zM Returns the image to display for the column for a specified object.
        )Úimage)r'   r(   r&   r&   r)   Ú	get_image!  s    zTableColumn.get_imagec             C   s   | j S )zD Returns the renderer for the column of a specified object.
        )Úrenderer)r'   r(   r&   r&   r)   Úget_renderer*  s    zTableColumn.get_rendererc             C   s   | j S )zH Returns whether the column is editable for a specified object.
        )Úeditable)r'   r(   r&   r&   r)   r9   3  s    zTableColumn.is_editablec             C   s   | j S )zg Returns whether the column is automatically edited/viewed for a
            specified object.
        )Úauto_editable)r'   r(   r&   r&   r)   Úis_auto_editable=  s    zTableColumn.is_auto_editablec             C   s   | j S )zs Returns whether a specified value is valid for dropping on the
            column for a specified object.
        )Ú	droppable)r'   r(   Úvaluer&   r&   r)   Úis_droppableH  s    zTableColumn.is_droppablec             C   s   | j S )zz Returns the context menu to display when the user right-clicks on
            the column for a specified object.
        )Úmenu)r'   r(   r&   r&   r)   Úget_menuS  s    zTableColumn.get_menuc             C   s   | j S )zq Returns the tooltip to display when the user mouses over the column
            for a specified object.
        )Útooltip)r'   r(   r&   r&   r)   Úget_tooltip^  s    zTableColumn.get_tooltipc             C   s   | j S )zH Returns the view to display when clicking a non-editable cell.
        )Úview)r'   r(   r&   r&   r)   Úget_viewh  s    zTableColumn.get_viewc             C   s   | j S )z> Returns the maximum value a numeric column can have.
        )Úmaximum)r'   r(   r&   r&   r)   Úget_maximumq  s    zTableColumn.get_maximumc             C   s   dS )z4 Called when the user clicks on the column.
        Nr&   )r'   r(   r&   r&   r)   Úon_clickz  s    zTableColumn.on_clickc             C   s   dS )z4 Called when the user clicks on the column.
        Nr&   )r'   r(   r&   r&   r)   Ú	on_dclickƒ  s    zTableColumn.on_dclickc             C   s(   | j |ƒ| j |ƒk| j |ƒ| j |ƒk  S )zk Returns 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   | j ƒ S )z@ Returns the string representation of the table column.
        )r,   )r'   r&   r&   r)   Ú__str__˜  s    zTableColumn.__str__g      ð¿g      ð¿g      ð¿)EÚ__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚUndefinedLabelr+   r
   r3   r   Z
text_colorr   r7   r	   Z
cell_colorZread_only_cell_colorZgraph_colorr>   r@   r   Zhorizontal_marginZvertical_marginr   rB   r   rD   r   ÚvisiblerF   rG   Zshow_checkboxrI   r   r   rL   rN   r   r-   r/   r1   Zresize_moder   rP   rR   r*   r,   r.   r0   r2   r4   r6   r8   r<   r=   r?   rA   rC   rE   r9   rH   rK   rM   rO   rQ   rS   rT   rU   rW   rX   r&   r&   r&   r)   r   H   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ddddgddd	gd
dddddgdgddddg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d0d1„ Zd2S )3ÚObjectColumnz# A column for editing objects.
    z%sÚnamer+   r3   z|[Column Information]z!horizontal_alignment{Horizontal}@zvertical_alignment{Vertical}@z|[Alignment]rF   Ú9rI   r^   z-[Options]>z	|{Column}ztext_color@zcell_color@zread_only_cell_color@z|[UI Colors]z	|{Colors}z
text_font@z	|[Font]<>z|{Font}zmenu@z|{Menu}zeditor@z	|{Editor}c             C   s   | j dk	r| j S t| jƒS )z' Gets the label of the column.
        N)Ú_labelr   r`   )r'   r&   r&   r)   Ú
_get_labelØ  s    
zObjectColumn._get_labelc             C   s(   | j | }| _ ||kr$| jd||ƒ d S )Nr+   )rb   Útrait_property_changed)r'   r+   Úoldr&   r&   r)   Ú
_set_labelß  s    zObjectColumn._set_labelc             C   sJ   yt | j|ƒ| jƒS  tk
rD } zddlm} |ƒ  dS d}~X nX dS )zJ Gets the unformatted value of the column for a specified object.
        r   )Úraise_to_debugN)r   r*   r`   Ú	ExceptionZtraitsui.apirg   )r'   r(   Úerg   r&   r&   r)   Úget_raw_valueè  s    zObjectColumn.get_raw_valuec          	   C   sN   y,| j dk	r| j | j|ƒƒS | j| j|ƒf S    tjd| jj ƒ dS dS )zH Gets the formatted value of the column for a specified object.
        Nz*Error occurred trying to format a %s valuezFormat!)Úformat_funcrj   ÚformatÚloggerÚ	exceptionÚ	__class__rY   )r'   r(   r&   r&   r)   Ú	get_valueò  s    
zObjectColumn.get_valuec             C   s
   | j |ƒS )z/Returns the drag value for the column.
        )rj   )r'   r(   r&   r&   r)   Úget_drag_value  s    zObjectColumn.get_drag_valuec             C   s   | j |ƒ\}}t|||ƒ dS )z> Sets the value of the column for a specified object.
        N)Útarget_nameÚsetattr)r'   r(   rJ   Útargetr`   r&   r&   r)   Ú	set_value  s    zObjectColumn.set_valuec             C   s,   | j dk	r| j S | j|ƒ\}}|j|ƒjƒ S )z? Gets the editor for the column of a specified object.
        N)Úeditorrr   Ú
base_traitÚ
get_editor)r'   r(   rt   r`   r&   r&   r)   rx     s    
zObjectColumn.get_editorc             C   s   | j S )zE Gets the editor style for the column of a specified object.
        )Ústyle)r'   r(   r&   r&   r)   Ú	get_style$  s    zObjectColumn.get_stylec             C   s
   | j |ƒS )z/ Returns the value to use for sorting.
        )rj   )r'   r(   r&   r&   r)   rV   -  s    zObjectColumn.keyc          
   C   s>   | j r:y&| j|ƒ\}}|j|ƒj|||ƒ dS    Y nX dS )zs Returns whether a specified value is valid for dropping on the
            column for a specified object.
        TF)rI   rr   rw   Úvalidate)r'   r(   rJ   rt   r`   r&   r&   r)   rK   7  s    zObjectColumn.is_droppablec             C   sL   | j |ƒ}| j}|jdƒ}|dk r*||fS t||d|… ƒ||d d… fS )z< Returns the target object and name for the column.
        Ú.r   Nr   )r*   r`   Úrfindr   )r'   r(   r`   Úcolr&   r&   r)   rr   I  s    

zObjectColumn.target_nameN)rY   rZ   r[   r\   r   r`   r   r+   r   r   rv   r   ry   rl   r   rk   r   Útraits_viewrc   rf   rj   rp   rq   ru   rx   rz   rV   rK   rr   r&   r&   r&   r)   r_   ¢  sJ   
	
	
	
r_   c               @   s,   e Zd ZdZeZedƒZei ƒZ	dd„ Z
dS )ÚExpressionColumnz. A column for displaying computed values.
    Fc             C   s>   yt | j| jd|iƒS  tk
r8   tjd| j ƒ dS X dS )zJ Gets the unformatted value of the column for a specified object.
        r(   z,Error evaluating table column expression: %sN)ÚevalZexpression_Úglobalsrh   rm   rn   Ú
expression)r'   r(   r&   r&   r)   rj   o  s    
zExpressionColumn.get_raw_valueN)rY   rZ   r[   r\   r   rƒ   r   rF   r   r‚   rj   r&   r&   r&   r)   r€   Y  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ØÿØ z%sr    c             C   s   | j dk	r| j S | jS )z' Gets the label of the column.
        N)rb   r`   )r'   r&   r&   r)   rc   �  s    
zNumericColumn._get_labelc             C   s(   | j | }| _ ||kr$| jd||ƒ d S )Nr+   )rb   rd   )r'   r+   re   r&   r&   r)   rf   ¤  s    zNumericColumn._set_labelc             C   s   | j S )zJ Gets the type of data for the column for a specified object row.
        )r3   )r'   r(   r&   r&   r)   r4   ­  s    zNumericColumn.get_typec             C   s   | j |ƒr| jS | jS )zK Returns the text color for the column for a specified object row.
        )Ú_is_selectedZselected_text_color_r5   )r'   r(   r&   r&   r)   r6   ¶  s    
zNumericColumn.get_text_colorc             C   s   | j |ƒr| jS | jS )zJ Returns the text font for the column for a specified object row.
        )r…   Úselected_text_fontr7   )r'   r(   r&   r&   r)   r8   Á  s    
zNumericColumn.get_text_fontc             C   s&   | j |ƒr | j|ƒr| jS | jS | jS )zb Returns the cell background color for the column for a specified
            object row.
        )r9   r…   Zselected_cell_color_r:   r;   )r'   r(   r&   r&   r)   r<   Í  s
    

zNumericColumn.get_cell_colorc             C   s   | j S )za Returns the horizontal alignment for the column for a specified
            object row.
        )r>   )r'   r(   r&   r&   r)   r?   Ü  s    z&NumericColumn.get_horizontal_alignmentc             C   s   | j S )z_ Returns the vertical alignment for the column for a specified
            object row.
        )r@   )r'   r(   r&   r&   r)   rA   æ  s    z$NumericColumn.get_vertical_alignmentc             C   s   | j S )zL Returns whether the column is editable for a specified object row.
        )rF   )r'   r(   r&   r&   r)   r9   ð  s    zNumericColumn.is_editablec             C   s   | j S )zw Returns whether a specified value is valid for dropping on the
            column for a specified object row.
        )rI   )r'   r(   ÚrowrJ   r&   r&   r)   rK   ú  s    zNumericColumn.is_droppablec             C   s   | j S )z~ Returns the context menu to display when the user right-clicks on
            the column for a specified object row.
        )rL   )r'   r(   r‡   r&   r&   r)   rM     s    zNumericColumn.get_menuc             C   s8   y(t || jƒ}y| j|f S    dS W n
   dS dS )zB Gets the value of the column for a specified object row.
        zFormat!z
Undefined!N)Úgetattrr`   rl   )r'   r(   rJ   r&   r&   r)   rp     s    zNumericColumn.get_valuec             C   s"   | j |ƒ}t|| ƒ|ƒ||< dS )zB Sets the value of the column for a specified object row.
        N)Úget_data_columnr3   )r'   r(   r‡   rJ   Úcolumnr&   r&   r)   ru     s    
zNumericColumn.set_valuec                s   t t| ƒj|ƒS )zC Gets the editor for the column of a specified object row.
        )Úsuperr„   rx   )r'   r(   )ro   r&   r)   rx   )  s    zNumericColumn.get_editorc             C   s   t || jƒS )zB Gets the entire contents of the specified object column.
        )rˆ   r`   )r'   r(   r&   r&   r)   r‰   2  s    zNumericColumn.get_data_columnc             C   s   t |dƒr|jdk	rdS dS )z= Returns whether a specified object row is selected.
        Úmodel_selectionNTF)ÚhasattrrŒ   )r'   r(   r&   r&   r)   r…   ;  s    

zNumericColumn._is_selected)rY   rZ   r[   r\   r   r+   r   Zselected_text_colorr   r†   Zselected_cell_colorr   rl   r>   rc   rf   r4   r6   r8   r<   r?   rA   r9   rK   rM   rp   ru   rx   r‰   r…   Ú__classcell__r&   r&   )ro   r)   r„   ~  s.   		




		r„   c               @   sf   e Zd ZdZeZeZdZe	ddddgddd	g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+   r3   z|[Column Information]ztext_color@zcell_color@z|[UI Colors]c             C   s   | j dk	r| j S d| jd  S )z' Gets the label of the column.
        Nz	Column %dr   )rb   r�   )r'   r&   r&   r)   rc   d  s    
zListColumn._get_labelc             C   s(   | j | }| _ ||kr$| jd||ƒ d S )Nr+   )rb   rd   )r'   r+   re   r&   r&   r)   rf   k  s    zListColumn._set_labelc             C   s   t j|| j ƒS )z> Gets the value of the column for a specified object.
        )ÚsixÚ	text_typer�   )r'   r(   r&   r&   r)   rp   t  s    zListColumn.get_valuec             C   s   ||| j < dS )z> Sets the value of the column for a specified object.
        N)r�   )r'   r(   rJ   r&   r&   r)   ru   }  s    zListColumn.set_valuec             C   s   dS )z? Gets the editor for the column of a specified object.
        Nr&   )r'   r(   r&   r&   r)   rx   †  s    zListColumn.get_editorc             C   s
   || j  S )z/ Returns the value to use for sorting.
        )r�   )r'   r(   r&   r&   r)   rV   �  s    zListColumn.keyN)rY   rZ   r[   r\   r   r+   r   r�   rF   r   r   rc   rf   rp   ru   rx   rV   r&   r&   r&   r)   r�   H  s   				r�   )-r\   Ú
__future__r   r   ÚosZ
traits.apir   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Ztraits.trait_baser   r   Zeditor_factoryr   rL   r   Z	ui_traitsr   r   r   rP   r   Úloggingr‘   Ú	getLoggerrY   rm   r]   r   r_   r€   r„   r�   r&   r&   r&   r)   Ú<module>   s*   D
  \ 8% K