a
    §ˆc8#  ã                   @   sT   d dl mZmZmZ d dl mZmZ d dl mZmZ d dl mZ G dd„ deƒZ	dS )é    )ÚPyGridTableBaseÚGridCellAttrÚGridTableMessage)ÚGRIDTABLE_NOTIFY_ROWS_DELETEDÚGRIDTABLE_NOTIFY_ROWS_APPENDED)ÚGRIDTABLE_NOTIFY_COLS_DELETEDÚGRIDTABLE_NOTIFY_COLS_APPENDED)Ú!GRIDTABLE_REQUEST_VIEW_GET_VALUESc                   @   s¨   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d„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(S ))ÚVirtualModelz„
    A custom wxGrid Table that expects a user supplied data source.
    THIS CLASS IS NOT LIMITED TO ONLY DISPLAYING LOG DATA!
    c                 C   s2   t  | ¡ |  |¡ || _|  ¡ | _|  ¡ | _dS )z�data is currently a list of the form
        [(rowname, dictionary),
        dictionary.get(colname, None) returns the data for a cell
        N)r   Ú__init__Úset_data_sourceÚcolnamesÚGetNumberRowsÚ_rowsÚGetNumberColsÚ_cols)ÚselfÚdataZcolumn_names© r   úf/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/wx/spreadsheet/virtual_model.pyr   "   s
    


zVirtualModel.__init__c                 C   s
   t | jƒS ©N)Úlenr   ©r   r   r   r   r   5   s    zVirtualModel.GetNumberColsc                 C   s
   t | jƒS r   )r   Ú_datar   r   r   r   r   8   s    zVirtualModel.GetNumberRowsc                 C   s
   | j | S r   )r   )r   Úcolr   r   r   ÚGetColLabelValue;   s    zVirtualModel.GetColLabelValuec                 C   s   | j | d S )Nr   ©r   )r   Úrowr   r   r   ÚGetRowLabelValue>   s    zVirtualModel.GetRowLabelValuec                 C   s    t | j| d  |  |¡d¡ƒS ©Né   Ú )Ústrr   Úgetr   ©r   r   r   r   r   r   ÚGetValueA   s    zVirtualModel.GetValuec                 C   s   | j | d  |  |¡d¡S r   )r   r#   r   r$   r   r   r   ÚGetRawValueD   s    zVirtualModel.GetRawValuec                 C   sR   t d|||f ƒ t d|  ||¡ƒ || j| d |  |¡< t d|  ||¡ƒ d S )NzSetting value %d %d %szBefore r    zAfter )Úprintr%   r   r   )r   r   r   Úvaluer   r   r   ÚSetValueG   s    zVirtualModel.SetValuec                 C   s   | j S )z4 The data structure we provide the data in.
        r   r   r   r   r   Úget_data_sourceZ   s    zVirtualModel.get_data_sourcec                 C   s
   || _ d S r   r   )r   Úsourcer   r   r   r   _   s    zVirtualModel.set_data_sourcec                 C   s¼   |  ¡  | j|  ¡ ttf| j|  ¡ ttffD ]^\}}}}||k r^t	| |||| ƒ}| 
|¡ q,||kr,t	| ||| ƒ}| 
|¡ |  |¡ q,| ¡  |  ¡ | _|  ¡ | _| ¡  | ¡  dS )zˆ
        (wxGrid) -> Reset the grid view.   Call this to
        update the grid if rows and columns have been added or deleted
        N)Z
BeginBatchr   r   r   r   r   r   r   r   r   ÚProcessTableMessageÚUpdateValuesZEndBatchZAdjustScrollbarsZForceRefresh)r   ÚgridÚcurrentÚnewZdelmsgZaddmsgÚmsgr   r   r   Ú	ResetViewg   s0    üüù


zVirtualModel.ResetViewc                 C   s   t | tƒ}| |¡ dS )zUpdate all displayed valuesN)r   r	   r,   )r   r.   r1   r   r   r   r-   �   s    
zVirtualModel.UpdateValuesc                 C   s    t d||ƒ tƒ }| d¡ |S )NzOverridden GetAttr r    )r'   r   ZSetReadOnly)r   r   r   ZsomeExtraParameterÚattrr   r   r   Ú	GetAttr88•   s    
zVirtualModel.GetAttr88c                 C   sr   t | jƒD ]b\}}tƒ }|| jv r.| j| }n
| jd }| |¡ || jv r`| j| }| |¡ | ||¡ q
dS )zw
        wxGrid -> update the column attributes to add the
        appropriate renderer given the column name.
        ZDEFAULT_RENDERERN)Ú	enumerater   r   Z	renderersZSetRendererZeditorsZ	SetEditorZ
SetColAttr)r   r.   r   Zcolnamer3   ZrendererZeditorr   r   r   Ú_updateColAttrs88    s    





zVirtualModel._updateColAttrs88c                 C   s"   |\}}t d|ƒ | j |¡ dS )z/ Append a tupe containing (name, data)
        z
Appending N)r'   r   Úappend©r   r   Únamer   r   r   r   Ú	AppendRowÆ   s    
zVirtualModel.AppendRowc                 C   sN   d}|dd… }|  ¡  |D ]}| j || ¡ |d7 }qt| jƒsJg | _dS )zb
        cols -> delete the columns from the dataset
        cols hold the column indices
        r   Nr    )Úsortr   Úpopr   r   )r   ÚcolsÚdeleteCountÚir   r   r   ÚDeleteCols88Ñ   s    

zVirtualModel.DeleteCols88c                 C   s"   |\}}t d|ƒ | j |¡ d S )Nz	Deleting )r'   r   Úremover8   r   r   r   Ú	DeleteRowä   s    
zVirtualModel.DeleteRowc                 C   s>   d}|dd… }|  ¡  |D ]}| j || ¡ |d7 }qdS )z\
        rows -> delete the rows from the dataset
        rows hold the row indices
        r   Nr    )r;   r   r<   )r   Úrowsr>   r?   r   r   r   ÚDeleteRows88é   s    zVirtualModel.DeleteRows88c                 C   sd   | j | }g }| jD ]"}|\}}| | |d¡|f¡ q| ¡  g | _|D ]\}}| j |¡ qJdS )z£
        to do - never tested
        tried to rename data to _data and _data to _tmp_data
        col -> sort the data based on the column indexed by col
        N)r   r   r7   r#   r;   )r   r   r9   Z	_tmp_datar   ZrownameÚentryZ	sortvaluer   r   r   ÚSortColumn88÷   s    

zVirtualModel.SortColumn88N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r%   r&   r)   r*   r   r2   r-   r4   r6   r:   r@   rB   rD   rF   r   r   r   r   r
      s(   (&r
   N)
Zwx.gridr   r   r   r   r   r   r   r	   r
   r   r   r   r   Ú<module>   s   