a
    Df                     @  s   d dl mZ d dlmZmZmZmZmZmZ d dl	Z	ddl
mZ ddlmZ ddlmZ dd	lmZ erd d
lmZ d dlmZ d dlmZ ddlmZ G dd deZdS )    )annotations)TYPE_CHECKINGClassVarListMappingOptionalTypeN   )Feed)ScrollButtonClick)edit_readonly   )Column)Document)Model)Comm)Viewablec                      s   e Zd ZU dZejddddZejdg ddd	Zej	d
ddZ
eZded< dZddddZded<  fddZejddd
ddd Zedd Zd3dd d d!d"d# fd$d%Z fd&d'Z fd(d)Zd4d"d*dd"d!d+d,d-Zd.d/d0d1d2Z  ZS )5r
   a  
    The `Feed` class inherits from the `Column` layout, thereby enabling the arrangement of
    multiple panel objects within a vertical container. However, it restrictively manages the number
    of objects displayed at any moment. This layout is particularly useful for efficiently
    rendering a substantial number of objects.

    Similar to `Column`, the `Feed` provides a list-like API, including methods such as `append`,
    `extend`, `clear`, `insert`, `pop`, `remove`, and `__setitem__`. These methods facilitate
    interactive updates and modifications to the layout.

    Reference: https://panel.holoviz.org/reference/layouts/Feed.html

    :Example:

    >>> pn.Feed(some_widget, some_pane, some_python_object, ..., python_object_1002)
    2   )r   Nz
        The number of objects loaded on each side of the visible objects.
        When scrolled halfway into the buffer, the feed will automatically
        load additional objects while unloading objects on the opposite side.)defaultZboundsdocy)FTz	both-autozy-autozx-autoZbothxr   aY  Whether to add scrollbars if the content overflows the size
        of the container. If "both-auto", will only add scrollbars if
        the content overflows in either directions. If "x-auto" or "y-auto",
        will only add scrollbars if the content overflows in the
        respective direction. If "both", will always add scrollbars.
        If "x" or "y", will always add scrollbars in the respective
        direction. If False, overflowing content will be clipped.
        If True, will only add scrollbars in the direction of the container,
        (e.g. Column: vertical, Row: horizontal).)r   objectsr   Tz
        Read-only upper and lower bounds of the currently visible feed objects.
        This list is automatically updated based on scrolling.)readonlyr   zClassVar[Type[Model]]_bokeh_modelZverticalchildrenvisible_childrenN)r   visible_rangeload_bufferz"ClassVar[Mapping[str, str | None]]_renamec                   s:   dD ]}||v r qqd|d< t  j|i | d | _d S )N)heightZ
min_heightZ
max_heighti,  r    )super__init___last_synced)selfr   paramsZheight_param	__class__ ^/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/layout/feed.pyr"   G   s    zFeed.__init__r   r   )Zwatchc           	      C  s   | j d u rd S | j \}}| j\}}| jd }|| |k }|| |k }|| | jk ob|| t| jk }|sp|sp|r|| jd d S )Nr	   r   )r   r#   r   lenr   paramtrigger)	r$   vsvessseZhalf_bufferZtop_triggerZbottom_triggerZinvalid_triggerr(   r(   r)   _trigger_get_objectsR   s    



zFeed._trigger_get_objectsc                 C  sn   t | j}| jr<t| jd | j dt| jd | j |fS | jrZt|| jd  d|fS dt| j|fS d S )Nr   r	   )r*   r   r   maxr   minZview_latest)r$   nr(   r(   r)   _synced_rangef   s    
zFeed._synced_ranger   zOptional[Model]zOptional[Comm]r   )r   rootparentcommreturnc                   s(   t  ||||}| jd|||d |S )NZscroll_button_click)modelr   r9   )r!   
_get_modelZ_register_events)r$   r   r7   r8   r9   r;   r&   r(   r)   r<   s   s    zFeed._get_modelc           	        s   d|v r| d}| j D ]B\}}dd |jD  |r|d  v rt fdd|D } qlqt |S | jd }t| j	}t
||d  dt||d  |g}|d |d kr|d | j |d< t||d	< t |S )
Nr   c                 S  s   g | ]}|j d  qS )id)ref).0cr(   r(   r)   
<listcomp>       z1Feed._process_property_change.<locals>.<listcomp>r   c                 3  s    | ]}| v r  |V  qd S )N)index)r?   vrefsr(   r)   	<genexpr>   rB   z0Feed._process_property_change.<locals>.<genexpr>r2   r   r   )pop_modelsvaluesr   sortedr!   _process_property_changer6   r*   r   r3   r4   r   tuple)	r$   msgZvisibler;   _Zindexesoffsetr5   r   r&   rE   r)   rL   {   s"    


zFeed._process_property_changec                   s   | dd  t |S )Nr   )rH   r!   _process_param_change)r$   rN   r&   r(   r)   rQ      s    zFeed._process_param_changezList[Viewable])r;   old_objectsr   r7   r9   c                 C  sB  ddl m}m} g g  }}	| j| _t| jD ]\}
}||| j|
< q,|D ]}|| jvrH|| qHt| j}|j	d }t
| j D ]}
||
 }||jv r|j|j	d  \}}|	| nxz|||||}W nb |y, } zH|jd ur|j| ur|d |_| ||d |
 |||W  Y d }~  S d }~0 0 || q||	fS )Nr	   )RerenderErrorpanelr=   )Z	pane.baserS   rT   r6   r#   	enumerater   _cleanuplistr>   rangerI   appendr<   Zlayout_get_objects)r$   r;   rR   r   r7   r9   rS   rT   Z
new_modelsZ
old_modelsiZpaneobjZcurrent_objectsr>   childrO   er(   r(   r)   rZ      s0    




4zFeed._get_objectsr   None)eventr:   c                 C  s   | j s
dS | j}t|  d| _W d   n1 s60    Y  t| j}| j d | j d  }t| ( t|| d d|f| _ W d   n1 s0    Y  t|  || _W d   n1 s0    Y  dS )z6
        Process a scroll button click event.
        Nr   r2   r   )r   r   r+   Zdiscard_eventsr*   r   r   r3   )r$   r`   r   r5   Z	n_visibler(   r(   r)   _process_event   s    $

6zFeed._process_event)NNN)N)__name__
__module____qualname____doc__r+   ZIntegerr   ZSelectorZscrollRanger   PnFeedr   __annotations__Z
_directionr   r"   dependsr1   propertyr6   r<   rL   rQ   rZ   ra   __classcell__r(   r(   r&   r)   r
      s4   


   !r
   )
__future__r   typingr   r   r   r   r   r   r+   modelsr
   rg   Zmodels.feedr   utilr   baser   Zbokeh.documentr   Zbokeh.modelr   Zpyviz_commsr   Zviewabler   r(   r(   r(   r)   <module>   s    