a
    Df                     @  s@  d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZmZmZ ddlZddlZddl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"m#Z#m$Z$ ddl%m&Z'm(Z(m)Z*m+Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; er"ddl<m=Z= G dd de5Z>G dd de>Z?G dd de?Z@G dd de4ZAG dd de?ZBG dd de?ZCG dd  d eCZG d!d" d"eCZG d#d$ d$e5ZG d%d& d&e?ZDG d'd( d(eDe8e2Z)G d)d* d*eDZEG d+d, d,e?ZFG d-d. d.eFe8e2ZGG d/d0 d0eFZHG d1d2 d2e?ZIG d3d4 d4e4eZJdS )5z_
Defines various Select widgets which allow choosing one or more items
from a list of options.
    )annotationsN)FunctionType)TYPE_CHECKINGAnyClassVarDictListMappingType)PaletteSelect)AutocompleteInputCheckboxGroupMultiChoiceMultiSelect
RadioGroup   )CDN_DIST)Column	ListPanelNamedListPanel)CheckboxButtonGroupCustomSelectRadioButtonGroupSingleSelect)PARAM_NAME_PATTERNindexOfisIn   )TooltipMixin)CompositeWidgetWidget)Button_ButtonBase)TextAreaInput	TextInput)Modelc                   @  sF   e Zd Zejg eefdZdZe	dd Z
e	dd Ze	dd Zd	S )

SelectBase)defaultclass_Tc                 C  sH   g }| j D ]8}t|tjr4t|js4||j q
|t| q
|S N)	options
isinstanceparamZParameterizedr   matchnameappendstr)selflabelso r4   a/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/widgets/select.pyr2   /   s    
zSelectBase.labelsc                 C  s$   t | jtrt| j S | jS d S r)   )r+   r*   dictlistvaluesr1   r4   r4   r5   r8   9   s    zSelectBase.valuesc                 C  s   t t| j| jS r)   )r6   zipr2   r8   r9   r4   r4   r5   _items@   s    zSelectBase._itemsN)__name__
__module____qualname__r,   ClassSelectorr6   r7   r*   Z_SelectBase__abstractpropertyr2   r8   r;   r4   r4   r4   r5   r&   )   s   
	
r&   c                      sh   e Zd ZU ejddZdZded< dZ fddZ	 fdd	Z
ed
d Z fddZdddZ  ZS )SingleSelectBaseNr'   TClassVar[bool]_supports_embedc                   s<   t  jf i | | j}| jd u r8d |vr8|r8|d | _d S )Nr   )super__init__r8   value)r1   paramsr8   	__class__r4   r5   rF   M   s    zSingleSelectBase.__init__c                   s   t  |}| j| j }}tt| jt|k}d|v r|d }t||rl|rT| jn|}|t|| |d< n |r~| jd | _	nd | _	d|d< d|v rt
| jtr|rdd t|| jD }n|}||d< n
| j|d< | j	}|rt||s|d | _	nd | _	|S )NrG   r    r*   c                 S  s   g | ]\}}||fqS r4   r4   ).0lvr4   r4   r5   
<listcomp>e       z:SingleSelectBase._process_param_change.<locals>.<listcomp>)rE   _process_param_changer2   r8   lensetunicode_valuesr   r   rG   r+   r*   r6   r:   )r1   msgr2   r8   uniquevalrT   r*   rI   r4   r5   rQ   S   s2    



z&SingleSelectBase._process_param_changec                 C  s   dd | j D S )Nc                 S  s   g | ]}t |qS r4   r0   rL   rN   r4   r4   r5   rO   u   rP   z3SingleSelectBase.unicode_values.<locals>.<listcomp>r8   r9   r4   r4   r5   rT   s   s    zSingleSelectBase.unicode_valuesc                   s   t  |}d|v r| jsnl|d dkrB| jr8| jd nd |d< nFt|d | jrdt|d | j}nt|d | j}| j| j|  |d< |dd  |S )NrG   rK   r   r*   )	rE   _process_property_changer8   r   rT   r   r2   r;   pop)r1   rU   idxrI   r4   r5   r[   w   s    z)SingleSelectBase._process_property_change   c                   s\   |d u r j }n(t fdd|D r8tdt j   j|jd  d |dd dd	fS )
Nc                 3  s   | ]}| j vV  qd S r)   rZ   rY   r9   r4   r5   	<genexpr>   rP   z4SingleSelectBase._get_embed_state.<locals>.<genexpr>CSupplied embed states were not found in the %s widgets values list.idr   c                 S  s   | j S r)   )rG   xr4   r4   r5   <lambda>   rP   z3SingleSelectBase._get_embed_state.<locals>.<lambda>rG   zcb_obj.valuer8   any
ValueErrortyper<   Z_modelsrefr1   rootr8   Zmax_optsr4   r9   r5   _get_embed_state   s    
z!SingleSelectBase._get_embed_state)Nr^   )r<   r=   r>   r,   	ParameterrG   rD   __annotations__Z_SingleSelectBase__abstractrF   rQ   r@   rT   r[   rl   __classcell__r4   r4   rI   r5   rA   E   s   
 
rA   c                      s   e Zd ZU dZejdddZejg dddZej	ddddZ
ejd	d
ddZejddddZddiZded< dddZded< e dgZded< edd Z fddZdd Zdd Zd d d! fd"d#Ze fd$d%Ze fd&d'Z  ZS )(Selecta  
    The `Select` widget allows selecting a value from a list or dictionary of
    `options` by selecting it from a dropdown menu or selection area.

    It falls into the broad category of single-value, option-selection widgets
    that provide a compatible API and include the `RadioBoxGroup`,
    `AutocompleteInput` and `DiscreteSlider` widgets.

    Reference: https://panel.holoviz.org/reference/widgets/Select.html

    :Example:

    >>> Select(name='Study', options=['Biology', 'Chemistry', 'Physics'])
    NB
        An HTML string describing the function of this component.r'   docTz
        Optional list of ``options`` that are disabled, i.e. unusable and
        un-clickable. If ``options`` is a dictionary the list items must be
        dictionary values.)r'   Znested_refsrs   z
        Dictionary whose keys are used to visually group the options
        and whose values are either a list or a dictionary of options
        to select from. Mutually exclusive with ``options``  and valid only
        if ``size`` is 1.r   r   Nz
        Declares how many options are displayed at the same time.
        If set to 1 displays options as dropdown otherwise displays
        scrollable area.r'   Zboundsrs   ,  ~
      Width of this component. If sizing_mode is set to stretch
      or scale mode this will merely be used as a suggestion.r'   Z
allow_Noners   groups"ClassVar[Mapping[str, str | None]]_rename)sizery   _source_transformscss/select.cssClassVar[List[str]]_stylesheetsc                 C  s   | j dkrtS tS )Nr   )r|   r   _BkSingleSelectr9   r4   r4   r5   _widget_type   s    zSelect._widget_typec                   sj   t  jf i | | jdkr&d| jj_| j| j| jddg| j| j	g dg |   | 	  d S )Nr   Tr*   ry   )r*   disabled_optionsrG   )
rE   rF   r|   r,   ZconstantZ_internal_callbacksextendwatch_validate_options_groups_validate_disabled_optionsr1   rH   rI   r4   r5   rF      s    


zSelect.__init__c                   s   j r( j  jkr(tdt j d fdd j D }|rZtdt j d| t|dkr|d jd	kr j j v rtd
t j d jdn8|d jdkr؈ j j v rtdt j d jd j j v rtdt j d jdd S )NzAll the options of a z widget cannot be disabled.c                   s   g | ]}| j pg vr|qS r4   rZ   )rL   Zdoptsr9   r4   r5   rO      s   z5Select._validate_disabled_options.<locals>.<listcomp>z'Cannot disable non existing options of z: r   r   rG   zCannot set the value of z to z as it is a disabled option.r   zCannot set disabled_options of z+ to a list that includes the current value .zCannot initialize z with value z& as it is one of the disabled options.)r   r8   rg   rh   r<   rR   r.   rG   )r1   eventsZnot_in_optsr4   r9   r5   r      s8    
z!Select._validate_disabled_optionsc                 G  sH   | j r | jr tt| j d| jdkrD| jrDtt| j dd S )Nz6 options and groups parameters are mutually exclusive.r   zM with size > 1 doe not support the `groups` parameter, use `options` instead.)r*   ry   rg   rh   r<   r|   )r1   r   r4   r4   r5   r      s    zSelect._validate_options_groupszDict[str, Any])rU   returnc           	        s(  d|v }t  |}|s*d|v r$ jr$ j}tdd | D du rltdd | D du rltd j j }}tt j	t|k}|rt
tt j tr|rdd	 | D }n fd
d	| D }||d< ndd	 | D |d<  j}|rt||s$|d  _nd  _|S )Nry   r*   c                 s  s   | ]}t |tV  qd S r)   )r+   r6   rL   r8   r4   r4   r5   r_   	  rP   z/Select._process_param_change.<locals>.<genexpr>Fc                 s  s   | ]}t |tV  qd S r)   )r+   r7   r   r4   r4   r5   r_   
  rP   zSThe values of the groups dictionary must be all of the dictionary or the list type.c                 S  s$   i | ]\}}|d d |  D qS )c                 S  s   g | ]\}}t ||fqS r4   rX   )rL   labelrG   r4   r4   r5   rO     rP   ;Select._process_param_change.<locals>.<dictcomp>.<listcomp>)items)rL   groupsubdr4   r4   r5   
<dictcomp>  s   z0Select._process_param_change.<locals>.<dictcomp>c                   s"   i | ]}|d d  j | D qS )c                 S  s   g | ]}t |qS r4   rX   rY   r4   r4   r5   rO     rP   r   )ry   )rL   r   r9   r4   r5   r     s   c                 S  s    i | ]\}}|d d |D qS )c                 S  s   g | ]}t |t |fqS r4   rX   )rL   rG   r4   r4   r5   rO      rP   r   r4   )rL   r   r8   r4   r4   r5   r     s   r   )rE   rQ   ry   allr8   rg   r2   rR   rS   rT   r+   nextiterr6   r   keysrG   r   )	r1   rU   Zgroups_providedry   r2   r8   rV   r*   rW   rI   r9   r5   rQ     s>    


zSelect._process_param_changec                   s6   | j rt jS | jsi S ttttj| j	  S d S r)   )
r*   rE   r2   ry   r7   mapr0   	itertoolschainr8   r9   rI   r4   r5   r2   +  s
    zSelect.labelsc                   s\   | j rt jS | jsg S ttt| j trDdd | j D S tt	j
| j  S d S )Nc                 S  s   g | ]}|  D ]}|qqS r4   rZ   )rL   r   rN   r4   r4   r5   rO   =  rP   z!Select.values.<locals>.<listcomp>)r*   rE   r8   ry   r+   r   r   r6   r7   r   r   r9   rI   r4   r5   r8   5  s    zSelect.values)r<   r=   r>   __doc__r,   Stringdescriptionr   r   r   ry   Integerr|   widthr{   rn   r}   r   r   r@   r   rF   r   r   rQ   r2   r8   ro   r4   r4   rI   r5   rp      s*   

 '	rp   c                      s  e Zd ZdZejddZejee	fddZ
ejeddZejddZejd	d
dZejddZejddZejddZ fddZd.ddZdd Zd/ddZddddZejddddd d!d" Zd#d$ Zd0d%d&Zd'd( Zd)d* Z ejd+dd d,d- Z!  Z"S )1NestedSelecta  
    The `NestedSelect` widget is composed of multiple widgets, where subsequent select options
    depend on the parent's value.

    Reference: https://panel.holoviz.org/reference/widgets/NestedSelect.html

    :Example:

    >>> NestedSelect(
    ...     options={
    ...         "gfs": {"tmp": [1000, 500], "pcp": [1000]},
    ...         "name": {"tmp": [1000, 925, 850, 700, 500], "pcp": [1000]},
    ...     },
    ...     levels=["model", "var", "level"],
    ... )
    z
        The value from all the Select widgets; the keys are the levels names.
        If no levels names are specified, the keys are the levels indices.)rs   a~  
        The options to select from. The options may be nested dictionaries, lists,
        or callables that return those types. If callables are used, the callables
        must accept `level` and `value` keyword arguments, where `level` is the
        level that updated and `value` is a dictionary of the current values, containing keys
        up to the level that was updated.)r(   rs   z
        The layout type of the widgets. If a dictionary, a "type" key can be provided,
        to specify the layout type of the widgets, and any additional keyword arguments
        will be used to instantiate the layout.rr   a  
        Either a list of strings or a list of dictionaries. If a list of strings, the strings
        are used as the names of the levels. If a list of dictionaries, each dictionary may
        have a "name" key, which is used as the name of the level, a "type" key, which
        is used as the type of widget, and any corresponding widget keyword arguments.
        Must be specified if options is callable.Fz(
        Whether the widget is disabled.zThe nested select widgets.z2The number of levels of the nested select widgets.zP
        The internal rep of levels to prevent overwriting user provided levels.c                   s   t  jf i | |   d S r)   )rE   rF   _update_widgetsr   rI   r4   r5   rF   u  s    zNestedSelect.__init__Nc                 C  sj   i }t | jD ]V\}}|dur*||kr* qf| j| }t|trL|d|}n|}|jr\|jnd||< q|S )zW
        Gather values from all the select widgets to update the class' value.
        Nr.   )	enumerate_widgets_levelsr+   r6   getr*   rG   )r1   up_to_ir8   iselectlevelr.   r4   r4   r5   _gather_values_from_widgetsy  s    

z(NestedSelect._gather_values_from_widgetsc                 C  sN   t |rdS t|trJ| D ]*}t |r0 dS t|tr| |  S qdS )z=
        Check if the nested options has a callable.
        TF)callabler+   r6   r8   _uses_callable)r1   drG   r4   r4   r5   r     s    

zNestedSelect._uses_callabler   c                 C  s   |d u st |dkrdS t|ts&|S |}| D ]J}t|trVt|| ||d }t|tr2t |dkr2|dkr2|d8 }q2|S )Nr   r   )rR   r+   r6   r8   max_find_max_depthr7   )r1   r   depthZ	max_depthrG   r4   r4   r5   r     s    


zNestedSelect._find_max_depthzdict | list)r   c                 C  s&   | j | }| j|d}|||d}|S )N)r   )r   rG   )levelsr   )r1   r   r*   r   rG   r4   r4   r5   _resolve_callable_options  s    
z&NestedSelect._resolve_callable_optionsr*   layoutr   Tr   c              	   C  s  |  | jr(| jstdt| j| _n| | jd | _| jsXdd t| jD | _n*t| j| jkrztd| j n| j| _g | _	| jpg }t
| jtr| j }t| jD ]}t|r| ||}| ||}t
|trt|dkr|dur|| }q|| jd k rt
|tstd| j| d	|d
t|j qt
| jtrf| jdt}| j }n0t| jttfr| j}i }ntd| jd|| j	i || _| jdur|  | _dS )zQ
        When options is changed, reflect changes on the select widgets.
        z/levels must be specified if options is callabler   c                 S  s   g | ]}|qS r4   r4   )rL   r   r4   r4   r5   rO     rP   z0NestedSelect._update_widgets.<locals>.<listcomp>zlevels must be of length r   NzThe level, z= is not the last nested level, so it must be a dict, but got , which is a rh   z7The layout must be a subclass of ListLike or dict, got r   )r   r*   r   rg   rR   
_max_depthr   ranger   r   r+   r6   copyr   r   _init_widgetrh   r<   r   r\   r   
issubclassr   r   
_compositer   rG   )r1   r*   r   rG   Zlayout_typeZlayout_kwargsr4   r4   r5   r     sP    


zNestedSelect._update_widgetsc                 C  sX   | j | }t|trti fS t|tr2td|ifS |dt}dd | D }||fS )zX
        Extract the widget type and keyword arguments from the level metadata.
        r.   rh   c                 S  s   i | ]\}}|d kr||qS )rh   r4   )rL   krN   r4   r4   r5   r     rP   z8NestedSelect._extract_level_metadata.<locals>.<dictcomp>)r   r+   intrp   r0   r   r   )r1   r   r   widget_typewidget_kwargsr4   r4   r5   _extract_level_metadata  s    


z$NestedSelect._extract_level_metadatac                 C  s   t |ttf}|du s&|r,t|dkr,d}nP|du rV|t|k rPt| | nd}n&t | jd trr||}n
||}|r|r||vr|dur|rtd|d|d|dn|d }|S )zO
        Look up the value of the select widget at index i or by name.
        Nr   zFailed to set value z for level z, must be one of r   )	r+   r7   r6   rR   r8   r   r   r   rg   )r1   r   r*   r8   r.   errorZoptions_iterablerG   r4   r4   r5   _lookup_value  s"    "
zNestedSelect._lookup_valuec                 C  s   t |trt| }n0t |ttfsHt|sHtd|dt|j | |\}}| j	||| j
dd}||d< ||d< d|vr|dkpt|pt|dk|d< |f i |}| j|d	d
 |j| jd | j| |S )z>
        Helper method to initialize a select widget.
        zHoptions must be a dict, list, or callable that returns those types, got r   F)r   r*   rG   visibler   disabled)r   )r+   r6   r7   r   r   rg   rh   r<   r   r   rG   rR   linkr,   r   $_update_widget_options_interactivelyr   r/   )r1   r   r*   r   r   rG   Zwidgetr4   r4   r5   r     s*    
 zNestedSelect._init_widgetc           	      C  sx  | j du rdS t| jD ]\}}||ju r q0qt| j r@| j n| j  }tj| 
 t| jdd D ]\}}|j	du ri }d}n@|rt
|tr|j	|v r||j	 }n|t| d  }t|}||k rql| j|d  }t|r| |d |}t|}n4t
|trt| }nt
|tr0|}ntd|jj||d ql|  | _	W d   n1 sj0    Y  dS )zX
        When a select widget's value is changed, update to the latest options.
        NFr   r   zCoptions must be a dict, list, or callable that returns those types.)r*   r   )r*   r   r   objr   r   r,   parameterizedbatch_call_watchersrG   r+   r6   r7   r   boolr   NotImplementedErrorupdater   )	r1   eventZstart_ir   r*   r   r   Znext_selectZnext_optionsr4   r4   r5   r   '  sF    






z1NestedSelect._update_widget_options_interactivelyrG   c              
   C  sz  | j du rdS t| j r| j n| j  }| j }|  }||krFdS tj|  zt| j	D ]}| j
| }t|r| ||}t|}nt|trt| }n|}| j||||jdd}t| 2 |jj||t|pt|dkd W d   n1 s0    Y  |du r q6|| j	d k rb|| }qbW n tyT   || _ Y n0 W d   n1 sl0    Y  dS )zE
        When value is passed, update to the latest options.
        NT)r.   r   r   )r*   rG   r   r   )r*   r   r   rG   r   r,   r   r   r   r   r   r   r7   r+   r6   r   r   r.   Zdiscard_eventsr   rR   	Exception)r1   r*   Z
set_valuesZoriginal_valuesr   Zcurr_selectZcurr_optionsZ
curr_valuer4   r4   r5    _update_options_programmatically_  sD    




&
z-NestedSelect._update_options_programmatically)N)r   )NF)#r<   r=   r>   r   r,   r   rG   r?   r6   r   r*   rm   r   r   r   r   Booleanr   r   r   r   r   rF   r   r   r   r   dependsr   r   r   r   r   r   ro   r4   r4   rI   r5   r   B  s,   


6
8r   c                   @  s   e Zd ZU dZeji ddZejdddZejdddZ	ejdd	dZ
ejd
ddZejd
ddZdd
dZeZded< ejdddddd Zejdddddd Zdd Zd
S )ColorMapao  
    The `ColorMap` widget allows selecting a value from a dictionary of
    `options` each containing a colormap specified as a list of colors
    or a matplotlib colormap.

    Reference: https://panel.holoviz.org/reference/widgets/ColorMap.html

    :Example:

    >>> ColorMap(name='Reds', options={'Reds': ['white', 'red'], 'Blues': ['#ffffff', '#0000ff']})
    z 
        Dictionary of colormapsrr   r   z2
        Number of columns of swatches to display.   z&
        Height of the color swatches.d   z%
        Width of the color swatches.NzThe selected colormap.zName of the selected colormap.r   )r*   
value_nameClassVar[Type[Model]]r   r   T)r   Zon_initc                 C  s$   | j r | j | jv r | j| j  | _d S r)   )r   r*   rG   r9   r4   r4   r5   _sync_value_name  s    zColorMap._sync_value_namerG   c                 C  s$   | j r t| j | j}| j| | _d S r)   )rG   r   r8   r2   r   )r1   r]   r4   r4   r5   _sync_value  s    zColorMap._sync_valuec                   s   d|v r~g }| d D ]Z\}}dt|ddv rft|dd}tdd|}d	  fd
d||D }|||f q||d< d|v rt|d ttd fst	|d j
}j| |d< fdd| D S )Nr*   Z
matplotlibr=   rK   N
   r   r   zrgba({0}, {1}, {2}, {3:.3g})c                   s6   g | ].} j g |d d d t|d R  qS )Nr^      r   )formatZastyper   )rL   Zrgba)	rgba_tmplr4   r5   rO     s   z2ColorMap._process_param_change.<locals>.<listcomp>rG   c                   s2   i | ]*\}} j |d dur j |||qS )FN)Z_property_mappingr   )rL   prN   r9   r4   r5   r     s   z2ColorMap._process_param_change.<locals>.<dictcomp>)r\   r   getattrnpZlinspacer/   r+   r0   rh   r   r8   r2   )r1   rH   r*   r.   Zcmapr   Zsamplesr]   r4   )r   r1   r5   rQ     s$    

zColorMap._process_param_change)r<   r=   r>   r   r,   r   r*   r   ZncolsZswatch_heightZswatch_widthrm   rG   r   r   r{   r   r   rn   r   r   r   rQ   r4   r4   r4   r5   r     s   



r   c                      sd   e Zd ZU ejg dZejddddZejdddZ	d	Z
d
ed< dZ fddZ fddZ  ZS )_MultiSelectBaserB   rv   Trw   rx   Nrq   rr   FrC   rD   c                   s   t t| |}| j| j  d|v rB fdd|d D |d< d|v r |d< tfdd| jD rfdd| jD | _|S )NrG   c                   s$   g | ]}t |r t| qS r4   r   r   rY   r2   r8   r4   r5   rO     s   
z:_MultiSelectBase._process_param_change.<locals>.<listcomp>r*   c                 3  s   | ]}t |  V  qd S r)   r   rY   rZ   r4   r5   r_     rP   z9_MultiSelectBase._process_param_change.<locals>.<genexpr>c                   s   g | ]}t | r|qS r4   r   rY   rZ   r4   r5   rO     rP   )rE   rA   rQ   r2   r8   rf   rG   r1   rU   rI   r   r5   rQ     s    z&_MultiSelectBase._process_param_changec                   sJ   t t|}d|v r:j  fdd|d D |d< |dd  |S )NrG   c                   s   g | ]}| v rj | qS r4   r;   rY   r2   r1   r4   r5   rO     s   z=_MultiSelectBase._process_property_change.<locals>.<listcomp>r*   )rE   rA   r[   r2   r\   r   rI   r   r5   r[     s    z)_MultiSelectBase._process_property_change)r<   r=   r>   r,   r   rG   r   r   r   r   rD   rn   Z_MultiSelectBase__abstractrQ   r[   ro   r4   r4   rI   r5   r     s   
r   c                   @  s@   e Zd ZU dZejdddZe dgZde	d< e
Zde	d	< d
S )r   a(  
    The `MultiSelect` widget allows selecting multiple values from a list of
    `options`.

    It falls into the broad category of multi-value, option-selection widgets
    that provide a compatible API and include the`CrossSelector`,
    `CheckBoxGroup` and `CheckButtonGroup` widgets.

    Reference: https://panel.holoviz.org/reference/widgets/MultiSelect.html

    :Example:

    >>> MultiSelect(
    ...     name='Frameworks', value=['Bokeh', 'Panel'],
    ...     options=['Bokeh', 'Dash', 'Panel', 'Streamlit', 'Voila'], size=8
    ... )
       z[
        The number of items displayed at once (i.e. determines the
        widget height).rr   r~   r   r   r   r   N)r<   r=   r>   r   r,   r   r|   r   r   rn   _BkMultiSelectr   r4   r4   r4   r5   r     s   
r   c                   @  s   e Zd ZU dZejdddZejddddZejddd	dZ	ejddd
dZ
ejdddZejdddZejddddZeZded< dS )r   a  
    The `MultiChoice` widget allows selecting multiple values from a list of
    `options`.

    It falls into the broad category of multi-value, option-selection widgets
    that provide a compatible API and include the `MultiSelect`,
    `CrossSelector`, `CheckBoxGroup` and `CheckButtonGroup` widgets.

    The `MultiChoice` widget provides a much more compact UI than
    `MultiSelect`.

    Reference: https://panel.holoviz.org/reference/widgets/MultiChoice.html

    :Example:

    >>> MultiChoice(
    ...     name='Favourites', value=['Panel', 'hvPlot'],
    ...     options=['Panel', 'hvPlot', 'HoloViews', 'GeoViews', 'Datashader', 'Param', 'Colorcet'],
    ...     max_items=2
    ... )
    TzA
        Whether to display a button to delete a selected option.rr   Nrt   z8
        Maximum number of options that can be selected.ru   z6
        Maximum number of options to display at once.zR
        Maximum number of options to display at once if search string is entered.rK   z:
        String displayed when no selection has been made.z=
        Whether to display widget with solid or light style.rv   rw   rx   r   r   )r<   r=   r>   r   r,   r   Zdelete_buttonr   Z	max_itemsZoption_limitZsearch_option_limitr   placeholderZsolidr   _BkMultiChoicer   rn   r4   r4   r4   r5   r     s   
r   c                      s   e Zd ZU dZejdddZejdddZej	g ddZ
ejdd	dZejdd
dZejdddgddZejddddZejddddZejddddZejdddZdddZded< eZded<  fddZ  ZS )r   a  
    The `MultiChoice` widget allows selecting multiple values from a list of
    `options`.

    It falls into the broad category of multi-value, option-selection widgets
    that provide a compatible API and include the `MultiSelect`,
    `CrossSelector`, `CheckBoxGroup` and `CheckButtonGroup` widgets.

    The `MultiChoice` widget provides a much more compact UI than
    `MultiSelect`.

    Reference: https://panel.holoviz.org/reference/widgets/AutocompleteInput.html

    :Example:

    >>> AutocompleteInput(
    ...     name='Study', options=['Biology', 'Chemistry', 'Physics'],
    ...     placeholder='Write your study here ...'
    ... )
    Tz,
        Enable or disable case sensitivity.rr   r   z\
        The number of characters a user must type before
        completions are presented.z
        A list of completion strings. This will be used to guide the
        user upon typing the beginning of a desired value.rK   z+
        Placeholder for empty input field.zz
        Set to False in order to allow users to enter text that is not
        present in the list of completion strings.Zstarts_withZincludesa  
        Define how to search the list of completion strings. The default option
        `"starts_with"` means that the user's text must match the start of a
        completion string. Using `"includes"` means that the user's text can
        match any substring of a completion string.r'   Zobjectsrs   zI
      Initial or entered text value updated when <enter> key is pressed.rx   z@
      Initial or entered text value updated on every key press.rv   rw   Nrq   titlecompletions)r.   r*   rz   r{   r   r   c                   s<   t  |}d|v r8| jr8t| j|d s8d |d< | _|S )Nr   rK   rG   )rE   rQ   restrictr   rG   r   rI   r4   r5   rQ     s
    z'AutocompleteInput._process_param_change)r<   r=   r>   r   r,   r   Zcase_sensitiver   Zmin_charactersr   r*   r   r   r   SelectorZsearch_strategyrG   value_inputr   r   r{   rn   _BkAutocompleteInputr   rQ   ro   r4   r4   rI   r5   r   E  s    
r   c                      s`   e Zd ZU dZddddZded< dd	iZdd
iZdZ fddZ	 fddZ
dddZ  ZS )_RadioGroupBaseFNr2   activer.   r*   rG   rz   r{   rG   source.labels[value]ztarget.labels.indexOf(value)Tc                   s   t t| |}| j}d|v rV|d }||v r>t|||d< n| jd urNd | _d |d< d|v r~| j|d< | j}t||s~d | _|S )Nr   r2   )rE   rA   rQ   r8   r   rG   r2   r   )r1   rU   r8   rG   rI   r4   r5   rQ     s    


z%_RadioGroupBase._process_param_changec                   sH   t t| |}d|v rD|d }|d u r2d |d< nt| j| |d< |S )NrG   )rE   rA   r[   r7   r8   )r1   rU   indexrI   r4   r5   r[     s    
z(_RadioGroupBase._process_property_changer^   c                   s\   |d u r j }n(t fdd|D r8tdt j   j|jd  d |dd dd	fS )
Nc                 3  s   | ]}| j vV  qd S r)   rZ   rY   r9   r4   r5   r_     rP   z3_RadioGroupBase._get_embed_state.<locals>.<genexpr>r`   ra   r   c                 S  s   | j S r)   )r   rb   r4   r4   r5   rd     rP   z2_RadioGroupBase._get_embed_state.<locals>.<lambda>r   zcb_obj.activere   rj   r4   r9   r5   rl     s    
z _RadioGroupBase._get_embed_state)Nr^   )r<   r=   r>   rD   r{   rn   r}   _target_transformsZ_RadioGroupBase__abstractrQ   r[   rl   ro   r4   r4   rI   r5   r     s   

r   c                   @  sb   e Zd ZU dZejdddgddZi eje	jZde
d< dd	d	d
ZdZde
d< eZde
d< d	S )r   a6  
    The `RadioButtonGroup` widget allows selecting from a list or dictionary
    of values using a set of toggle buttons.

    It falls into the broad category of single-value, option-selection widgets
    that provide a compatible API and include the `RadioBoxGroup`, `Select`,
    and `DiscreteSlider` widgets.

    Reference: https://panel.holoviz.org/reference/widgets/RadioButtonGroup.html

    :Example:

    >>> RadioButtonGroup(
    ...     name='Plotting library', options=['Matplotlib', 'Bokeh', 'Plotly'],
    ...     button_type='success'
    ... )
    
horizontalverticalO
        Button group orientation, either 'horizontal' (default) or 'vertical'.r   rz   r{   r   NrG   Zbutton_styler   TrC   rD   r   r   )r<   r=   r>   r   r,   r   orientationr   r{   r   rn   r}   rD   _BkRadioButtonGroupr   r4   r4   r4   r5   r     s   
r   c                   @  s8   e Zd ZU dZejdddZdZded< e	Z
ded	< d
S )RadioBoxGroupa  
    The `RadioBoxGroup` widget allows selecting from a list or dictionary of
    values using a set of checkboxes.

    It falls into the broad category of single-value, option-selection widgets
    that provide a compatible API and include the `RadioButtonGroup`, `Select`
    and `DiscreteSlider` widgets.

    Reference: https://panel.holoviz.org/reference/widgets/RadioBoxGroup.html

    :Example:

    >>> RadioBoxGroup(
    ...     name='Sponsor', options=['Anaconda', 'Blackstone'], inline=True
    ... )
    Fh
        Whether the items be arrange vertically (``False``) or
        horizontally in-line (``True``).rr   TrC   rD   r   r   N)r<   r=   r>   r   r,   r   inlinerD   rn   _BkRadioBoxGroupr   r4   r4   r4   r5   r     s   
r   c                      sb   e Zd ZU ejg dZddddZded< dd	iZdd
iZ	dZ
dZ fddZ fddZ  ZS )_CheckGroupBaserB   Nr2   r   r   rz   r{   rG   *value.map((index) => source.labels[index])z2value.map((label) => target.labels.indexOf(label))FTc                   s   t  |}| j d|v r4 fdd|d D |d< d|v r| j|d< t fdd| jD rt fdd| jD | _ fdd| jD |d< |d	d  |S )
Nr   c                   s    g | ]}t | rt| qS r4   r   rY   rZ   r4   r5   rO     s   
z9_CheckGroupBase._process_param_change.<locals>.<listcomp>r2   c                 3  s   | ]}t |  V  qd S r)   r   rY   rZ   r4   r5   r_     rP   z8_CheckGroupBase._process_param_change.<locals>.<genexpr>c                   s   g | ]}t | r|qS r4   r   rY   rZ   r4   r5   rO     rP   c                   s    g | ]}t | rt| qS r4   r   rY   rZ   r4   r5   rO     s   
r   )rE   rQ   r8   r2   rf   rG   r\   r   rI   rZ   r5   rQ     s    
z%_CheckGroupBase._process_param_changec                   s<   t t| |}d|v r8| j  fdd|d D |d< |S )NrG   c                   s   g | ]} | qS r4   r4   )rL   arZ   r4   r5   rO   $  rP   z<_CheckGroupBase._process_property_change.<locals>.<listcomp>)rE   rA   r[   r8   r   rI   rZ   r5   r[      s
    z(_CheckGroupBase._process_property_change)r<   r=   r>   r,   r   rG   r{   rn   r}   r   rD   Z_CheckGroupBase__abstractrQ   r[   ro   r4   r4   rI   r5   r    s   
r  c                   @  sV   e Zd ZU dZejdddgddZi eje	jZde
d< dd	d	d
ZeZde
d< d	S )CheckButtonGroupa<  
    The `CheckButtonGroup` widget allows selecting between a list of options
    by toggling the corresponding buttons.

    It falls into the broad category of multi-option selection widgets that
    provide a compatible API and include the `MultiSelect`, `CrossSelector`
    and `CheckBoxGroup` widgets.

    Reference: https://panel.holoviz.org/reference/widgets/CheckButtonGroup.html

    :Example:

    >>> CheckButtonGroup(
    ...     name='Regression Models', value=['Lasso', 'Ridge'],
    ...     options=['Lasso', 'Linear', 'Ridge', 'Polynomial']
    ... )
    r   r   r   r   rz   r{   r  Nr   r   r   )r<   r=   r>   r   r,   r   r   r  r{   r   rn   r}   _BkCheckboxButtonGroupr   r4   r4   r4   r5   r  )  s   
r  c                   @  s,   e Zd ZU dZejdddZeZde	d< dS )CheckBoxGroupa8  
    The `CheckBoxGroup` widget allows selecting between a list of options by
    ticking the corresponding checkboxes.

    It falls into the broad category of multi-option selection widgets that
    provide a compatible API and include the `MultiSelect`, `CrossSelector`
    and `CheckButtonGroup` widgets.

    Reference: https://panel.holoviz.org/reference/widgets/CheckBoxGroup.html

    :Example:

    >>> CheckBoxGroup(
    ...     name='Fruits', value=['Apple', 'Pear'], options=['Apple', 'Banana', 'Pear', 'Strawberry'],
    ...     inline=True
    ... )
    Fr   rr   r   r   N)
r<   r=   r>   r   r,   r   r  _BkCheckboxGroupr   rn   r4   r4   r4   r5   r  J  s   
r  c                   @  s*   e Zd ZdZddgZddgZd	ddZdS )
ToggleGroupaO  This class is a factory of ToggleGroup widgets.

    A ToggleGroup is a group of widgets which can be switched 'on' or 'off'.

    Two types of widgets are available through the widget_type argument :
        * `'button'` (default)
        * `'box'`

    Two different behaviors are available through behavior argument:
        * 'check' (default) : boolean
           Any number of widgets can be selected. In this case value
           is a 'list' of objects.
        * 'radio' : boolean
           One and only one widget is switched on. In this case value
           is an 'object'.
    buttonZboxcheckZradioc                 K  s   |t jvrtd|t j|t jvr8td|t j|dkrf|dkrVtf i |S tf i |S nDt|dt	rtd|d  |dkrt
f i |S tf i |S d S )Nz1widget_type {} is not valid. Valid options are {}z.behavior {} is not valid. Valid options are {}r  r  rG   z/Radio buttons require a single value, found: %s)r
  _widgets_typerg   r   
_behaviorsr  r  r+   r   r7   r   r   )clsr   ZbehaviorrH   r4   r4   r5   __new__z  s&    

zToggleGroup.__new__N)r  r  )r<   r=   r>   r   r  r  r  r4   r4   r4   r5   r
  e  s   r
  c                      s  e Zd ZdZejddddZejddddZeje	j
ddZejd	d
dZejdddZ fddZejddddd Zejddddd Zejddddd Zejddddd Zejddddd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd+d)d*Z  ZS ),CrossSelectora  
    A composite widget which allows selecting from a list of items
    by moving them between two lists. Supports filtering values by
    name to select them in bulk.

    Reference: https://panel.holoviz.org/reference/widgets/CrossSelector.html

    :Example:

    >>> CrossSelector(
    ...     name='Fruits', value=['Apple', 'Pear'],
    ...     options=['Apple', 'Banana', 'Pear', 'Strawberry']
    ... )
    iX  Tzu
        The number of options shown at once (note this is the
        only way to control the height of this widget)rx      z
        The filter function applied when querying using the text
        fields, defaults to re.search. Function is two arguments, the
        query or pattern and the item label.rr   r   zu
        The number of options shown at once (note this is the only way
        to control the height of this widget)z
       Whether to preserve definition order after filtering. Disable
       to allow the order of selection to define the order of the
       selected list.c                   s  t  jf i | | j| j   fdd|dg D fdd D }tddd}tf || jd|tf | jd|d	| _| jd
 j	
| jd | jd j	
| jd tdddtdddd	| _| jd
 j	
| jd | jd j	
| jd tddddtddddd	| _| jd
 j	
| jd | jd j	
| jd tf ddd|| _| jrr| jd n| j}t| jd
 | jd
 fi || _t| jd |fi || _t| jd | jd
 ddd}| j|| jg| jd d < g g d	| _ddd	| _|   |   d S )Nc                   s$   g | ]}t |r t| qS r4   r   rY   r   r4   r5   rO     s   
z*CrossSelector.__init__.<locals>.<listcomp>rG   c                   s   g | ]}| vr|qS r4   r4   rL   r   selectedr4   r5   rO     rP   Zstretch_bothr   )Zsizing_modemargin)r*   r|   )FTFTu   ❮❮2   )r.   r   u   ❯❯ZclickszFilter available options)r   r   r   r   r   )r   r  Zwidth_policyzFilter selected optionsr   z\To select an item highlight it on the left and use the arrow button to move it to the right.)r   r   )r      center)r  ZalignrK   )rE   rF   r2   r8   r   r6   r   r|   _listsr,   r   _update_selectionr!   _buttons_apply_selectionr$   _search_filter_optionsr#   _placeholderrG   r   Z_unselected	_selectedr   _selections_query_update_disabled_update_width)r1   rH   
unselectedr   rightZbuttonsrI   r2   r  r8   r5   rF     s\    



 
zCrossSelector.__init__r   r   c                 C  sF   t | jd d }|| jd _|| jd _|| jd _|| jd _d S )Ng       @r  FT)r   r   r  r  )r1   r   r4   r4   r5   r%    s
    zCrossSelector._update_widthr|   c                 C  s    | j | jd _ | j | jd _ d S NFT)r|   r  r9   r4   r4   r5   _update_size  s    zCrossSelector._update_sizer   c                 C  s    | j | jd _ | j | jd _ d S r)  )r   r  r9   r4   r4   r5   r$    s    zCrossSelector._update_disabledrG   c                   s   | j | j   fdd| jD fdd D }| jd _g | jd _|| jd _g | jd _t| jd jr| jd | jd ur| jd | jd< n,t| jd js| jd | jur| j| jd< d S )Nc                   s$   g | ]}t |r t| qS r4   r   rY   r   r4   r5   rO     s   
z/CrossSelector._update_value.<locals>.<listcomp>c                   s   g | ]}| vr|qS r4   r4   r  r  r4   r5   rO     rP   TFr   )r2   r8   rG   r  r*   rR   r!  r   )r1   r&  r4   r(  r5   _update_value  s    $ zCrossSelector._update_valuer*   c                 C  s    g | j d< g | j d< |   dS )zy
        Updates the options of each of the sublists after the options
        for the whole widget are updated.
        FTN)r"  r+  r9   r4   r4   r5   _update_options  s    

zCrossSelector._update_optionsc                 C  s   |  d |  d d S r)  )_apply_queryr9   r4   r4   r5   _apply_filters%  s    
zCrossSelector._apply_filtersc                 C  s*   |j | jd u }|j| j|< | | dS )zI
        Filters unselected options based on a text query event.
        TN)r   r  newr#  r-  r1   r   r  r4   r4   r5   r  )  s    zCrossSelector._filter_optionsc                   s   j | j|  j j}jr8 fdd|D }nj| j}sb|j| _g j| _nZzfdd|D }W n ty   g }Y n0 |r|ng j| _dd |D j| _d S )Nc                   s   g | ]}| vr|qS r4   r4   r  )otherr4   r5   rO   6  rP   z.CrossSelector._apply_query.<locals>.<listcomp>c                   s   g | ]}  |r|qS r4   )	filter_fnrL   r3   )queryr1   r4   r5   rO   >  rP   c                 S  s   g | ]}|qS r4   r4   )rL   mr4   r4   r5   rO   B  rP   )r#  r  r2   definition_orderr8   r*   rG   r   )r1   r  r2   r*   matchesr4   )r1  r4  r1   r5   r-  1  s    

zCrossSelector._apply_queryc                 C  s*   |j | jd u }dd |jD | j|< dS )z=
        Updates the current selection in each list.
        Tc                 S  s   g | ]}|d kr|qS rK   r4   rY   r4   r4   r5   rO   I  rP   z3CrossSelector._update_selection.<locals>.<listcomp>N)r   r  r/  r"  r0  r4   r4   r5   r  D  s    zCrossSelector._update_selectionc                   s   |j jd u }fddj|  D  j| j}j|  j}dd t|t  D } fdd|D }|rx|ni j| _|r|ni j|  _tjd jrjd jd< njjd< fddjd jD _	
  d	S )
z^
        Applies the current selection depending on which button was
        pressed.
        Tc                   s   i | ]}| j | qS r4   r   r  r9   r4   r5   r   R  rP   z2CrossSelector._apply_selection.<locals>.<dictcomp>c                 S  s   i | ]
}||qS r4   r4   r  r4   r4   r5   r   V  rP   c                   s   i | ]}| vr||qS r4   r4   r  )r/  r4   r5   r   W  rP   r   c                   s   g | ]}|d kr j | qS r8  r   r3  r9   r4   r5   rO   ^  rP   z2CrossSelector._apply_selection.<locals>.<listcomp>N)r   r  r"  r  r*   r7   rR   r!  r   rG   r.  )r1   r   r  oldr1  mergedZ	leftoversr4   )r/  r1   r5   r  K  s    zCrossSelector._apply_selectionNc                 C  s   | j ||||S r)   )r   
_get_model)r1   rs   rk   parentZcommr4   r4   r5   r;  a  s    zCrossSelector._get_model)NNN)r<   r=   r>   r   r,   r   r   heightCallableresearchr2  r|   r6  rF   r   r%  r*  r$  r+  r,  r.  r  r-  r  r  r;  ro   r4   r4   rI   r5   r    s.   A




	r  )Kr   
__future__r   r   r?  typesr   typingr   r   r   r   r   r	   r
   numpyr   r,   Zbokeh.modelsr   Zbokeh.models.widgetsr   r   r   r	  r   r   r   r   r   r  Zio.resourcesr   Zlayout.baser   r   r   modelsr   r  r   r   r   r   r   utilr   r   r   Z_mixinr   baser   r    r  r!   r"   inputr#   r$   Zbokeh.modelr%   r&   rA   rp   r   r   r   r   r   r  r  r  r
  r  r4   r4   r4   r5   <module>   sN   $M 1  PC&0H7#&!.