a
    Df[2                     @  s~  U d 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 ddlZddlmZmZ ddlmZm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$ erddl%m&Z& ddl'm(Z( ddl)m*Z* ddlm+Z+m,Z, g dZ-de.d< ddgZ/de.d< G dd de$Z0G dd de$Z1G dd de$Z2G dd  d e0e2e1e"ZG d!d" d"e0e1ZG d#d$ d$e0e2e1Z3dS )%zt
Defines the Button and button-like widgets which allow triggering
events or merely toggling between on-off states.
    )annotations)
TYPE_CHECKINGAny	AwaitableCallableClassVarDictListMappingOptionalTypeN)ButtonClickMenuItemClick)DropdownToggle)SVGIcon
TablerIcon   )CDN_DISTCallback)Button   )TooltipMixin)Widget)Document)Model)Comm)JSLinkTargetLink)defaultZprimarysuccesswarningZdangerlight	List[str]BUTTON_TYPESsolidoutlineBUTTON_STYLESc                      sx   e Zd ZU ejdeddZejdeddZdddZ	d	e
d
< ddiZd	e
d< e dgZde
d< dZ fddZ  ZS )_ButtonBaser    z
        A button theme; should be one of 'default' (white), 'primary'
        (blue), 'success' (green), 'info' (yellow), 'light' (light),
        or 'danger' (red).)r    Zobjectsdocr&   z=
        A button style to switch between 'solid', 'outline'.labelN)namebutton_style"ClassVar[Mapping[str, str | None]]_renamer-   _source_transformszcss/button.csszClassVar[List[str]]_stylesheetsTc                   s>   d|v sd|v r2| d| jg|d| j |d< t |S )Nr-   css_classes)popr-   getr2   super_process_param_changeselfparams	__class__ a/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/widgets/button.pyr6   5   s    z!_ButtonBase._process_param_change)__name__
__module____qualname__paramZObjectSelectorr%   Zbutton_typer(   r-   r/   __annotations__r0   r   r1   Z_ButtonBase__abstractr6   __classcell__r<   r<   r:   r=   r)   #   s   
r)   c                      sd   e Zd ZU ejdddZejdddZddddZded	< d
Z	dd fddZ
 fddZ  ZS )	IconMixinNz
        An icon to render to the left of the button label. Either an SVG or an
        icon name which is loaded from https://tabler-icons.io.r    r*   Z1emz8
        Size of the icon as a string, e.g. 12px or 1em.icon)	icon_size_iconrF   r.   r/   TNonereturnc                   s,   t | jfi tj| _t jf i | d S N)dictr/   rD   r5   __init__r7   r:   r<   r=   rN   L   s    zIconMixin.__init__c                   s`   | d| j}|dd urT|d }| dr@t||d}nt||d}||d< t |S )NrG   rF   z<svg)svgsize)Z	icon_namerP   rH   )	r3   rG   r4   lstrip
startswithr   r   r5   r6   )r8   r9   rG   rF   Z
icon_modelr:   r<   r=   r6   P   s    zIconMixin._process_param_change)r>   r?   r@   rA   StringrF   rG   r/   rB   Z_IconMixin__abstractrN   r6   rC   r<   r<   r:   r=   rD   =   s   
rD   c                      sl   e Zd ZU dZdZded< dddddd	d
 fddZi dfddddddZi fddddddZ  Z	S )_ClickButtonTbutton_clickClassVar[str]_eventNr   Optional[Model]Optional[Comm]r   r*   rootparentcommrK   c                   s*   t  ||||}| j| j|||d |S )Nmodelr*   r]   )r5   
_get_model_register_eventsrW   r8   r*   r[   r\   r]   r_   r:   r<   r=   r`   b   s    z_ClickButton._get_model zDict[str, Any]strr   )argscoderK   c                 C  s$   ddl m} || d| j |i|dS )a  
        Allows defining a JS callback to be triggered when the button
        is clicked.

        Arguments
        ----------
        args: dict
          A mapping of objects to make available to the JS callback
        code: str
          The Javascript code to execute when the button is clicked.

        Returns
        -------
        callback: Callback
          The Callback which can be used to disable the callback.
        r   r   event:rf   re   )linksr   rW   )r8   re   rf   r   r<   r<   r=   js_on_clickj   s    z_ClickButton.js_on_click)re   	callbacksrK   c                 K  sT   t | D ]8\}}|dkr&d| j }| j||}|dur|||< qt| ||dS )a  
        Allows defining a Javascript (JS) callback to be triggered when a property
        changes on the source object. The keyword arguments define the
        properties that trigger a callback and the JS code that gets
        executed.

        Arguments
        ----------
        args: dict
          A mapping of objects to make available to the JS callback
        **callbacks: dict
          A mapping between properties on the source model and the code
          to execute when that property changes

        Returns
        -------
        callback: Callback
          The Callback which can be used to disable the callback.
        clicksrg   Nrh   )listitemsrW   r/   r4   r   )r8   re   rk   kvvalr<   r<   r=   
jscallback~   s    

z_ClickButton.jscallback)NNN)
r>   r?   r@   Z_ClickButton__abstractrW   rB   r`   rj   rr   rC   r<   r<   r:   r=   rT   \   s   
  rT   c                      s   e Zd ZU dZejdddZejddZi e	j
dddd	Z
d
e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dd fddZd,ddddddd fd d!Zd"d#d$d%d&Zd'd(d)d*d+Z  ZS )-r   a  
    The `Button` widget allows triggering events when the button is
    clicked.

    The Button provides a `value` parameter, which will toggle from
    `False` to `True` while the click event is being processed

    It also provides an additional `clicks` parameter, that can be
    watched to subscribe to click events.

    Reference: https://panel.holoviz.org/reference/widgets/Button.html#widgets-gallery-button

    :Example:

    >>> pn.widgets.Button(name='Click me', icon='caret-right', button_type='primary')
    r   z.
        Number of clicks (can be listened to)rE   zG
        Toggles from False to True while the event is being processed.)r*   Nr+   )rl   r,   valuer.   r/   )r-   descriptionr0   )zevent:button_clickrs   _target_transformsClassVar[Type[Model]]_widget_typec                   s0   | dd }t jf i | |r,| | d S Non_clickr3   r5   rN   ry   r8   r9   Zclick_handlerr:   r<   r=   rN      s    zButton.__init__r$   rJ   c                   s   t  jdg S )Nrs   )r5   _linkable_paramsr8   r:   r<   r=   r|      s    zButton._linkable_paramsFr   zOptional[Dict[str, str]]zOptional[Dict[str, Any]]boolrd   r   )targetrf   re   bidirectionalri   rK   c                   s0    fdd|  D }t j||||fi |S )a  
        Links properties on the this Button to those on the
        `target` object in Javascript (JS) code.

        Supports two modes, either specify a
        mapping between the source and target model properties as
        keywords or provide a dictionary of JS code snippets which
        maps from the source parameter to a JS code snippet which is
        executed when the property changes.

        Arguments
        ----------
        target: panel.viewable.Viewable | bokeh.model.Model | holoviews.core.dimension.Dimensioned
          The target to link the value(s) to.
        code: dict
          Custom code which will be executed when the widget value
          changes.
        args: dict
          A mapping of objects to make available to the JS callback
        bidirectional: boolean
          Whether to link source and target bi-directionally. Default is `False`.
        **links: dict[str,str]
          A mapping between properties on the source model and the
          target model property to link it to.

        Returns
        -------
        Link
          The Link can be used unlink the widget and the target model.
        c                   s(   i | ] \}}|d krd j  n||qS )rs   rg   )rW   ).0prp   r}   r<   r=   
<dictcomp>       z!Button.jslink.<locals>.<dictcomp>)rn   r5   jslink)r8   r   rf   re   r   ri   r:   r}   r=   r      s    #zButton.jslinkr   rI   )eventrK   c                 C  s   | j d |  jd7  _d S )Nrs   r   )rA   triggerrl   )r8   r   r<   r<   r=   _process_event   s    zButton._process_eventz=Callable[[param.parameterized.Event], None | Awaitable[None]]param.parameterized.WatchercallbackrK   c                 C  s   | j j|dddS )a  
        Register a callback to be executed when the `Button` is clicked.

        The callback is given an `Event` argument declaring the number of clicks

        Example
        -------

        >>> button = pn.widgets.Button(name='Click me')
        >>> def handle_click(event):
        ...    print("I was clicked!")
        >>> button.on_click(handle_click)

        Arguments
        ---------
        callback:
            The function to run on click events. Must accept a positional `Event` argument. Can
            be a sync or async function

        Returns
        -------
        watcher: param.Parameterized.Watcher
          A `Watcher` that executes the callback when the button is clicked.
        rl   FZonlychangedrA   Zwatchr8   r   r<   r<   r=   ry      s    zButton.on_click)NNF)r>   r?   r@   __doc__rA   ZIntegerrl   Eventrs   r   r/   rB   r0   ru   	_BkButtonrw   rN   propertyr|   r   r   ry   rC   r<   r<   r:   r=   r      s*   
  &r   c                   @  sT   e Zd ZU dZejdddZdddZded	< d
Z	ded< e
Zded< dddZdS )r   a'  The `Toggle` widget allows toggling a single condition between `True`/`False` states.

    This widget is interchangeable with the `Checkbox` widget.

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

    :Example:

    >>> Toggle(name='Toggle', button_type='success')
    Fz1
        Whether the button is currently toggled.rE   activer+   )rs   r,   r.   r/   TzClassVar[bool]_supports_embedrv   rw   N   c                 C  s(   | | j |jd  d ddgdd ddfS )	Nidr   FTc                 S  s   | j S rL   )r   )xr<   r<   r=   <lambda>,  r   z)Toggle._get_embed_state.<locals>.<lambda>r   zcb_obj.active)Z_modelsref)r8   r[   valuesZmax_optsr<   r<   r=   _get_embed_state*  s    
zToggle._get_embed_state)Nr   )r>   r?   r@   r   rA   Booleanrs   r/   rB   r   	_BkTogglerw   r   r<   r<   r<   r=   r     s   
r   c                      s   e Zd ZU dZejdddZejg ddZej	dddZ
dZd	ed
< ddddZded< eZded<  fddZd$dddddd fddZddddZdd d!d"d#Z  ZS )%
MenuButtonaM  
    The `MenuButton` widget allows specifying a list of menu items to
    select from triggering events when the button is clicked.

    Unlike other widgets, it does not have a `value`
    parameter. Instead it has a `clicked` parameter that can be
    watched to trigger events and which reports the last clicked menu
    item.

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

    :Example:

    >>> menu_items = [('Option A', 'a'), ('Option B', 'b'), None, ('Option C', 'c')]
    >>> MenuButton(name='Dropdown', items=menu_items, button_type='primary')
    Nz'
      Last menu item that was clicked.rE   z
      Menu items in the dropdown. Allows strings, tuples of the form
      (title, value) or Nones to separate groups of items.Fz7
      Whether to add separate dropdown area to button.Zmenu_item_clickrV   rW   r+   menu)r,   rn   clickedr.   r/   rv   rw   c                   s0   | dd }t jf i | |r,| | d S rx   rz   r{   r:   r<   r=   rN   Q  s    zMenuButton.__init__r   rX   rY   r   rZ   c                   s(   t  ||||}| jd|||d |S )NrU   r^   )r5   r`   ra   rb   r:   r<   r=   r`   W  s    zMenuButton._get_modelzButtonClick | MenuItemClick)r   c                 C  s,   t |tr|j}nt |tr"| j}|| _d S rL   )
isinstancer   itemr   r,   r   )r8   r   r   r<   r<   r=   r   _  s
    

zMenuButton._process_eventz+Callable[[param.parameterized.Event], None]r   r   c                 C  s   | j j|dddS )a  
        Register a callback to be executed when the button is clicked.

        The callback is given an `Event` argument declaring the number of clicks

        Arguments
        ---------
        callback: (Callable[[param.parameterized.Event], None])
            The function to run on click events. Must accept a positional `Event` argument

        Returns
        -------
        watcher: param.Parameterized.Watcher
          A `Watcher` that executes the callback when the MenuButton is clicked.
        r   Fr   r   r   r<   r<   r=   ry   f  s    zMenuButton.on_click)NNN)r>   r?   r@   r   rA   rS   r   r	   rn   r   splitrW   rB   r/   _BkDropdownrw   rN   r`   r   ry   rC   r<   r<   r:   r=   r   /  s   
  r   )4r   
__future__r   typingr   r   r   r   r   r   r	   r
   r   r   rA   Zbokeh.eventsr   r   Zbokeh.modelsr   r   r   r   Zbokeh.models.uir   r   Zio.resourcesr   ri   r   Zmodels.widgetsr   r   Z_mixinr   baser   Zbokeh.documentr   Zbokeh.modelr   Zpyviz_commsr   r   r   r%   rB   r(   r)   rD   rT   r   r<   r<   r<   r=   <module>   s0   0?x