
    	e0                       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 ddlZddlmZmZ ddlmZ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  erd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e           Z, G d de           Z- G d de,e-          Z. G d de.          Z G d d e,e-          Z G d! d"e.          Z/dS )#zt
Defines the Button and button-like widgets which allow triggering
events or merely toggling between on-off states.
    )annotations)	TYPE_CHECKINGAnyCallableClassVarDictListMappingOptionalTypeN)ButtonClickMenuItemClick)ButtonDropdownToggle)SVGIcon
TablerIcon   )CDN_DISTCallback   )Widget)Document)Model)Comm)JSLinkTargetLink)defaultprimarysuccesswarningdangerlight	List[str]BUTTON_TYPESsolidoutlineBUTTON_STYLESc                       e Zd ZU  ej        ded          Z ej        de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Z x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   objectsdocr'   z=
        A button style to switch between 'solid', 'outline'.labelN)namebutton_style"ClassVar[Mapping[str, str | None]]_renamer0   _source_transformszcss/button.csszClassVar[List[str]]_stylesheetsTc                    d|v sd|v r;|                     d| j                  g|                    d| j                  z   |d<   t	                                          |          S )Nr0   css_classes)popr0   getr6   super_process_param_changeselfparams	__class__s     4lib/python3.11/site-packages/panel/widgets/button.pyr:   z!_ButtonBase._process_param_change5   sk    V##}'>'>

>4+<==%

=$*:;;%<F=! ww,,V444    )__name__
__module____qualname__paramObjectSelectorr&   button_typer)   r0   r2   __annotations__r3   r   r4   _ButtonBase__abstractr:   __classcell__r>   s   @r?   r+   r+   #   s         &%&y, U   K
 (5' U@ A A AL <CTX2Y2YGYYYY>Ld=SSSSS,4)D)D)D(ELEEEEJ5 5 5 5 5 5 5 5 5r@   r+   c                       e Zd ZU  ej        dd          Z ej        dd          ZddddZded	<   d
Z	d fdZ
 fdZ x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-   1emz8
        Size of the icon as a string, e.g. 12px or 1em.icon)	icon_size_iconrO   r1   r2   TreturnNonec                |    t          | j        fi t          j        | _         t                      j        di | d S )N )dictr2   rL   r9   __init__r;   s     r?   rW   zIconMixin.__init__L   sB    DL>>I,=>>""6"""""r@   c                T   |                     d| j                  }|                    d          W|d         }|                                                    d          rt          ||          }nt          ||          }||d<   t                                          |          S )NrP   rO   z<svg)svgsize)	icon_namerZ   rQ   )	r7   rP   r8   lstrip
startswithr   r   r9   r:   )r<   r=   rP   rO   
icon_modelr>   s        r?   r:   zIconMixin._process_param_changeP   s    JJ{DN;;	::f)&>D{{}}''// H$I>>>

'$YGGG
(F7Oww,,V444r@   )rR   rS   )rA   rB   rC   rD   StringrO   rP   r2   rG   _IconMixin__abstractrW   r:   rI   rJ   s   @r?   rL   rL   =   s         5< +C D D DD U 1; < < <I FD3 3G     J# # # # # #	5 	5 	5 	5 	5 	5 	5 	5 	5r@   rL   c                  f     e Zd ZU dZdZded<   ddiZded<   	 	 dd fdZi dfddZi fddZ	 xZ
S ) _ClickButtonTbutton_clickClassVar[str]_eventr0   Nr1   r3   r-   r   rootOptional[Model]parentcommOptional[Comm]rR   r   c                    t                                          ||||          }|                     | j        |||           |S )Nmodelr-   ri   )r9   
_get_model_register_eventsre   r<   r-   rf   rh   ri   rm   r>   s         r?   rn   z_ClickButton._get_modelf   sF     ""3fd;;dkCdKKKr@    argsDict[str, Any]codestrr   c                >    ddl m}  || d| j        z   |i|          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:rt   rr   )linksr   re   )r<   rr   rt   r   s       r?   js_on_clickz_ClickButton.js_on_clickn   s9    " 	%$$$$$xHT[$8$#?dKKKKr@   	callbacksc                    t          |                                          D ]7\  }}|dk    r
d| j        z   }| j                            ||          }||||<   8t          | ||          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.
        clicksrw   Nrx   )listitemsre   r2   r8   r   )r<   rr   r{   kvvals         r?   
jscallbackz_ClickButton.jscallback   sy    ( **++ 	# 	#DAqH}}T[(,""1a((C"	!948888r@   NNN
r-   r   rf   rg   rh   rg   ri   rj   rR   r   )rr   rs   rt   ru   rR   r   )rr   rs   r{   ru   rR   r   )rA   rB   rC   _ClickButton__abstractre   rG   r3   rn   rz   r   rI   rJ   s   @r?   rb   rb   \   s         J*F**** 	>    
 6:?C       24 L L L L L( 13 9 9 9 9 9 9 9 9 9r@   rb   c                       e Zd ZU dZ ej        dd          Z ej        d          Zdddd	Z	d
e
d<   dddZd
e
d<   eZde
d<    fdZed) fd            Z	 	 d*d+ fd Zd,d$Zd-d(Z x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)rM   zG
        Toggles from False to True while the event is being processed.)r-   Nr.   )r}   r/   valuer1   r2   )zevent:button_clickr   _target_transformsClassVar[Type[Model]]_widget_typec                    |                     dd           } t                      j        di | |r|                     |           d S d S Non_clickrU   r7   r9   rW   r   r<   r=   click_handlerr>   s      r?   rW   zButton.__init__   ]    

:t44""6""" 	)MM-(((((	) 	)r@   rR   r%   c                2    t                      j        dgz   S )Nr   )r9   _linkable_params)r<   r>   s    r?   r   zButton._linkable_params   s    ww'7)33r@   Ftargetr   rt   Optional[Dict[str, str]]rr   Optional[Dict[str, Any]]bidirectionalboolry   ru   r   c                      f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                <    i | ]\  }}|d k    r
dj         z   n||S )r   rw   )re   ).0pr   r<   s      r?   
<dictcomp>z!Button.jslink.<locals>.<dictcomp>   s3    ZZZDAqg$+%%1aZZZr@   )r   r9   jslink)r<   r   rt   rr   r   ry   r>   s   `     r?   r   zButton.jslink   sM    F [ZZZEKKMMZZZuww~fdD-II5IIIr@   eventparam.parameterized.EventrS   c                Z    | j                             d           | xj        dz  c_        d S )Nr   r   )rD   triggerr}   )r<   r   s     r?   _process_eventzButton._process_event   s,    
7###qr@   callback+Callable[[param.parameterized.Event], None]param.parameterized.Watcherc                <    | j                             |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 button is clicked.
        r}   FonlychangedrD   watchr<   r   s     r?   r   zButton.on_click   s!    $ z(FFFr@   )rR   r%   )NNF)r   r   rt   r   rr   r   r   r   ry   ru   rR   r   )r   r   rR   rS   r   r   rR   r   )rA   rB   rC   __doc__rD   Integerr}   Eventr   r2   rG   r   	_BkButtonr   rW   propertyr   r   r   r   rI   rJ   s   @r?   r   r      s{         " U]1 +1 2 2 2F EK J K K KE $3 3G    
 #T> >     +4L3333) ) ) ) ) 4 4 4 4 4 X4 FJEJ$J $J $J $J $J $J $JL   G G G G G G G Gr@   r   c                  p    e Zd ZU dZ ej        dd          ZdddZded	<   d
Z	ded<   e
Zde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.rM   activer.   )r   r/   r1   r2   TzClassVar[bool]_supports_embedr   r   N   c                P    | | j         |j        d                  d         ddgd ddfS )Nidr   FTc                    | j         S N)r   )xs    r?   <lambda>z)Toggle._get_embed_state.<locals>.<lambda>#  s    !( r@   r   zcb_obj.active)_modelsref)r<   rf   valuesmax_optss       r?   _get_embed_statezToggle._get_embed_state!  s3    dl48D>215t}""Ho? 	?r@   )Nr   )rA   rB   rC   r   rD   Booleanr   r2   rG   r   	_BkToggler   r   rU   r@   r?   r   r   
  s         	 	 EM% .4 5 5 5E 73 3G     '+O*****3L3333? ? ? ? ? ?r@   r   c                       e Zd ZU dZ ej        dd          Z ej        g d          Z ej	        dd          Z
dZd	ed
<   ddddZded<   eZded<    fdZ	 	 d"d# fdZd Zd$d!Z x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.rM   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.menu_item_clickrd   re   r.   menu)r/   r   clickedr1   r2   r   r   c                    |                     dd           } t                      j        di | |r|                     |           d S d S r   r   r   s      r?   rW   zMenuButton.__init__H  r   r@   r-   r   rf   rg   rh   ri   rj   rR   r   c                    t                                          ||||          }|                     d|||           |S )Nrc   rl   )r9   rn   ro   rp   s         r?   rn   zMenuButton._get_modelN  sD     ""3fd;;nEsNNNr@   c                    t          |t                    r|j        }nt          |t                    r| j        }|| _        d S r   )
isinstancer   itemr   r/   r   )r<   r   r   s      r?   r   zMenuButton._process_eventV  sA    e]++ 	:DD{++ 	9Dr@   r   r   r   c                <    | j                             |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   s     r?   r   zMenuButton.on_click]  s!    $ z)GGGr@   r   r   r   )rA   rB   rC   r   rD   r_   r   r	   r   r   splitre   rG   r2   _BkDropdownr   rW   rn   r   r   rI   rJ   s   @r?   r   r   &  s=         " el4 .* + + +G EJr (> ? ? ?E EM% .: ; ; ;E .F----;BV`d2e2eGeeee*5L5555) ) ) ) ) 6:?C        H H H H H H H Hr@   r   )0r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   rD   bokeh.eventsr   r   bokeh.modelsr   r   r   r   r   r   bokeh.models.uir   r   io.resourcesr   ry   r   baser   bokeh.documentr   bokeh.modelr   pyviz_commsr   r   r   r&   rG   r)   r+   rL   rb   r   rU   r@   r?   <module>r      s     # " " " " "                     
  3 3 3 3 3 3 3 3          0 / / / / / / / # # # # # #             +''''''!!!!!!      ******** ZYY Y Y Y Y#Y/ / / / /5 5 5 5 5& 5 5 545 5 5 5 5 5 5 5>@9 @9 @9 @9 @9;	 @9 @9 @9FhG hG hG hG hG\ hG hG hGV? ? ? ? ?[) ? ? ?8IH IH IH IH IH IH IH IH IH IHr@   