a
    §ˆcã  ã                   @   sp   d Z ddlmZmZmZ ddl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 )ú( A model that provides data for a grid. é    )ÚGridTableBaseÚGridTableMessageÚGRIDTABLE_NOTIFY_ROWS_APPENDED)ÚAnyÚBoolÚ	HasTraitsÚ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 )Ú	GridModelr   Tc                 K   sv   t j| fi |¤Ž t| ƒ| _t| jƒdkrr| jdurrtdƒ g }tt| jd ƒƒD ]}| 	t
t|ƒd�¡ qR|| _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   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/wx/grid/grid_model.pyr   2   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   ÚGetNumberRowsI   s    zGridModel.GetNumberRowsc                 C   s
   t | jƒS ©z, Return the number of columns in the model. )r   r   r   r   r   r   ÚGetNumberColsN   s    zGridModel.GetNumberColsc                 C   s,   z| j | |  W S  ty&   Y dS 0 dS )ú Is the specified cell empty? TN©r   Ú
IndexError©r   ÚrowÚcolr   r   r   ÚIsEmptyCellS   s    zGridModel.IsEmptyCellc                 C   s(   z| j | | W S  ty"   Y n0 dS )ú0 Get the value at the specified row and column. Ú r#   r%   r   r   r   ÚGetValue_   s
    zGridModel.GetValuec                 C   s`   z|| j | |< W nH tyZ   | j  dg|  ¡  ¡ || j | |< t| tdƒ}|| _Y n0 dS )ú0 Set the value at the specified row and column. r   r   N)r   r$   r   r!   r   r   Úmodel_changed)r   r&   r'   ÚvalueÚmessager   r   r   ÚSetValuej   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   ÚGetColLabelValue‚   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   Útyper%   r   r   r   ÚGetTypeName‡   s    zGridModel.GetTypeNamec                 C   s   |   ||¡}||kS ©z} Called to determine how the data can be fetched.

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

        )r9   )r   r&   r'   Ú	type_nameZcolumn_typenamer   r   r   ÚCanGetValueAs‘   s    zGridModel.CanGetValueAsc                 C   s   |   |||¡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 )ú( 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   Úrowsr   r   r   Zshow_row_headersZshow_column_headersr	   r-   r   r   r!   r(   r+   r0   r3   r6   r9   r<   r?   rC   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   r   c                 C   s   t  | ¡ || _dS )z Creates a new table base. N)r   r   Úmodel)r   rI   r   r   r   r   À   s    
z_GridTableBase.__init__c                 C   s
   | j  ¡ S r   )rI   r   r   r   r   r   r   Ï   s    z_GridTableBase.GetNumberRowsc                 C   s
   | j  ¡ S r    )rI   r!   r   r   r   r   r!   Ô   s    z_GridTableBase.GetNumberColsc                 C   s   | j  ||¡S )r"   )rI   r(   r%   r   r   r   r(   Ù   s    z_GridTableBase.IsEmptyCellc                 C   s   | j  ||¡S )r)   )rI   r+   r%   r   r   r   r+   Þ   s    z_GridTableBase.GetValuec                 C   s   | j  |||¡S )r,   )rI   r0   )r   r&   r'   r.   r   r   r   r0   ã   s    z_GridTableBase.SetValuec                 C   s   | j  |¡S r1   )rI   r3   r2   r   r   r   r3   è   s    z_GridTableBase.GetRowLabelValuec                 C   s   | j  |¡S r4   )rI   r6   r5   r   r   r   r6   í   s    z_GridTableBase.GetColLabelValuec                 C   s   | j  ||¡S r7   )rI   r9   r%   r   r   r   r9   ò   s    z_GridTableBase.GetTypeNamec                 C   s   | j  |||¡S r:   )rI   r<   r>   r   r   r   r<   ü   s    z_GridTableBase.CanGetValueAsc                 C   s   | j  |||¡S r=   )rI   r?   r>   r   r   r   r?     s    z_GridTableBase.CanSetValueAsc                 C   s   | j  ||¡S )r@   )rI   rC   )r   rA   rB   r   r   r   rC     s    z_GridTableBase.DeleteRowsN)rD   rE   rF   rG   r   r   r!   r(   r+   r0   r3   r6   r9   r<   r?   rC   r   r   r   r   r   ¹   s   
		r   N)rG   Zwx.gridr   r   r   Z
traits.apir   r   r   r	   r
   Zgrid_columnr   Zgrid_rowr   r   r   r   r   r   r   Ú<module>   s    