
    e|!                    T   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZmZmZmZmZ ddlZddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZm Z  er#ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddlm'Z'  ed          Z( G d de          Z) G d de)          Z*d Z+ ee+           dS )z
Defines the Widget base class which provides bi-directional
communication between the rendered dashboard and the Widget
parameters.
    )annotationsN)TYPE_CHECKINGAnyCallableClassVarDictListMappingOptionalTupleTypeTypeVar)ImportedStyleSheetTooltip)HTML)register_reference_transform   )Margin)Row)Reactive)
LayoutableViewable)Document)Model)Comm)	ListPanelTc                  n    e Zd ZU dZ ej        dd          Z ej        d          Z ej	        dd	          Z
 ej	        dd	          Z ed
d          ZddiZded<   dZded<   dZded<   dZ fdZed4d            Zed5 fd            Zed             Zd6 fd"Z	 	 d7d8d+Z	 d9d:d3Z xZS );Widgetzn
    Widgets allow syncing changes in bokeh widget models with the
    parameters on the Widget instance.
    Fz'
       Whether the widget is disabled.)defaultdoc )r    N)r   N)r    bounds)   
   z
        Allows to create additional space around the component. May
        be specified as a two-tuple of the form (vertical, horizontal)
        or a four-tuple (top, right, bottom, left).nametitlez"ClassVar[Mapping[str, str | None]]_renamezClassVar[bool]_supports_embedzClassVar[Type[Model] | None]_widget_typeTc                    d|vrd|d<   d|v r|                     d          | _        d|v r|                     d          | _        nd | _         t                      j        di | d S )Nr&   r"   r)   _param_pane )popr)   r,   super__init__)selfparams	__class__s     2lib/python3.11/site-packages/panel/widgets/base.pyr0   zWidget.__init__B   s    F6N&&#)::.?#@#@D F""%zz-88D#D""6"""""    clsType[T]	parameterparam.Parameterreturnr   c           	     v    ddl m}  |||j        t          dd| i|it          j                   }|d         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.
        params: dict
          Keyword arguments to be passed to the widget constructor

        Returns
        -------
        Widget instance linked to the supplied parameter
        r   )Paramtype)widgetsdisplay_thresholdr   r-   )paramr<   r&   dictmathinf)r6   r8   r2   r<   layouts        r4   
from_paramzWidget.from_paramM   s^    " 	"!!!!!	0H0H#0H0H0HI#xi
 
 
 ayr5   
Tuple[str]c                    t          t                      j                  }d|v r|                    d           t	          |          S )Ndescription)listr/   _linked_propertiesremovetuple)r1   propsr3   s     r4   rJ   zWidget._linked_propertiese   s@    UWW/00E!!LL'''U||r5   c                $    | j         j        j        S N)r@   valuerxr1   s    r4   rQ   z	Widget.rxl   s    z""r5   r2   Dict[str, Any]c                   t                                          |          }| j        2d|v r.t          | j        dg           }d |D             |d         z   |d<   d|v r|d         }|                    di           }t          |t                    rMddlm}  |j	        di |}|
                    |          }t          t          |          d
dgd          |d<   nt          |t                    rd|_        |S )Nstylesheets__css__c                .    g | ]}t          |           S ))url)r   ).0sss     r4   
<listcomp>z0Widget._process_param_change.<locals>.<listcomp>t   s1     % % %/1"r***% % %r5   rH   renderer_optionsr   )Markdownmarkdown-itr-   rightz1:host { white-space: initial; max-width: 300px; }F)contentpositionrU   syncable)r^   r-   )r/   _process_param_changer*   getattrr.   
isinstancestrpane.markupr]   _get_parserrenderr   r   rb   )	r1   r2   cssrH   r\   r]   parserhtmlr3   s	           r4   rc   zWidget._process_param_changep   s<   ..v66(]f-D-D$+Y;;C% %58% % %}%%&F=! F"" /K%zz*<bAA+s++ 
-222222--TTCSTT}}[11(/ JJ!T U") ) )}%%
 K11 -',$r5   r!   r   rootOptional[Model]parentcommOptional[Comm]r   c                     | j         di |                     |          }|p|}||f| j        |j        d         <   |                     || j        |||           |S )Nidr-   )r*   _get_properties_modelsref_link_propsrJ   r1   r!   rm   ro   rp   models         r4   
_get_modelzWidget._get_model   sm     "!>>D$8$8$=$=>>}u(-vTXd^$ 7dDIIIr5      'Model'valuesOptional[List[Any]]max_optsintGTuple['Widget', 'Model', List[Any], Callable[['Model'], Any], str, str]c                    dS )a  
        Returns the bokeh model and a discrete set of value states
        for the widget.

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

        Returns
        -------
        widget: panel.widget.Widget
          The Panel widget instance to modify to effect state changes
        model: bokeh.model.Model
          The bokeh model to record the current value state on
        values: list
          A list of value states to explore.
        getter: callable
          A function that returns the state value given the model
        on_change: string
          The name of the widget property to attach a callback on
        js_getter: string
          JS snippet that returns the state value given the model
        Nr-   )r1   rm   r}   r   s       r4   _get_embed_statezWidget._get_embed_state   s      r5   )r6   r7   r8   r9   r:   r   )r:   rF   )r2   rS   r:   rS   NNN
r!   r   rm   rn   ro   rn   rp   rq   r:   r   )Nr{   )rm   r|   r}   r~   r   r   r:   r   )__name__
__module____qualname____doc__r@   BooleandisabledStringr&   Integerheightwidthr   marginr(   __annotations__r)   r*   _Widget__abstractr0   classmethodrE   propertyrJ   rQ   rc   rz   r   __classcell__r3   s   @r4   r   r   $   s         
 u}U 1* + + +H 5<###DU]4	:::FEM$y999EVG *7 8 8 8F
 4:72CGCCCC ',O++++ 26L5555J	# 	# 	# 	# 	#    [.      X # # X#     0 6:?C     RS        r5   r   c                       e Zd ZU dZeZded<   dZded<   dZ fdZ	d$dZ
	 d%d& fdZd%d' fdZ	 	 d(d)dZd*d!Zed+d#            Z xZS ),CompositeWidgetzT
    A baseclass for widgets which are made up of two or more other
    widgets
    zClassVar[Type[ListPanel]]_composite_typer-   zClassVar[Tuple[str]]rJ   Tc                8     t                      j        di | d t          j        D             } fd|D             }|                    d j                  	d|vrd|d<   |                    d          dvrD|                    d          r/|                    d          }|                    d          s||d<     j        di | _         j        j	         _	         j
                             j                             j        |                     d S )	Nc                    g | ]
}|d k    |S )r&   r-   )rY   ps     r4   r[   z,CompositeWidget.__init__.<locals>.<listcomp>   s    DDDqVr5   c                R    i | ]#}t          |          |t          |          $S rO   )rd   )rY   r   r1   s     r4   
<dictcomp>z,CompositeWidget.__init__.<locals>.<dictcomp>   s>     3 3 3!T1%%1 WT1%%111r5   r   sizing_modestretch_width)Nfixed	min_widthr-   )r/   r0   r   r@   getr   r.   r   
_compositeru   _internal_callbacksappendwatch_update_layout_params)r1   r2   layout_paramsrD   r   r3   s   `    r4   r0   zCompositeWidget.__init__   sB   ""6"""DDJ$4DDD3 3 3 3} 3 3 3::gtz**2}F7R7R$3F=!::m$$O;;

7@S@S;

7++I::k** 0&/{#.$.8888. ''JT7GG	
 	
 	
 	
 	
r5   eventsparam.parameterized.Eventr:   Nonec                L    d |D             } | j         j        j        di | d S )Nc                (    i | ]}|j         |j        S r-   )r&   new)rY   events     r4   r   z9CompositeWidget._update_layout_params.<locals>.<dictcomp>   s    ===U5:uy===r5   r-   )r   r@   update)r1   r   updatess      r4   r   z%CompositeWidget._update_layout_params   s9    ==f===$$//w/////r5   Nselector-Optional[type | Callable[['Viewable'], bool]]List[Viewable]c                    t                                          |          }| j        j        D ]}||                    |          z  }|S )a  
        Iterates over the Viewable and any potential children in the
        applying the Selector.

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

        Returns
        -------
        viewables: list(Viewable)
        )r/   selectr   objects)r1   r   r   objr3   s       r4   r   zCompositeWidget.select   sK    " ''..**?* 	, 	,Cszz(+++GGr5   rm   Model | Nonec                ~    | j                             |           t                                          |           d S rO   )r   _cleanupr/   )r1   rm   r3   s     r4   r   zCompositeWidget._cleanup   s7      &&&r5   r!   r   rn   ro   rp   rq   r   c                v    | j                             ||||          }|p|}||f| j        |j        d         <   |S )Nrs   )r   rz   ru   rv   rx   s         r4   rz   zCompositeWidget._get_model   sC     **3fdCC}u(-vTXd^$r5   objectr   boolc                    || j         j        v S rO   )r   r   )r1   r   s     r4   __contains__zCompositeWidget.__contains__   s    000r5   	List[str]c                    g S rO   r-   rR   s    r4   _synced_paramszCompositeWidget._synced_params   s    	r5   )r   r   r:   r   rO   )r   r   r:   r   )rm   r   r:   r   r   r   )r   r   r:   r   )r:   r   )r   r   r   r   r   r   r   rJ   _CompositeWidget__abstractr0   r   r   r   rz   r   r   r   r   r   s   @r4   r   r      s$         
 25O4444/11111J
 
 
 
 
"0 0 0 0
 IM      ,      
 6:?C    1 1 1 1    X    r5   r   c                H    t          | t                    r| j        j        n| S rO   )re   r   r@   rP   )r   s    r4   _widget_transformr      s    (f55>39??3>r5   ),r   
__future__r   rB   typingr   r   r   r   r   r	   r
   r   r   r   r   r@   bokeh.modelsr   r   bokeh.models.domr   param.parameterizedr   _paramr   layout.baser   reactiver   viewabler   r   bokeh.documentr   bokeh.modelr   pyviz_commsr   r   r   r   r   r   r-   r5   r4   <module>r      s/   
 # " " " " "                          
  4 4 4 4 4 4 4 4 ! ! ! ! ! ! < < < < < <                   + + + + + + + + ''''''!!!!!!      ''''''AK K K K KX K K K\I I I I If I I IX? ? ?  . / / / / /r5   