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 ddl	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Zddlm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/m/Z/ d	dl0m1Z1m2Z2 d	dl3m4Z5m6Z7 d	dl8m9Z9m:Z: ddl;m<Z<m=Z= e
r:ddl>m?Z? ddl@mAZA ddlBmCZC d	dlDmEZE G dd de=Z-G dd de-Z'G dd de-Z6G dd de=Z#G dd de=ZFG dd de=ZG d d! d!e=ZG d"d# d#e=ZGG d$d% d%eGZ4G d&d' d'eGZHG d(d) d)e=ZG d*d+ d+e=ZIG d,d- d-eIZJG d.d/ d/eIZKG d0d1 d1eIZLG d2d3 d3eLeJZMG d4d5 d5eLeKZNG d6d7 d7eLZOeOZ)G d8d9 d9e=ZPG d:d; d;ePZQG d<d= d=ePZRG d>d? d?e<ZSG d@dA dAe=ZTG dBdC dCeTZG dDdE dEeTZ+dS )Fz`
The input widgets generally allow entering arbitrary information into
a text field or similar.
    )annotationsN	b64decode)datedatetime)	TYPE_CHECKINGAnyClassVarDictIterableMappingOptionalTupleType)TickFormatter)CheckboxColorPicker
DatePickerDateRangePickerDiv	FileInputNumericInputPasswordInputSpinnerSwitch	TextInput   )config)ColumnPanel)DatetimePickerTextAreaInput)param_reprstry_datetime64_to_datetime   )CompositeWidgetWidget)Document)Model)Comm)Viewablec                      s   e Zd ZU 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
dZ
ejdd	ddZejdd	ddZeZded< edddd fddZ  ZS )r   z
    The `TextInput` widget allows entering any string using a text input box.

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

    :Example:

    >>> TextInput(name='Name', placeholder='Enter your name here ...')
    NB
        An HTML string describing the function of this component.defaultdoci  z4
        Max count of characters in the input field. +
        Placeholder for empty input field.TzK
        Initial or entered text value updated when <enter> key is pressed.r-   Z
allow_Noner.   zB
        Initial or entered text value updated on every key press.,  ~
      Width of this component. If sizing_mode is set to stretch
      or scale mode this will merely be used as a suggestion.ClassVar[Type[Model]]_widget_typeFzparam.Parameterr*   )	parameterreturnc                   s   ||d< t  j|fi |S )a  
        Construct a widget from a Parameter and link the two
        bi-directionally.

        Parameters
        ----------
        parameter: param.Parameter
          A parameter to create the widget from.
        onkeyup: boolean
          Whether to trigger events on every key press.
        params: dict
          Keyword arguments to be passed to the widget constructor

        Returns
        -------
        Widget instance linked to the supplied parameter
        onkeyup)super
from_param)clsr6   r8   params	__class__ `/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/widgets/input.pyr:   M   s    zTextInput.from_param)F)__name__
__module____qualname____doc__paramStringdescriptionInteger
max_lengthplaceholdervalueZvalue_inputwidth_BkTextInputr5   __annotations__classmethodr:   __classcell__r?   r?   r=   r@   r   -   s   

r   c                   @  s   e Zd ZU dZeZded< dS )r   a'  
    The `PasswordInput` allows entering any string using an obfuscated text
    input box.

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

    :Example:

    >>> PasswordInput(
    ...     name='Password', placeholder='Enter your password here...'
    ... )
    r4   r5   N)rA   rB   rC   rD   _BkPasswordInputr5   rN   r?   r?   r?   r@   r   d   s   
r   c                   @  sh   e Zd ZU 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g dddZeZded< dS )r!   a`  
    The `TextAreaInput` allows entering any multiline string using a text input
    box.

    Lines are joined with the newline character `
`.

    Reference: https://panel.holoviz.org/reference/widgets/TextAreaInput.html
    :Example:

    >>> TextAreaInput(
    ...     name='Description', placeholder='Enter your description here...'
    ... )
    Fzl
        Whether the text area should automatically grow vertically to
        accommodate the current text.r,      z3
        Number of columns in the text input field.Nzq
        When combined with auto_grow this determines the maximum number
        of rows the input area can grow.r   z0
        Number of rows in the text input field.)ZbothrL   heightFz
        Whether the layout is interactively resizable,
        and if so in which dimensions: `width`, `height`, or `both`.
        Can only be set during initialization.)objectsr.   r4   r5   )rA   rB   rC   rD   rE   BooleanZ	auto_growrH   colsZmax_rowsrowsObjectSelectorZ	resizable_bkTextAreaInputr5   rN   r?   r?   r?   r@   r!   u   s   
r!   c                      s   e Zd ZU dZejddZejdddZejde	e
fddZejde	e
fddZejddZejddZddd	Zd
ed< ddiZd
ed< eZded<  fddZe fddZ fddZdd Z  ZS )r   a  
    The `FileInput` allows the user to upload one or more files to the server.

    It makes the filename, MIME type and (bytes) content available in Python.

    Please note

    - you can in fact *drag and drop* files onto the `FileInput`.
    - you easily save the files using the `save` method.

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

    :Example:

    >>> FileInput(accept='.png,.jpeg', multiple=True)
    Nr-   r+   r,   Tr-   class_Zis_instanceF)filenamename"ClassVar[Mapping[str, str | None]]_renamerK   z/'data:' + source.mime_type + ';base64,' + value_source_transformsr4   r5   c                   s4   t  |}d|v r|d d|v r0|d |S )NrK   	mime_type)r9   _process_param_changepopselfmsgr=   r?   r@   rc      s    

zFileInput._process_param_changec                   s   t  j}|d S )N)r]   r9   _linked_properties)rf   Z
propertiesr=   r?   r@   ri      s    zFileInput._linked_propertiesc                   sN   t  |}d|v rJt|d tr4t|d |d< ndd |d D |d< |S )NrK   c                 S  s   g | ]}t |qS r?   r   ).0contentr?   r?   r@   
<listcomp>       z6FileInput._process_property_change.<locals>.<listcomp>)r9   _process_property_change
isinstancestrr   re   r=   r?   r@   rn      s    z"FileInput._process_property_changec              	   C  s   | j }t|tr$t|ts$tdnt|ts@t|tr@tdt|tsR| j g}t|tsb|g}t||D ]R\}}t|trt|d}|| W d   q1 s0    Y  ql|| qldS )z
        Saves the uploaded FileInput data object(s) to file(s) or
        BytesIO object(s).

        Arguments
        ---------
        filename (str or list[str]): File path or file-like object
        zFileInput contains a list of files but only a single filename was given. Please provide a list of filenames or file-like objects.zzFileInput contains a single files but a list of filenames was given. Please provide a single filename or file-like object.wbN)rK   ro   list	TypeErrorziprp   openwrite)rf   r]   rK   valfnfr?   r?   r@   save   s$    	


*zFileInput.save)rA   rB   rC   rD   rE   rF   acceptrG   ClassSelectorrp   rr   r]   rb   rU   multiple	ParameterrK   r`   rN   ra   _BkFileInputr5   rc   propertyri   rn   rz   rP   r?   r?   r=   r@   r      s*   


	r   c                      sz   e Zd ZU dZejdddZdZded< ddd	Z	d
ed< ddiZ
d
ed< ddiZd
ed< eZded<  fddZ  ZS )
StaticTextz
    The `StaticText` widget displays a text value, but does not allow editing
    it.

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

    :Example:

    >>> StaticText(name='Model', value='animagen2')
    N
        The current valuer,   z<b>{title}</b>: {value}zClassVar[str]_formattextr^   rK   r_   r`   rK   z%target.text.split(": ")[0]+": "+value_target_transformszvalue.split(": ")[1]ra   r4   r5   c                   sf   t  |}d|v rbt|d}| jddj| jd}| jrZ| jj| j||dd}||d< |S )Nr   z{value}r/   )title)r   rK   )r9   rc   rp   rd   r   replaceformatr^   )rf   rg   r   partialr=   r?   r@   rc     s    z StaticText._process_param_change)rA   rB   rC   rD   rE   r~   rK   r   rN   r`   r   ra   _BkDivr5   rc   rP   r?   r?   r=   r@   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dddZej	de
efdZej	de
efdZejdd	d
dZejdddZi Zded< dddZded< eZded<  fddZ fddZ  ZS )r   aW  
    The `DatePicker` allows selecting a `date` value using a text box
    and a date-picking utility.

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

    :Example:

    >>> DatePicker(
    ...     value=date(2025,1,1),
    ...     start=date(2025,1,1), end=date(2025,12,31),
    ...     name='Date'
    ... )
    Nr   r,   <
        Inclusive lower bound of the allowed date selection<
        Inclusive upper bound of the allowed date selectionr-   	item_typer2   Tr3   r1   r+   r_   ra   min_datemax_datestartendr`   r4   r5   c                   sb   d|v rt |d}||d< d|v rLt|d }t|drD| }||d< t jf i | d S )Noptionsenabled_datesrK   r   )rr   rd   r#   hasattrr   r9   __init__)rf   r<   r   rK   r=   r?   r@   r   S  s    
zDatePicker.__init__c                   sL   t  |}dD ]6}||vrq|| }t|trtt|d||< q|S )Nr   r   rK   %Y-%m-%d)r9   rn   ro   rp   r   r   strptimerf   rg   prK   r=   r?   r@   rn   a  s    
z#DatePicker._process_property_change)rA   rB   rC   rD   rE   CalendarDaterK   r   r   Listr   rp   disabled_datesr   rH   rL   rF   rG   ra   rN   r`   _BkDatePickerr5   r   rn   rP   r?   r?   r=   r@   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dddZ	ej
deefdZej
deefdZejdd	d
dZejdddZdddddZded< dddZded< eZded<  fddZejddd	ddd Z fddZ fdd Zed!d" Zed#d$ Z  Z S )%r   a~  
    The `DateRangePicker` allows selecting a `date` range using a text box
    and a date-picking utility.

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

    :Example:

    >>> DateRangePicker(
    ...     value=(date(2025,1,1), date(2025,1,5)),
    ...     start=date(2025,1,1), end=date(2025,12,31),
    ...     name='Date range'
    ... )
    Nr   r,   r   r   r   r2   Tr3   r1   r+   rK   r   r   moder_   ra   r   r   r   r`   r4   r5   c                   s   t  jf i | |   d S N)r9   r   _update_value_boundsrf   r<   r=   r?   r@   r     s    zDateRangePicker.__init__r   r   watchc                 C  s&   | j | jf| jj_| jj| j d S r   )r   r   rE   rK   bounds	_validaterf   r?   r?   r@   r     s    z$DateRangePicker._update_value_boundsc                   sP   t  |}dD ]:}||vrq|| }t|trt fdd|D ||< q|S )Nr   c                 3  s   | ]}  |V  qd S r   )_convert_string_to_daterj   vr   r?   r@   	<genexpr>  rm   z;DateRangePicker._process_property_change.<locals>.<genexpr>)r9   rn   ro   tupler   r=   r   r@   rn     s    
z(DateRangePicker._process_property_changec                   sj   t  |}d|v r2t fdd|d D |d< d|v rL |d |d< d|v rf |d |d< |S )NrK   c                 3  s   | ]}  |V  qd S r   )_convert_date_to_stringr   r   r?   r@   r     rm   z8DateRangePicker._process_param_change.<locals>.<genexpr>r   r   )r9   rc   r   r   re   r=   r   r@   rc     s    z%DateRangePicker._process_param_changec                 C  s   t | d S Nr   )r   r   r   r   r?   r?   r@   r     s    z'DateRangePicker._convert_string_to_datec                 C  s
   |  dS r   strftimer   r?   r?   r@   r     s    z'DateRangePicker._convert_date_to_string)!rA   rB   rC   rD   rE   	DateRangerK   r   r   r   r   r   rp   r   r   rH   rL   rF   rG   ra   rN   r`   _BkDateRangePickerr5   r   dependsr   rn   rc   staticmethodr   r   rP   r?   r?   r=   r@   r   l  s,   




r   c                      s*  e Zd ZU ejdeefddZejdeef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ejddddZejdddZej	dddZdddddZded< ddddZded< eZded< dZ fddZdd Zejdddd d!d" Z fd#d$Z fd%d&Z   Z!S )'_DatetimePickerBaseNz/
      Dates to make unavailable for selection.)r-   r   r.   z-
      Dates to make available for selection.Tz0
      Enable editing of the time in the widget.r,   z3
      Enable editing of the seconds in the widget.z;
      Inclusive upper bound of the allowed date selection.z1
      Whether to display time in 24 hour format.z;
      Inclusive lower bound of the allowed date selection.r2   r3   r1   r+   z
        Whether to return values as numpy.datetime64. If left unset,
        will be True if value is a numpy.datetime64, else False.r   r_   ra   r   r   )r   r   as_numpy_datetime64r`   r4   r5   c                   sb   d|v rt |d}||d< |dd d u rDt|dtj|d< t jf i | |   d S )Nr   r   r   rK   )	rr   rd   getro   np
datetime64r9   r   r   )rf   r<   r   r=   r?   r@   r     s    z_DatetimePickerBase.__init__c                   s   |d u rd S t |tr>t |ts>t|}| fdd|D S t|}t |trT|S t |trpt|j|j|j	S t |trt
|dS td| dd S )Nc                 3  s   | ]}  |V  qd S r   )_convert_to_datetime)rj   vvr   r?   r@   r     s   z;_DatetimePickerBase._convert_to_datetime.<locals>.<genexpr>%Y-%m-%d %H:%M:%SzCould not convert z to datetime)ro   r   rp   typer#   r   r   yearmonthdayr   
ValueError)rf   r   Zcontainer_typer?   r   r@   r     s    


z(_DatetimePickerBase._convert_to_datetimer   r   r   c                 C  s8   |  | j|  | jf| jj_| jj|  | j d S r   )r   r   r   rE   rK   r   r   r   r?   r?   r@   r     s    



z(_DatetimePickerBase._update_value_boundsc                   s*   t  |}d|v r&| |d |d< |S NrK   )r9   rn   _serialize_valuere   r=   r?   r@   rn     s    z,_DatetimePickerBase._process_property_changec                   sd   t  |}d|v r,| | |d |d< d|v rF| |d |d< d|v r`| |d |d< |S )NrK   r   r   )r9   rc   _deserialize_valuer   re   r=   r?   r@   rc      s    z)_DatetimePickerBase._process_param_change)"rA   rB   rC   rE   r   r   rp   r   r   rU   Zenable_timeZenable_secondsDater   Zmilitary_timer   rH   rL   rF   rG   r   ra   rN   r`   _bkDatetimePickerr5   Z_DatetimePickerBase__abstractr   r   r   r   rn   rc   rP   r?   r?   r=   r@   r     s,   

	r   c                   @  s:   e Zd ZdZejddZejdddZdd Z	d	d
 Z
dS )r    a  
    The `DatetimePicker` allows selecting selecting a `datetime` value using a
    textbox and a datetime-picking utility.

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

    :Example:

    >>> DatetimePicker(
    ...    value=datetime(2025,1,1,22,0),
    ...    start=date(2025,1,1), end=date(2025,12,31),
    ...    military_time=True, name='Date and time'
    ... )
    NrZ   singleTconstantc                 C  s0   t |tr,|r,| jr t|}nt|d}|S Nr   )ro   rp   r   r   r   r   r   rf   rK   r?   r?   r@   r   @  s
    zDatetimePicker._serialize_valuec                 C  s   t |ttfr|d}|S r   )ro   r   r   r   r   r?   r?   r@   r   H  s    
z!DatetimePicker._deserialize_value)rA   rB   rC   rD   rE   r   rK   rF   r   r   r   r?   r?   r?   r@   r    +  s
   r    c                   @  s<   e Zd ZdZejdddZejdddZdd	 Z	d
d Z
dS )DatetimeRangePickera  
    The `DatetimeRangePicker` allows selecting selecting a `datetime` range
    using a text box and a datetime-range-picking utility.

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

    :Example:

    >>> DatetimeRangePicker(
    ...    value=(datetime(2025,1,1,22,0), datetime(2025,1,2,22,0)),
    ...    start=date(2025,1,1), end=date(2025,12,31),
    ...    military_time=True, name='Datetime Range'
    ... )
    Nr   r,   rangeTr   c                   s2   t |tr.|r. fdd|dD }t|}|S )Nc                   s(   g | ] } j rt|n
t|d qS )r   )r   r   r   r   r   )rj   rK   r   r?   r@   rl   e  s   z8DatetimeRangePicker._serialize_value.<locals>.<listcomp> to )ro   rp   splitr   r   r?   r   r@   r   c  s    
z$DatetimeRangePicker._serialize_valuec                 C  s.   t |trddd |D }|d u r*d}|S )Nr   c                 s  s   | ]}| d V  qdS )r   Nr   r   r?   r?   r@   r   q  rm   z9DatetimeRangePicker._deserialize_value.<locals>.<genexpr>r/   )ro   r   joinr   r?   r?   r@   r   o  s
    
z&DatetimeRangePicker._deserialize_value)rA   rB   rC   rD   rE   r   rK   rF   r   r   r   r?   r?   r?   r@   r   N  s
   r   c                   @  sZ   e Zd ZU 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diZded< dS )r   u  
    The `ColorPicker` widget allows selecting a hexadecimal RGB color value
    using the browser’s color-picking widget.

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

    :Example:

    >>> ColorPicker(name='Color', value='#99ef78')
    Nr+   r,   z
        The selected color4   Tr3   r1   r4   r5   rK   colorr_   r`   )rA   rB   rC   rD   rE   rF   rG   ZColorrK   rH   rL   _BkColorPickerr5   rN   r`   r?   r?   r?   r@   r   x  s   
r   c                   @  s   e Zd ZU ejdddZejddddZejdd	dZej	de
efd
dZejddddZejddddZdddZded< eZded< dZdS )_NumericInputBaseNr+   r,   r   T*
        The current value of the spinner.r1   0r0   zG
        Allows defining a custom format string or bokeh TickFormatter.)r-   r\   r.   *
        Optional minimum allowable value.*
        Optional maximum allowable value.lowhighr   r_   r`   r4   r5   )rA   rB   rC   rE   rF   rG   NumberrK   rJ   r|   rp   r   r   r~   r   r   r`   rN   _BkNumericInputr5   Z_NumericInputBase__abstractr?   r?   r?   r@   r     s   
r   c                   @  sP   e Z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	d
Z	dZ
dS )_IntInputBaser   Tr   r1   Nr   r   intB
        Define the type of number which can be enter in the inputr-   r   r.   )rA   rB   rC   rE   rH   rK   r   r   rF   r   Z_IntInputBase__abstractr?   r?   r?   r@   r     s
   r   c                   @  sP   e Z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	d
Z	dZ
dS )_FloatInputBaser   Tr   r1   Nr   r   floatr   r   )rA   rB   rC   rE   r   rK   r   r   rF   r   Z_FloatInputBase__abstractr?   r?   r?   r@   r     s
   r   c                      s   e Zd ZU ejddddZejdddZejdd	d
dZddiZde	d< e
Zde	d< d	Z fddZd(ddZedd fddZddddddd d! fd"d#Z fd$d%Z fd&d'Z  ZS ))_SpinnerBase
   r   Nzs
        Defines the multiplication factor applied to step when the page up
        and page down keys are pressed.)r-   r   r.   d   z
        Defines the debounce time in ms before updating `value_throttled` when
        the mouse wheel is used to change the input.r,   r2   Tr3   r1   value_throttledNr_   r`   r4   r5   c                   sZ   d|vr&| d| j}|d ur&||d< d|v rDd| jv rD|d |d< t jf i | d S )NrK   r   r   )r   rK   rE   r9   r   )rf   r<   rK   r=   r?   r@   r     s    z_SpinnerBase.__init__r   c                 C  s"   dj t| jdt| dgdS )Nz{cls}({params})z, r   )r;   r<   )r   r   rA   r   r"   )rf   depthr?   r?   r@   __repr__  s    z_SpinnerBase.__repr__z
Tuple[str])r7   c                   s   t  jd S )N)r   rh   r   r=   r?   r@   ri     s    z_SpinnerBase._linked_propertiesz$Dict[str, param.parameterized.Event]zDict[str, Any]r(   r'   zOptional[Comm]None)eventsrg   rootmodelr.   commr7   c                   s$   d|v r|d= t  ||||||S )Nr   )r9   _update_model)rf   r   rg   r   r   r.   r   r=   r?   r@   r     s    z_SpinnerBase._update_modelc                   s4   d|v r(|d t dkr(d |d< d |d< t |S )NrK   z-infr   )r   r9   rc   re   r=   r?   r@   rc     s    z"_SpinnerBase._process_param_changec                   s4   t jr(d|v r|d= d|v r(|d |d< t |S )NrK   r   )r   Z	throttledr9   rn   re   r=   r?   r@   rn     s    z%_SpinnerBase._process_property_change)r   )rA   rB   rC   rE   rH   Zpage_step_multiplierZ
wheel_waitrL   r`   rN   
_BkSpinnerr5   Z_SpinnerBase__abstractr   r   r   ri   r   rc   rn   rP   r?   r?   r=   r@   r     s   
	
	r   c                   @  sB   e Zd ZU dZejdddZejddddZd	d
dZde	d< dS )IntInputa  
    The `IntInput` allows selecting an integer value using a spinbox.

    It behaves like a slider except that lower and upper bounds are optional
    and a specific value can be entered. The value can be changed using the
    keyboard (up, down, page up, page down), mouse wheel and arrow buttons.

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

    :Example:

    >>> IntInput(name='Value', value=100, start=0, end=1000, step=10)
    r$   
        The step size.r,   NTV
        The current value. Updates only on `<enter>` or when the widget looses focus.r   r   r   r   r_   r`   )
rA   rB   rC   rD   rE   rH   stepr   r`   rN   r?   r?   r?   r@   r     s   
r   c                      sl   e Zd ZU dZejdddZejdddZejddd	d
Z	dddZ
ded<  fddZ fddZ  ZS )
FloatInputa  
    The `FloatInput` allows selecting a floating point value using a spinbox.

    It behaves like a slider except that the lower and upper bounds are
    optional and a specific value can be entered. The value can be changed
    using the keyboard (up, down, page up, page down), mouse wheel and arrow
    buttons.

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

    :Example:

    >>> FloatInput(name='Value', value=5., step=1e-1, start=0, end=10)
    r/   z-
        Placeholder when the value is empty.r,   g?r   NTr   r   r   r   r   r_   r`   c                   sD   | ddd u rtd|d< | ddd u r8td|d< t |S )NrK   FNaNr   )r   r   r9   rc   re   r=   r?   r@   rc   A  s
    z FloatInput._process_param_changec                   sP   | ddr"t|d r"d |d< | ddrDt|d rDd |d< t |S )NrK   Fr   )r   r   isnanr9   rn   re   r=   r?   r@   rn   H  s
    z#FloatInput._process_property_change)rA   rB   rC   rD   rE   rF   rJ   r   r   r   r`   rN   rc   rn   rP   r?   r?   r=   r@   r   &  s   
r   c                   @  s   e Zd Zdd ZdS )NumberInputc                   s>   g d}t  fdd|D r,tf i  S tf i  S d S )N)rK   r   stopr   c                 3  s    | ]}t  |d tV  qdS r   )ro   r   r   rj   r   r<   r?   r@   r   T  rm   z&NumberInput.__new__.<locals>.<genexpr>)allr   r   )rf   r<   Z
param_listr?   r   r@   __new__R  s    zNumberInput.__new__N)rA   rB   rC   r  r?   r?   r?   r@   r   P  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dddgd	d
Z	ej
deefddZejddZejddddZdddZded< dddZded< ddiZded< eZded<  fddZdd Z fd d!Z fd"d#Z  ZS )$LiteralInputa  
    The `LiteralInput` allows declaring Python literals using a text
    input widget.

    A *literal* is some specific primitive value of type `str`
    , `int`, `float`, `bool` etc or a `dict`, `list`, `tuple`, `set` etc of
    primitive values.

    Optionally the literal `type` may be declared.

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

    :Example:

    >>> LiteralInput(name='Dictionary', value={'key': [1, 2, 3]}, type=dict)
    Nr+   r,   r/   z)
      Placeholder for empty input field.astjsonz
       The serialization (and deserialization) method to use. 'ast'
       uses ast.literal_eval and 'json' uses json.loads and json.dumps.
    )r-   rT   r.   Tr[   rZ   r2   r3   r1   )r   
serializerr_   r`   z$JSON.parse(value.replace(/'/g, '"')))r  rK   ra   rK   z<JSON.stringify(value).replace(/,/g, ",").replace(/:/g, ": ")r   r4   r5   c                   s>   t  jf i | d| _| d  | j| j| jd d S )Nr/   rK   )r9   r   _stater   Z_internal_callbacksappendrE   r   r   r=   r?   r@   r     s    
zLiteralInput.__init__c                 C  sn   | j d u rd S | j}t|| j sj|d urj|r4|j| _t| j trJt| j n| j j}td||t |jf d S )Nz9LiteralInput expected %s type but value %s is of type %s.)r   rK   ro   oldr   reprrA   r   )rf   eventnewtypesr?   r?   r@   r     s    zLiteralInput._validatec              	     sN  t  |}d}d|v r|d}z2|dkr4d}n | jdkrJt|}n
t|}W n tyr   d}| j	}Y n0 | j
rt|| j
st| j
tr| j
n| j
f}d }|D ](}z||}W n ty   Y q0  qq|d u r|dkrd }n$|d u r|d urd}| j	}n|}||d< |d| j| jd| |d< || _| jd |S )Nr/   rK   r  
 (invalid)z (wrong type)r   r^   )r9   rn   rd   r  r  loadsr  literal_eval	ExceptionrK   r   ro   r   r   r^   r   r  rE   trigger)rf   rg   	new_staterK   ZvtypesZtyped_valuevtyper=   r?   r@   rn     sB    


 z%LiteralInput._process_property_changec                   sp   t  |}d|v rb|d }t|tr0t|}n*| jdkrFt|}n|d u rRdnt|}||d< | j|d< |S )NrK   r  r/   r   )	r9   rc   ro   rp   r
  r  r  dumpsr^   rf   rg   rK   r=   r?   r@   rc     s    



z"LiteralInput._process_param_change)rA   rB   rC   rD   rE   rF   rG   rJ   rX   r  r|   r   r   r~   rK   rH   rL   r`   rN   ra   r   rM   r5   r   r   rn   rc   rP   r?   r?   r=   r@   r  ^  s*   
'r  c                      sl   e Zd ZU dZejdddZddiZded< dddd	Z	ded
<  fddZ
 fddZ fddZ  ZS )
ArrayInputa;  
    The `ArrayInput` allows rendering and editing NumPy arrays in a text
    input widget.

    Arrays larger than the `max_array_size` will be summarized and editing
    will be disabled.

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

    :Example:

    >>> To be determined ...
    i  a.  
        Arrays larger than this limit will be allowed in Python but
        will not be serialized into JavaScript. Although such large
        arrays will thus not be editable in the widget, such a
        restriction helps avoid overwhelming the browser and lets
        other widgets remain usable.r,   max_array_sizeNr_   r`   )r  r   rK   ra   c                   s   t  jf i | d| _d S )NF)r9   r   _auto_disabledr   r=   r?   r@   r     s    zArrayInput.__init__c                   s8   t  |}d|v r4t|d tr4t|d |d< |S r   )r9   rn   ro   rr   r   Zasarrayre   r=   r?   r@   rn     s    z#ArrayInput._process_property_changec                   s   | ddrd| _| d}|d u r0t |S |j| jkrj| |d< | jr| jrd| _d|d< d| _nRtj	|d d| jd|d< | js| j
d|j d| j d d	| _d	|d< d	| _t |S )
NdisabledFrK   ,)	separator	thresholdzNumber of array elements (z) exceeds `max_array_size` (z), editing will be disabled.T)r   r  r9   rc   sizer  tolistr  r   Zarray2stringrE   warningr  r=   r?   r@   rc     s2    


z ArrayInput._process_param_change)rA   rB   rC   rD   rE   r   r  r`   rN   ra   r   rn   rc   rP   r?   r?   r=   r@   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dddZej	dddZ
eZdddd	Zd
ed< ddddddZd
ed<  fddZdd Zdd Zdd Z  ZS )DatetimeInputa7  
    The `DatetimeInput` allows specifying Python `datetime` like values using
    a text input widget.

    An optional `type` may be declared.

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

    :Example:

    >>> DatetimeInput(name='Datetime', value=datetime(2019, 2, 8))
    Nr   r,   r   r   r   F
        Datetime format used for parsing and formatting the datetime.)rK   r   r   r_   ra   )r   r   r   r   r  r`   c                   s0   t  jf i | | j| jd | d  d S r   )r9   r   rE   r   r   r   r=   r?   r@   r   F  s    zDatetimeInput.__init__c                 C  s   | j }|d ur| jd ur"| j|ks6| jd ur| j|k rt|| j}t| j| j}t| j| j}|rp|j| _ tdj|||dd S )NzPDatetimeInput value must be between {start} and {end}, supplied value is {value}r   )rK   r   r   r   r   r   r	  r   )rf   r  r  rK   r   r   r?   r?   r@   r   K  s    zDatetimeInput._validatec                 C  s   t | |}d}d|v r|d}zt|| j}W n tyP   d}| j}Y n<0 |d ur| jd urn| j|ks| j	d ur| j	|k rd}| j}||d< |
d| j| jd| |d< || _|S )Nr/   rK   r  z (out of bounds)r   r^   )r&   rn   rd   r   r   r   r  rK   r   r   r   r^   r   r  )rf   rg   r  rK   r?   r?   r@   rn   X  s(    
 z&DatetimeInput._process_property_changec                 C  sR   t | |}d|v rD|d }|d u r*d}nt|d | j}||d< | j|d< |S )NrK   r/   r   )r&   rc   r   r   r   r^   r  r?   r?   r@   rc   l  s    
z#DatetimeInput._process_param_change)rA   rB   rC   rD   rE   r   rK   r   r   rF   r   r   r   ra   rN   r`   r   r   rn   rc   rP   r?   r?   r=   r@   r!  !  s   
r!  c                      s   e Zd ZU 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ZeZded<  fddZejddddddd Zejdddddd Zdd Z  ZS )DatetimeRangeInputa  
    The `DatetimeRangeInput` widget allows selecting a `datetime` range using
    two `DatetimeInput` widgets, which return a `tuple` range.

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

    :Example:

    >>> DatetimeRangeInput(
    ...     name='Datetime Range',
    ...     value=(datetime(2017, 1, 1), datetime(2018, 1, 10)),
    ...     start=datetime(2017, 1, 1), end=datetime(2019, 1, 1),
    ... )
    )NNr   r   )r-   lengthr.   Nr   r,   r   r   r"  zClassVar[Type[Panel]]_composite_typec                   s   t dddid| _tddd| _tddd| _d|vrJ|d |d	 f|d< t jf i | d
| _| j	| j| j| jg d| _
| j| jdd | jD  |   |   d S )N)   r   r   r   zwhite-spaceZnowrap)marginZstylesZstretch_width)Zsizing_moder'  rK   r   r   r/   Fc                 S  s   g | ]}|d kr|qS r^   r?   r   r?   r?   r@   rl     rm   z/DatetimeRangeInput.__init__.<locals>.<listcomp>)r   _textr!  _start_endr9   r   _msgZ
_compositeextend	_updatingrE   r   _update_widgets_update_labelr   r=   r?   r@   r     s    zDatetimeRangeInput.__init__r^   z_start.namez	_end.nameTr   c                 C  s(   | j  | jj  | jj  | j | j_d S r   )r^   r*  r+  r,  r)  rK   r   r?   r?   r@   r0    s    z DatetimeRangeInput._update_labelz_start.valuez
_end.valuec                 C  s   | j r
d S | jjd urD| jjd urD| jj| jjkrDd| _|   d S | jrXd| _|   z"d| _ | jj| jjf| _W d| _ nd| _ 0 d S )Nz  (start of range must be <= end)r/   TF)r.  r*  rK   r+  r,  r0  r   r?   r?   r@   _update  s"    
zDatetimeRangeInput._updatec                   s   |rdd |D nt | j d v r. d | jr8d S zxd| _ fdd| j  D }t|| jd d}t|| jd	 d}| jjj	f i | | j
jj	f i | W d
| _nd
| _0 d S )Nc                 S  s   g | ]
}|j qS r?   r(  )rj   r  r?   r?   r@   rl     rm   z6DatetimeRangeInput._update_widgets.<locals>.<listcomp>r^   Tc                   s   i | ]\}}| v r||qS r?   r?   )rj   kr   filtersr?   r@   
<dictcomp>  rm   z6DatetimeRangeInput._update_widgets.<locals>.<dictcomp>r   )rK   r$   F)rr   rE   remover.  valuesitemsdictrK   r*  updater+  )rf   r   r<   Zstart_params
end_paramsr?   r3  r@   r/    s    
z"DatetimeRangeInput._update_widgets)rA   rB   rC   rD   rE   r   rK   r   r   r   rF   r   r   r%  rN   r   r   r0  r1  r/  rP   r?   r?   r=   r@   r#  y  s   


r#  c                   @  sH   e Zd ZU ejdddZdZded< ddd	Zd
ed< dZ	dddZ
dS )_BooleanWidgetFr   r,   TzClassVar[bool]_supports_embedactivelabel)rK   r^   r_   r`   N   c                 C  s(   | | j |jd  d ddgdd ddfS )	Nidr   FTc                 S  s   | j S r   )r>  )xr?   r?   r@   <lambda>  rm   z1_BooleanWidget._get_embed_state.<locals>.<lambda>r>  zcb_obj.active)Z_modelsref)rf   r   r7  Zmax_optsr?   r?   r@   _get_embed_state  s    
z_BooleanWidget._get_embed_state)Nr@  )rA   rB   rC   rE   rU   rK   r=  rN   r`   Z_BooleanWidget__abstractrE  r?   r?   r?   r@   r<    s
   
r<  c                   @  s   e Zd ZU dZeZded< dS )r   aX  
    The `Checkbox` allows toggling a single condition between `True`/`False`
    states by ticking a checkbox.

    This widget is interchangeable with the `Toggle` widget.

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

    :Example:

    >>> Checkbox(name='Works with the tools you know and love', value=True)
    r4   r5   N)rA   rB   rC   rD   _BkCheckboxr5   rN   r?   r?   r?   r@   r     s   
r   c                   @  s0   e Zd ZU dZdddZded< eZded< dS )	r   aR  
    The `Switch` allows toggling a single condition between `True`/`False`
    states by ticking a checkbox.

    This widget is interchangeable with the `Toggle` widget.

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

    :Example:

    >>> Switch(name='Works with the tools you know and love', value=True)
    Nr>  r   r_   r`   r4   r5   )rA   rB   rC   rD   r`   rN   	_BkSwitchr5   r?   r?   r?   r@   r     s   
r   )UrD   
__future__r   r  r  base64r   r   r   typingr   r   r	   r
   r   r   r   r   r   numpyr   rE   Zbokeh.models.formattersr   Zbokeh.models.widgetsr   rF  r   r   r   r   r   r   r   r   r   r   r   r   r   rQ   r   r   r   rG  r   rM   r   Zlayoutr   r   modelsr    r   r!   rY   utilr"   r#   baser%   r&   Zbokeh.documentr'   Zbokeh.modelr(   Zpyviz_commsr)   Zviewabler*   r   r   r   r   r   r   r   r   r   r   r  r  r!  r#  r<  r?   r?   r?   r@   <module>   s\   ,47&d(ETk#*>*|GXT