3
7ßL]í   ã               @   sˆ   d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZdS )z( A model that provides data for a grid. é    )Úprint_functionN)ÚPyGridTableBaseÚGridTableMessageÚGRIDTABLE_NOTIFY_ROWS_APPENDED)ÚAnyÚBoolÚ	HasTraitsÚTraitÚEventÚListé   )Ú
GridColumn)ÚGridRowc               @   s˜   e Zd ZdZeZeeƒZee	ƒZ
edƒZedƒZe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 )Ú	GridModelz( A model that provides data for a grid. Tc             K   sv   t j| f|Ž t| ƒ| _t| jƒdkrr| jdk	rrtdƒ g }x.tt| jd ƒƒD ]}|j	t
t|ƒd�ƒ qPW || _dS )z Create a new grid model. r   Nz#Building default table column model)Úlabel)r   Ú__init__Ú_GridTableBaseZ_grid_table_baseÚlenÚcolumnsÚdataÚprintÚrangeÚappendr   Ústr)ÚselfZtraitsr   Úi© r   ú=/tmp/pip-install-5sebvq2j/pyface/pyface/wx/grid/grid_model.pyr   4   s    
zGridModel.__init__c             C   s
   t | jƒS )z) Return the number of rows in the model. )r   r   )r   r   r   r   ÚGetNumberRowsK   s    zGridModel.GetNumberRowsc             C   s
   t | jƒS )z, Return the number of columns in the model. )r   r   )r   r   r   r   ÚGetNumberColsP   s    zGridModel.GetNumberColsc             C   s*   y| j | |  S  tk
r$   dS X dS )z Is the specified cell empty? TN)r   Ú
IndexError)r   ÚrowÚcolr   r   r   ÚIsEmptyCellU   s    zGridModel.IsEmptyCellc             C   s(   y| j | | S  tk
r"   Y nX dS )z0 Get the value at the specified row and column. Ú )r   r    )r   r!   r"   r   r   r   ÚGetValuea   s
    zGridModel.GetValuec             C   sl   | j |ƒ}y|| j| |< W nJ tk
rf   | jjdg| jƒ  ƒ || j| |< t| tdƒ}|| _Y nX dS )z0 Set the value at the specified row and column. r   r   N)ÚGetColLabelValuer   r    r   r   r   r   Úmodel_changed)r   r!   r"   Úvaluer   Úmessager   r   r   ÚSetValuel   s    

zGridModel.SetValuec             C   s   t |ƒS )z4 Called when the grid needs to display a row label. )r   )r   r!   r   r   r   ÚGetRowLabelValue…   s    zGridModel.GetRowLabelValuec             C   s   | j | jS )z7 Called when the grid needs to display a column label. )r   r   )r   r"   r   r   r   r&   Š   s    zGridModel.GetColLabelValuec             C   s   | j | jS )zÇ Called to determine the kind of editor/renderer to use.

        This doesn't necessarily have to be the same type used natively by the
        editor/renderer if they know how to convert.

        )r   Útype)r   r!   r"   r   r   r   ÚGetTypeName�   s    zGridModel.GetTypeNamec             C   s   | j ||ƒ}||kS )z} Called to determine how the data can be fetched.

        This allows you to enforce some type-safety in the grid.

        )r-   )r   r!   r"   Ú	type_nameZcolumn_typenamer   r   r   ÚCanGetValueAs™   s    zGridModel.CanGetValueAsc             C   s   | j |||ƒS )z| Called to determine how the data can be stored.

        This allows you to enforce some type-safety in the grid.

        )r/   )r   r!   r"   r.   r   r   r   ÚCanSetValueAs¤   s    zGridModel.CanSetValueAsc             C   s(   | j ||| …= t| t| ƒ}|| _dS )z( Called when the view is deleting rows. T)r   r   r   r'   )r   ÚposÚnum_rowsr)   r   r   r   Ú
DeleteRows­   s
    zGridModel.DeleteRowsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Zrowsr   r   r   Zshow_row_headersZshow_column_headersr
   r'   r   r   r   r#   r%   r*   r+   r&   r-   r/   r0   r3   r   r   r   r   r      s&   
	r   c               @   sp   e Z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S )r   z( A model that provides data for a grid. c             C   s   t j| ƒ || _dS )z Creates a new table base. N)r   r   Úmodel)r   r8   r   r   r   r   È   s    
z_GridTableBase.__init__c             C   s
   | j jƒ S )z) Return the number of rows in the model. )r8   r   )r   r   r   r   r   ×   s    z_GridTableBase.GetNumberRowsc             C   s
   | j jƒ S )z, Return the number of columns in the model. )r8   r   )r   r   r   r   r   Ü   s    z_GridTableBase.GetNumberColsc             C   s   | j j||ƒS )z Is the specified cell empty? )r8   r#   )r   r!   r"   r   r   r   r#   á   s    z_GridTableBase.IsEmptyCellc             C   s   | j j||ƒS )z0 Get the value at the specified row and column. )r8   r%   )r   r!   r"   r   r   r   r%   æ   s    z_GridTableBase.GetValuec             C   s   | j j|||ƒS )z0 Set the value at the specified row and column. )r8   r*   )r   r!   r"   r(   r   r   r   r*   ë   s    z_GridTableBase.SetValuec             C   s   | j j|ƒS )z4 Called when the grid needs to display a row label. )r8   r+   )r   r!   r   r   r   r+   ð   s    z_GridTableBase.GetRowLabelValuec             C   s   | j j|ƒS )z7 Called when the grid needs to display a column label. )r8   r&   )r   r"   r   r   r   r&   õ   s    z_GridTableBase.GetColLabelValuec             C   s   | j j||ƒS )zÇ Called to determine the kind of editor/renderer to use.

        This doesn't necessarily have to be the same type used natively by the
        editor/renderer if they know how to convert.

        )r8   r-   )r   r!   r"   r   r   r   r-   ú   s    z_GridTableBase.GetTypeNamec             C   s   | j j|||ƒS )z} Called to determine how the data can be fetched.

        This allows you to enforce some type-safety in the grid.

        )r8   r/   )r   r!   r"   r.   r   r   r   r/     s    z_GridTableBase.CanGetValueAsc             C   s   | j j|||ƒS )z| Called to determine how the data can be stored.

        This allows you to enforce some type-safety in the grid.

        )r8   r0   )r   r!   r"   r.   r   r   r   r0     s    z_GridTableBase.CanSetValueAsc             C   s   | j j||ƒS )z( Called when the view is deleting rows. )r8   r3   )r   r1   r2   r   r   r   r3     s    z_GridTableBase.DeleteRowsN)r4   r5   r6   r7   r   r   r   r#   r%   r*   r+   r&   r-   r/   r0   r3   r   r   r   r   r   Á   s   
		r   )r7   Ú
__future__r   ZwxZwx.gridr   r   r   Z
traits.apir   r   r   r	   r
   r   Zgrid_columnr   Zgrid_rowr   r   r   r   r   r   r   Ú<module>   s     %