a
    Df$!                     @  s   d Z ddl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 ddlZddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZm Z  erddl!m"Z" ddl#m$Z$ ddl%m&Z& ddlm'Z' edZ(G dd deZ)G dd de)Z*dd Z+ee+ dS )z
Defines the Widget base class which provides bi-directional
communication between the rendered dashboard and the Widget
parameters.
    )annotationsN)TYPE_CHECKINGAnyCallableClassVarDictListMappingOptionalTupleTypeTypeVar)ImportedStyleSheetTooltip)HTML)register_reference_transform   )Margin)Row)Reactive)
LayoutableViewable)Document)Model)Comm)	ListPanelTc                      s
  e Zd ZU dZejdddZejddZej	ddd	Z
ej	ddd	Zed
ddZddiZded< dZded< dZded< dZ fddZeddddddZedd fdd Zed!d" Zd#d#d$ fd%d&Zd6d'd(d(d)d*d+d,d-Zd7d/d0d1d2d3d4d5Z  ZS )8Widgetzn
    Widgets allow syncing changes in bokeh widget models with the
    parameters on the Widget instance.
    Fz'
       Whether the widget is disabled.)defaultdoc )r   N)r   N)r   Zbounds)   
   z
        Allows to create additional space around the component. May
        be specified as a two-tuple of the form (vertical, horizontal)
        or a four-tuple (top, right, bottom, left).nametitlez"ClassVar[Mapping[str, str | None]]_renamezClassVar[bool]_supports_embedzClassVar[Type[Model] | None]_widget_typeTc                   sV   d|vrd|d< d|v r$| d| _d|v r:| d| _nd | _t jf i | d S )Nr#   r    r&   _param_pane)popr&   r(   super__init__)selfparams	__class__ _/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/widgets/base.pyr+   B   s    zWidget.__init__zType[T]zparam.Parameterr   )cls	parameterreturnc                 K  s:   ddl m} |||jtf d| i|itj d}|d S )a5  
        Construct a widget from a Parameter and link the two
        bi-directionally.

        Parameters
        ----------
        parameter: param.Parameter
          A parameter to create the widget from.

        Returns
        -------
        Widget instance linked to the supplied parameter
        r   )Paramtype)ZwidgetsZdisplay_thresholdr   )paramr5   r#   dictmathinf)r2   r3   r-   r5   layoutr0   r0   r1   
from_paramM   s    zWidget.from_paramz
Tuple[str]r4   c                   s&   t t j}d|v r|d t|S )Ndescription)listr*   _linked_propertiesremovetuple)r,   propsr.   r0   r1   r@   c   s    
zWidget._linked_propertiesc                 C  s
   | j jjS N)r7   valuerxr,   r0   r0   r1   rF   j   s    z	Widget.rxzDict[str, Any])r-   r4   c                   s   t  |}| jd urFd|v rFt| jdg }dd |D |d  |d< d|v r|d }|di }t|trddlm} |j	di |}|
|}tt|ddgdd|d< nt|trd|_|S )NstylesheetsZ__css__c                 S  s   g | ]}t |d qS ))url)r   ).0ssr0   r0   r1   
<listcomp>r   s   z0Widget._process_param_change.<locals>.<listcomp>r>   renderer_optionsr   )Markdownmarkdown-itr0   rightz1:host { white-space: initial; max-width: 300px; }F)contentpositionrH   syncable)rO   r0   )r*   _process_param_changer'   getattrr)   
isinstancestrZpane.markuprN   Z_get_parserrenderr   r   rS   )r,   r-   cssr>   rM   rN   parserhtmlr.   r0   r1   rT   n   s.    


zWidget._process_param_changer   Optional[Model]Optional[Comm]r   r   rootparentcommr4   c                 C  sJ   | j f i | |}|p|}||f| j|jd < | || j||| |S Nid)r'   Z_get_properties_modelsrefZ_link_propsr@   r,   r   r_   r`   ra   modelr0   r0   r1   
_get_model   s
    zWidget._get_model   z'Model'zOptional[List[Any]]intzGTuple['Widget', 'Model', List[Any], Callable[['Model'], Any], str, str])r_   valuesmax_optsr4   c                 C  s   dS )a  
        Returns the bokeh model and a discrete set of value states
        for the widget.

        Arguments
        ---------
        root: bokeh.model.Model
          The root model of the widget
        values: list (optional)
          An explicit list of value states to embed
        max_opts: int
          The maximum number of states the widget should return

        Returns
        -------
        widget: panel.widget.Widget
          The Panel widget instance to modify to effect state changes
        model: bokeh.model.Model
          The bokeh model to record the current value state on
        values: list
          A list of value states to explore.
        getter: callable
          A function that returns the state value given the model
        on_change: string
          The name of the widget property to attach a callback on
        js_getter: string
          JS snippet that returns the state value given the model
        Nr0   )r,   r_   rk   rl   r0   r0   r1   _get_embed_state   s    zWidget._get_embed_state)NNN)Nri   )__name__
__module____qualname____doc__r7   BooleandisabledStringr#   ZIntegerheightwidthr   marginr%   __annotations__r&   r'   Z_Widget__abstractr+   classmethodr<   propertyr@   rF   rT   rh   rm   __classcell__r0   r0   r.   r1   r   $   s.   

   r   c                      s   e Zd ZU dZeZded< dZded< dZ fdd	Z	d
ddddZ
d)ddd fddZd*ddd fddZd+ddddddddZd d!d"d#d$Zed%d&d'd(Z  ZS ),CompositeWidgetzT
    A baseclass for widgets which are made up of two or more other
    widgets
    zClassVar[Type[ListPanel]]_composite_typer0   zClassVar[Tuple[str]]r@   Tc                   s   t  jf i | dd tjD } fdd|D }|d jd u rVd|vrVd|d< |ddvr|dr|d}|d	s||d	<  jf i | _ jj	 _	 j
 j j| d S )
Nc                 S  s   g | ]}|d kr|qS )r#   r0   rJ   pr0   r0   r1   rL          z,CompositeWidget.__init__.<locals>.<listcomp>c                   s&   i | ]}t  |d ur|t  |qS rD   )rU   r~   rG   r0   r1   
<dictcomp>   s   z,CompositeWidget.__init__.<locals>.<dictcomp>rv   Zsizing_modeZstretch_width)Nfixed	min_width)r*   r+   r   r7   getrv   r)   r}   
_compositerd   Z_internal_callbacksappendZwatch_update_layout_params)r,   r-   Zlayout_paramsr;   r   r.   rG   r1   r+      s    


zCompositeWidget.__init__zparam.parameterized.EventNone)eventsr4   c                 G  s&   dd |D }| j jjf i | d S )Nc                 S  s   i | ]}|j |jqS r0   )r#   new)rJ   eventr0   r0   r1   r      r   z9CompositeWidget._update_layout_params.<locals>.<dictcomp>)r   r7   update)r,   r   Zupdatesr0   r0   r1   r      s    z%CompositeWidget._update_layout_paramsNz-Optional[type | Callable[['Viewable'], bool]]zList[Viewable])selectorr4   c                   s,   t  |}| jjD ]}|||7 }q|S )a  
        Iterates over the Viewable and any potential children in the
        applying the Selector.

        Arguments
        ---------
        selector: type or callable or None
          The selector allows selecting a subset of Viewables by
          declaring a type or callable function to filter by.

        Returns
        -------
        viewables: list(Viewable)
        )r*   selectr   objects)r,   r   r   objr.   r0   r1   r      s    zCompositeWidget.selectzModel | None)r_   r4   c                   s   | j | t | d S rD   )r   _cleanupr*   )r,   r_   r.   r0   r1   r      s    zCompositeWidget._cleanupr   r\   r]   r   r^   c                 C  s2   | j ||||}|p|}||f| j|jd < |S rb   )r   rh   rd   re   rf   r0   r0   r1   rh      s    zCompositeWidget._get_modelr   bool)objectr4   c                 C  s   || j jv S rD   )r   r   )r,   r   r0   r0   r1   __contains__   s    zCompositeWidget.__contains__z	List[str]r=   c                 C  s   g S rD   r0   rG   r0   r0   r1   _synced_params   s    zCompositeWidget._synced_params)N)N)NNN)rn   ro   rp   rq   r   r}   rx   r@   Z_CompositeWidget__abstractr+   r   r   r   rh   r   rz   r   r{   r0   r0   r.   r1   r|      s   
   	r|   c                 C  s   t | tr| jjS | S rD   )rV   r   r7   rE   )r   r0   r0   r1   _widget_transform   s    r   ),rq   
__future__r   r9   typingr   r   r   r   r   r   r	   r
   r   r   r   r7   Zbokeh.modelsr   r   Zbokeh.models.domr   Zparam.parameterizedr   Z_paramr   Zlayout.baser   Zreactiver   Zviewabler   r   Zbokeh.documentr   Zbokeh.modelr   Zpyviz_commsr   r   r   r   r|   r   r0   r0   r0   r1   <module>   s,   4 L