a
    Df                     @  s  U d Z ddlmZ ddl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mZ ddlZddl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"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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z<m=Z= ddl>m?Z?m@Z@mAZA ddlBmCZC ddlDmEZEmFZFmGZGmHZI ddlJmKZK ddlLmMZM ddlNmOZOmPZPmQZQmRZR ddlSmTZT ddlUmVZVmWZWmXZXmYZY ddlZm[Z[ ddl\m]Z]m^Z^ er@ddl_m`Z` ddlambZb dd lmcZd dd!lmeZe dd"lfmgZg dd#l-mhZh d$Zid%ejd&< d'Zkd%ejd(< G d)d* d*ejleVeXe1ZmG d+d, d,eMZnG d-d. d.emZoG d/d0 d0emZcdS )1zS
Templates allow multiple Panel objects to be embedded into custom HTML
documents.
    )annotationsN)partial)PathPurePath)
IOTYPE_CHECKINGAnyClassVarDictListLiteralOptionalTupleType)Document)	LayoutDOM)settings)JupyterCommManager   )_base_configconfigpanel_extension)init_doc)
add_to_doc)render_template)NotificationArea)
BUNDLE_DIRCDN_DIST
JS_VERSIONResourceComponent_envcomponent_resource_pathget_dist_pathloading_cssparse_templateresolve_custom_pathuse_cdn)save)curdoc_lockedstate)ColumnGridSpecListLike)CommManager)HTML	HoloViewsStrpanel)	ImageBase)ReactiveHTML)THEMESDefaultThemeDesignTheme)isurl)MimeRenderMixin
RenderableServableMixinViewable)Button)BooleanIndicatorLoadingSpinner)Model)BokehSessionContext)Template)Comm)Location)ResourcesTypezf<b>Running server:</b> <a target="_blank" href="https://localhost:{port}">https://localhost:{port}</a>str_server_infoz+/static/extensions/panel/images/favicon.icoFAVICON_URLc                      s  e Zd ZU eje edddZejeeddddZej	dddZ
ejeedddd	Zi Zd
ed< dZded< dZded< i i i i dZded< dZdVddd fddZejddddd ZddddZd dd!d"Zd#dd$d%Zd#d&d'dd(d)d*Zd+d,d-d.ZdWd/d0d1d2d3d4d5d6ZdXd7dd8d9ZdYd;d<d=d> fd?d@ZdZdEd1d2dFdFd2d#d#d1ddG
dHdIZd[d/d#d3dJdKdLdMZ d\d1dOd#d1dPdQ fdRdSZ!d]dTdUZ"  Z#S )^BaseTemplateTzo
        Configuration object declaring custom CSS and JS files to load
        specifically for this template.)defaultclass_constantdocFz/
        A Design applies themes to a template.)rK   rJ   is_instanceinstantiaterM   z
        Whether to add a Location component to this Template.
        Note if this is set to true, the Jinja2 template must
        either insert all available roots or explicitly embed
        the location root with : {{ embed(roots.location) }}.rJ   rM   )rK   rJ   rL   rN   rO   z.ClassVar[Dict[Type[Viewable], Dict[str, Any]]]	modifiersNz.ClassVar[Path | str | List[Path | str] | None]_css_js)cssjs
js_modulesZtarballz#ClassVar[Dict[str, Dict[str, str]]]
_resourcesstr | _TemplatezOptional[str | _Template])templatenb_templatec                   s   dd |  D }i | _i | _t jf i dd |  D  | jj| t|t	rj|| _
t|| _nd | _
|| _t|t	rt|| _n|p| j| _g | _d | _|  | _|   d S )Nc                 S  s    i | ]\}}|t jv r||qS  r   param.0pvr[   r[   `/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/template/base.py
<dictcomp>u   s   z)BaseTemplate.__init__.<locals>.<dictcomp>c                 S  s(   i | ] \}}|t jvs|d kr||qS namer\   r^   r[   r[   rb   rc   z   s   )items_render_items_render_variablessuper__init__r   r]   update
isinstancerF   _coder    Zfrom_stringrY   rZ   
_documents_server_build_layout_layout_setup_design)selfrY   rf   rZ   paramsZconfig_params	__class__r[   rb   rj   q   s*    



zBaseTemplate.__init__design)watchc                 C  s   | j | jd| _d S )N)theme)rw   ry   _designrs   r[   r[   rb   rr      s    zBaseTemplate._setup_designNonereturnc                 G  s   dS )zO
        Updates the render variables before the template is rendered.
        Nr[   )rs   argsr[   r[   rb   _update_vars   s    zBaseTemplate._update_varsr*   c                   sH   t t}tdtdd  fdd} j|d t| S )N Launch serverrd   c                   sP   j r$d _d_j   d _ n(d _jddd_ tjj jd_d S )Nr   r   zStop serverT)startshow)port)ro   re   objectstopZ_get_serverrG   formatr   )eventbuttonrs   Zserver_infor[   rb   launch   s    
z*BaseTemplate._build_layout.<locals>.launchZclicks)r0   reprr.   r=   r]   rx   r*   )rs   Zstr_reprr   r[   r   rb   rp      s    

zBaseTemplate._build_layoutrF   c                 C  s4   d}| dd | j D }t| j | | S )Nz
    c                 S  s4   g | ],\}\}}| d sd| d|d qS )_[z]    )
startswith__repr__)r_   re   objr   r[   r[   rb   
<listcomp>   s   

z)BaseTemplate.__repr__.<locals>.<listcomp>)joinrg   rf   type__name__)rs   Zspacerobjsr[   r[   rb   r      s
    
zBaseTemplate.__repr__r@   	List[str])re   modeltagsr~   c                 C  s   d S Nr[   )rs   re   r   r   r[   r[   rb   _apply_root   s    zBaseTemplate._apply_rootrA   session_contextc                 C  s(   |j }|tjv rtj|= | j| d S r   )Z	_documentr)   
_templatesrn   remove)rs   r   rM   r[   r[   rb   _server_destroy   s    
zBaseTemplate._server_destroyOptional[Document]zOptional[Comm]Optional[str]boolbool | Location)rM   commtitlenotebooklocationc                   s  |pt  }t|}| j| |tjvr2| tj|< |rH| jrH| || |tj	 || j
 |sn|jdkr||ptd}||_t }|j||dd}|j| jj |jd }	g g  }
}i i  }}t }| j D ]j\}\}}|j||dd | _ j fdd|D   _ jd }t tr j||< | jj|jvrN|j| jj |tD ]}|j|}t|dg D ]0}|d	sqtd
t j!"| }|||< qt|d u rqX||j|	< t|t#rX||j$v rX|j$||j$|	< qX| %| |  |j|< |
| |  |t& |t'||dO }||j
 qtj(|	 ||||ftj)|	< |
|_*||j+d d < ||_,| jj-||dd |.| ||j|< ||j
 |r| j/|_0n| j0|_0| 1  | j2d|id}||j3d< ||j3d< |j34| j5 |S )NzBokeh ApplicationPanel ApplicationF)
preprocessidc                   s   g | ]}| j vr|qS r[   )r   )r_   tagr   r[   rb   r          z*BaseTemplate._init_doc.<locals>.<listcomp>Z_stylesheetsz.cssZextra_)Zholdskip)isolatedrT   )extrasZtemplate_resourcessizing_modes)6r(   r   rn   appendr)   r   r   Z_add_locationZon_session_destroyedZ_destroy_sessionr   r   r*   Zget_rootZ_hooksrz   Z_apply_hooksrefsetrg   rf   re   r   rl   r   Zsizing_modeselectr<   Z_modelsgetgetattrendswithospathbasenamer/   Z_plotsr   r   r   Z_fake_rootsZ_viewsobjectschildrendocumentapplyZ_preprocessrZ   rY   r   resolve_resourcesZ_template_variablesrk   rh   )rs   rM   r   r   r   r   r   colZpreprocess_rootr   r   modelsZstylesheetsr   Ztracked_modelsre   r   r   ZmrefsubZsubmodelZ
stylesheetZsts_name	resourcesr[   r   rb   	_init_doc   s    


















zBaseTemplate._init_docz7Tuple[Dict[str, str], Dict[str, Dict[str, str]]] | Nonec                   s2  t j}|s$dtjv r$dd l}|jj}|s:tjjd d S zt	 j
d usLJ tt_W n tyf   Y n0 ddlm} t }tj  | j| dd |jd jd }t j|dd	}tjjt| j||t| j|t| j| fd
dd}	|	j|_|| tj dkr&|t!" j#d}
|
g ftj$|< t%| |S )N	holoviewsr   zDisplaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.)displayT)r   r   Zcomm_manager)Zcomm_idZplot_idre   c                   s      S r   )init)r   r   r[   rb   <lambda><  r   z0BaseTemplate._repr_mimebundle_.<locals>.<lambda>)Zon_msgZon_errorZ	on_stdoutZon_opendisable)Z
display_id)&r   _loadedsysmodulesr   	extensionr]   mainwarningZget_ipythonkernel_JupyterCommManagerr)   Z_comm_manager	ExceptionZIPython.displayr   r   Zget_server_commr   rootsr   r-   r   Zget_client_commr   Z_on_msgZ	_on_errorZ
_on_stdoutZclient_comm_idZadd_rootr   Zconsole_outputuuiduuid4hexZ_handlesr   )rs   includeexcludeZloadedZhvr   rM   r   managerZclient_commhandler[   r   rb   _repr_mimebundle_  sD    





zBaseTemplate._repr_mimebundle_autozbool | Literal['auto']z dict[str, dict[str, str]] | NonerE   )cdnr   r~   c                   s  t | }t j||dd }d }d }d }|j}| }	|dkrTt n|}t|d}
dt }|
 d	| |d
< |t	| j
jtt
jt
jt
jg  | j| D ]D\ t trֈ   q   fdd D 7  < q| j
j D ]4\}d|vr0tjr0tj d| }||< q| j
j D ]4\}d|vrrtjrrtj d| }||< qHtt	| j
jD ]:\}}d|vrtjrtj d| }||d| < q| j}t|t	s|r|gng }|D ]}|	}|jdd D ]Z}t|tsqn|jdu r. qbt|jt	rB|jn|jg}||v r|j }qtj !|}t"| | # r|
 d| d| | |d| < n<t$|r||d| < n"t%| |rt&| d||d| < q| j'}t|t	s|r|gng }|D ]}|	}t | jdd D ]Z}t|ts:q$n|j'du rL qt|j't	r`|j'n|j'g}||v r$|j }q$tj !|}t"| | # r|
d| d|  |d| < n<t$|r||d| < n"t%| |r
t&| d||d| < q
S )a>  
        Resolves the resources required for this template component.

        Arguments
        ---------
        cdn: bool | Literal['auto']
            Whether to load resources from CDN or local server. If set
            to 'auto' value will be automatically determine based on
            global settings.
        extras: dict[str, dict[str, str]] | None
            Additional resources to add to the bundle. Valid resource
            types include js, js_modules and css.

        Returns
        -------
        Dictionary containing JS and CSS resources.
        )r   r   rU   rV   rT   raw_cssr   )r   z?v=zcss/loading.cssZloadingc                   s   g | ]}  vr|qS r[   r[   )r_   rresZresource_typesrnamer[   rb   r   v  s   z2BaseTemplate.resolve_resources.<locals>.<listcomp>z///Zconfig_r   Nzbundled/Zbase_rR   rS   )(r   ri   r   r   lowerr&   r"   r   extendlistr   r   r#   Zloading_spinnerZloading_colorZloading_max_heightrz   rf   rl   dictrk   js_filesr)   rel_pathrV   	enumerate	css_filesrR   __mro__
issubclassrI   r   r   r   r   is_filer8   r%   r!   rS   )rs   r   r   clsr   rV   r   r   Zclsnamere   	dist_pathZversion_suffixrU   irT   Zbase_cssZ	tmpl_nameZsclsZtmpl_cssZcss_fileZbase_jsZtmpl_jsZjs_nameru   r   rb   r   K  s    




$

 
zBaseTemplate.resolve_resources     r   ./zstr | os.PathLike | IOint)
filenamer   embed
max_statesmax_opts
embed_jsonjson_prefix	save_path	load_pathr~   c                 C  s0   |rt dt| |||| j| j||||||	|
S )a  
        Saves Panel objects to file.

        Arguments
        ---------
        filename: string or file-like object
           Filename to save the plot to
        title: string
           Optional title for the plot
        resources: bokeh resources
           One of the valid bokeh.resources (e.g. CDN or INLINE)
        embed: bool
           Whether the state space should be embedded in the saved file.
        max_states: int
           The maximum number of states to embed
        max_opts: int
           The maximum number of states for a single widget
        embed_json: boolean (default=True)
           Whether to export the data to json files
        json_prefix: str (default='')
           Prefix for the auto-generated json directory
        save_path: str (default='./')
           The path to save json files to
        load_path: str (default=None)
           The path or URL the json files will be loaded from.
        z+Embedding is not yet supported on Template.)
ValueErrorr'   rY   rh   )rs   r   r   r   r   r   r   r   r  r  r  r[   r[   rb   r'     s     
zBaseTemplate.saver   )rM   r   r   r~   c                 C  s   | j |||dS )aO  
        Returns a servable bokeh Document with the panel attached

        Arguments
        ---------
        doc : bokeh.Document (optional)
          The Bokeh Document to attach the panel to as a root,
          defaults to bokeh.io.curdoc()
        title : str
          A string title to give the Document
        location : boolean or panel.io.location.Location
          Whether to create a Location component to observe and
          set the URL location.

        Returns
        -------
        doc : bokeh.Document
          The Bokeh document the panel was attached to
        )r   r   )r   )rs   rM   r   r   r[   r[   rb   
server_doc  s    zBaseTemplate.server_docr   zbool | 'Location'z'BaseTemplate')r   r   areatargetr~   c                   s(   t  jrtjrtdt ||||S )aZ  
        Serves the template and returns self to allow it to display
        itself in a notebook context.

        Arguments
        ---------
        title : str
          A string title to give the Document (if served as an app)
        location : boolean or panel.io.location.Location
          Whether to create a Location component to observe and
          set the URL location.
        area: str (deprecated)
          The area of a template to add the component too. Only has an
          effect if pn.config.template has been set.
        target: str
          Target area to write to. If a template has been configured
          on pn.config.template this refers to the target area in the
          template while in pyodide this refers to the ID of the DOM
          node to write to.

        Returns
        -------
        The template
        zCannot mark template as servable if a global template is defined. Either explicitly construct a template and serve it OR set `pn.config.template`, whether directly or via `pn.extension(template=...)`, not both.)r(   r   r   rY   RuntimeErrorri   servable)rs   r   r   r  r  ru   r[   rb   r	    s
    zBaseTemplate.servablec                 C  s*   g }| j  D ]\}}|||7 }q|S )a  
        Iterates over the Template 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)
        )rg   valuesr   )rs   selectorr   r   r   r[   r[   rb   r     s    zBaseTemplate.select)NN)NNNFT)NN)r   N)	NNFr   r   Fr   r   N)NNT)NTr   N)N)$r   
__module____qualname__r]   ClassSelectorr   r   r6   rw   Booleanr   r7   r5   ry   rQ   __annotations__rR   rS   rW   Z_BaseTemplate__abstractrj   dependsrr   r   rp   r   r   r   r   r   r   r'   r  r	  r   __classcell__r[   r[   ru   rb   rI   I   s^   

  
	   a 4  l    "*    %rI   c                   @  sL   e Zd ZU dZejddZejddZdZde	d< dgdgd	Z
d
e	d< dS )TemplateActionszo
    A component added to templates that allows triggering events such
    as opening and closing a modal.
    r   rJ   r   zClassVar[str]	_templatez
          document.getElementById('pn-Modal').style.display = 'block'
          window.dispatchEvent(new Event('resize'));
        z:document.getElementById('pn-Modal').style.display = 'none')
open_modalclose_modalz$ClassVar[Dict[str, List[str] | str]]_scriptsN)r   r  r  __doc__r]   Integerr  r  r  r  r  r[   r[   r[   rb   r  3  s   
r  c                      sH  e Zd ZU dZejedddeddddZej	dddd	Z
ejedd
dZejedddZejdddZejedddZejdddZejedddZejedddZejddZeje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Zejd dZejd!dZejd"dZ ejd#dZ!ejd$dZ"ej#d%g d&d'd(Z$ejd)dZ%ejd*dZ&ej'ddd+Z(eje) e)d,Z*dZ+d-e,d.< dZ- fd/d0Z.dQd1d2d3d4d5d6d7 fd8d9Z/d:d; fd<d=Z0d:d;d>d?Z1d@d:dAdBdCZ2dDdE fdFdGZ3d:d;dHdIZ4d:d;dJdKZ5e6dLd;dMdNZ7e6dOdP Z8  Z9S )RBasicTemplateaW  
    BasicTemplate provides a baseclass for templates with a basic
    organization including a header, sidebar and main area. Unlike the
    more generic Template class these default templates make it easy
    for a user to generate an application with a polished look and
    feel without having to write any Jinja2 template themselves.
       )widthheightTz4
        Visual indicator of application busy state.)rJ   rK   rL   Z
allow_NonerM   FzA
        Whether the sidebar (if present) is initially collapsed.)rJ   rL   rM   z>
        A list-like container which populates the header bar.)rK   rL   rM   z=
        A list-like container which populates the main area.r   z
        The maximum width of the main area. For example '800px' or '80%'.
        If the string is '' (default) no max width is set.rP   z;
        A list-like container which populates the sidebar.iJ  z<
        The width of the sidebar in pixels. Default is 330.z8
        A list-like container which populates the modalz
        The NotificationArea instance attached to this template.
        Automatically added if config.notifications is set, but may
        also be provided explicitly.z
        URI of logo to add to the header (if local file, logo is
        base64 encoded as URI). Default is '', i.e. not shown.)rM   zn
        URI of favicon to add to the document head (if local file, favicon is
        base64 encoded as URI).r   z{
        A title to show in the header. Also added to the document head
        meta settings and as the browser tab title.zy
        Name of the site. Will be shown in the header and link to the
        'site_url'. Default is '', i.e. not shown.r   z2
        Url of the site and logo. Default is '/'.Nz!
        Manifest to add to site.zz
        A meta description to add to the document head for search
        engine optimization. For example 'P.A. Nelson'.zZ
        Meta keywords to add to the document head for search engine
        optimization.zy
        A meta author to add to the the document head for search
        engine optimization. For example 'P.A. Nelson'.z
        A meta refresh rate to add to the document head. For example
        '30' will instruct the browser to refresh every 30
        seconds. Default is '', i.e. no automatic refresh.z.
        A meta viewport to add to the header.zl
        Specifies the base URL for all relative URLs in a
        page. Default is '', i.e. not the domain._self)Z_blankr  _parentZ_topzC
        Specifies the base Target for all relative URLs in a page.)rJ   r   rM   z3
        Optional header background color override.z-
        Optional header text color override.)rJ   readonly)rJ   rK   zClassVar[Path | None]r  c              	     s  | j jdd}z tt| j ttj}W n" t	j
jtfyP   t|}Y n0 d|vrft |d< n| |d | jjj|d< d|vrt |d< n| |d | jjj|d< d|vrt |d< n| |d | jjj|d< d|vrt |d< n| |d | jjj|d< d|v r6t|d trDt|d  |d< nttj |d< d|v rnt|d trnt|d |d< d	|vrtjrtjrtjnt |d	< t j f d
|i| t!dddd| _"d|v }|sd|v r| j"g f| j#d< |sd|v r| j$g f| j#d< |sd|v r8| jr8| jg f| j#d	< d| j%d	< tj&rrd|v sP|rrtj&rrtj&g f| j#d< d| j%d< | '  | jj(| j)dg | jj(| j)dg | jj(| j)dg | jj(| j)dg | jj*d | jj*d | jj*d | jj*d d S )Nzutf-8)encodingheaderr   sidebarmodalry   faviconnotificationsrY   r   )marginr  r  z{% block state_roots %}zembed(roots.js_area)Zjs_areazembed(roots.actions)actionszembed(roots.notifications)Tzembed(roots.browser_info)browser_infor   )+r  	read_textr    Zget_templaterF   relative_tor   __file__parentjinja2
exceptionsZTemplateNotFoundr  r$   r,   _get_paramsr]   r#  rK   r   r$  r%  rl   r4   r   ry   r   r'  r)   Zcurdocr   ri   rj   r.   Z_js_arearg   _actionsrh   r*  _update_busyrx   _update_render_itemstrigger)rs   rt   Ztmpl_stringrY   Zstate_rootsru   r[   rb   rj     s^     

 
zBasicTemplate.__init__r   zOptional['Comm']r   r   r   r   )rM   r   r   r   r   r~   c                   sl   | j | jj jkr| j n|}| jr,t| j t |||||}| jrR| jtj	|< | j
jjrh| j
jj|_|S r   )r   r]   rJ   busy_indicatorr)   Z	sync_busyri   r   r'  Z_notificationsrz   ry   bokeh_theme)rs   rM   r   r   r   r   r   ru   r[   rb   r     s    
zBasicTemplate._init_docr|   r}   c                   s  t  j|  | j| jd< | j| jd< | j| jd< | j| jd< | j| jd< | j| jd< | j| jd< | j	| jd< | j
| jd	< | j| jd
< | j| jd< | j| jd< tj| jrt| j}t|tstd| j d|||j}n| j}tj| jr6t| j}t|ts"td| j d|||j}n.tjdddkr^| jtkr^td }n| j}|| jd< || jd< | | j| jd< | j| jd< | j | jd< | j!| jd< | j"| jd< | j#j$| jd< | j%| jd< d S )NZ	app_titleZ	meta_nameZ
site_titlesite_urlmanifestmeta_descriptionmeta_keywordsmeta_authormeta_refreshmeta_viewportbase_urlbase_targetz'Could not determine file type of logo: .z*Could not determine file type of favicon: serverr  r   zimages/favicon.icoZapp_logoZapp_faviconZapp_favicon_typeheader_backgroundheader_colormain_max_widthsidebar_widthry   collapsed_sidebar)&ri   r   r   rh   siter8  r9  r:  r;  r<  r=  r>  r?  r@  r   r   isfilelogo_panelrl   r2   r  Z_b64_datar   r&  	_settingsr   rH   r   _get_favicon_typerC  rD  rE  rF  rz   ry   rG  )rs   r   imgrJ  r&  ru   r[   rb   r     sH    





zBasicTemplate._update_varsc                 C  s>   | j r| j g f| jd< nd| jv r*| jd= | j d u| jd< d S )Nr6  busy)r6  rg   rh   r{   r[   r[   rb   r3  %  s
    
zBasicTemplate._update_busyzparam.parameterized.Event)r   r~   c                 C  s  |j | u r|jdkr|  S |j | ju r.d}n4|j | ju r@d}n"|j | ju rRd}n|j | ju rbd}t|jt	rt|jnt	|j
 }|D ],}| dtt| }|| jv r| j|= qt|jt	r|jn|j
 }| jjjr|D ]*}||v rq|tD ]}| jjj|_qqi }	|D ]T}| dtt| }|jt|jrLd|	|< n
|j|	|< ||gf| j|< qdd	 | j
 D }
td
d |
D | jd< tdd |
D | jd< |	| jd< d S )Nr6  r   navr#  r%  -ZContentc                 S  s   g | ]\}}|qS r[   r[   )r_   r   r   r[   r[   rb   r   N  r   z6BasicTemplate._update_render_items.<locals>.<listcomp>c                 s  s   | ]}d |v V  qdS )rQ  Nr[   r_   tsr[   r[   rb   	<genexpr>O  r   z5BasicTemplate._update_render_items.<locals>.<genexpr>c                 s  s   | ]}d |v V  qdS )r#  Nr[   rS  r[   r[   rb   rU  P  r   Zroot_labels)r   re   r3  r   r$  r#  r%  rl   oldr   r
  rF   r   rg   newrz   ry   r7  r   r/   r   r   r   anyrh   )rs   r   r   rV  r   r   rW  oZhvpanelabelsr   r[   r[   rb   r4  ,  sB     



z"BasicTemplate._update_render_itemsrA   r   c                   s0   t  | | js,| jtjv r,tj| j d S r   )ri   r   rn   r6  r)   Z_indicatorsr   )rs   r   ru   r[   rb   r   S  s    zBasicTemplate._server_destroyc                 C  s   | j  jd7  _dS )z&
        Opens the modal area
        r   N)r2  r  r{   r[   r[   rb   r  X  s    zBasicTemplate.open_modalc                 C  s   | j  jd7  _dS )z'
        Closes the modal area
        r   N)r2  r  r{   r[   r[   rb   r  ^  s    zBasicTemplate.close_modalrF   c                 C  sZ   | sdS |  drdS |  dr$dS |  dr2dS |  dr@d	S |  d
rNdS tdd S )Nr   z.pngz	image/pngZjpgz	image/jpgZgifz	image/gifsvgz	image/svgZicozimage/x-iconzfavicon type not supported.)r   r  )r&  r[   r[   rb   rN  d  s    




zBasicTemplate._get_favicon_typec                 C  s   t | |r| S t | tr"g | } nt | ts2| g} dd | D } |tu rRt| dS |tu rtddd}t| D ]\}}|||d d f< qn|S | S )Nc                 S  s   g | ]}t |qS r[   )rK  )r_   itemr[   r[   rb   r     r   z-BasicTemplate._get_params.<locals>.<listcomp>)r      override)Zncolsmode)rl   tupler   r,   r+   r   )valuerK   Zgridindexr\  r[   r[   rb   r1  u  s    




zBasicTemplate._get_params)NNNFT):r   r  r  r  r]   r  r?   r>   r6  ZSelectorrG  r,   r#  r   StringrE  r$  r  rF  r%  r   r'  rJ  rH   r&  r   rH  r8  r9  r:  r;  r<  r=  r>  r?  ZObjectSelectorr@  rC  rD  r  r   r  r2  r  r  Z_BasicTemplate__abstractrj   r   r   r3  r4  r   r  r  staticmethodrN  r1  r  r[   r[   ru   rb   r  H  s`   
9  )'r  c                      sV   e Zd ZdZddddd fddZg fd	d
dddddZd	dddddZ  ZS )rB   aa  
    A Template is a high-level component to render multiple Panel
    objects into a single HTML document defined through a Jinja2
    template. The Template object is given a Jinja2 template and then
    allows populating this template by adding Panel objects, which are
    given unique names. These unique names may then be referenced in
    the template to insert the rendered Panel object at a specific
    location. For instance, given a Jinja2 template that defines roots
    A and B like this:

        <div> {{ embed(roots.A) }} </div>
        <div> {{ embed(roots.B) }} </div>

    We can then populate the template by adding panel 'A' and 'B' to
    the Template object:

        template.add_panel('A', pn.panel('A'))
        template.add_panel('B', pn.panel('B'))

    Once a template has been fully populated it can be rendered using
    the same API as other Panel objects. Note that all roots that have
    been declared using the {{ embed(roots.A) }} syntax in the Jinja2
    template must be defined when rendered.

    Since embedding complex CSS frameworks inside a notebook can have
    undesirable side-effects and a notebook does not afford the same
    amount of screen space a Template may given separate template
    and nb_template objects. This allows for different layouts when
    served as a standalone server and when used in the notebook.
    NrX   zstr | _Template | NonezOptional[Dict[str, Any]]rY   rZ   rf   c                   sL   t  jf |||d| |d u r&i n|}| D ]\}}| || q2d S )Nre  )ri   rj   rf   	add_panel)rs   rY   rZ   rf   rt   re   r\  ru   r[   rb   rj     s    zTemplate.__init__rF   r<   r   r|   )re   r1   r   r~   c                 C  s<   || j v rtd| t||f| j |< t| | jd _dS )aK  
        Add panels to the Template, which may then be referenced by
        the given name using the jinja2 embed macro.

        Arguments
        ---------
        name : str
          The name to refer to the panel by in the template
        panel : panel.Viewable
          A Panel component to embed in the template.
        zThe name %s has already been used for another panel. Ensure each panel has a unique name by which it can be referenced in the template.r   N)rg   r  rK  r   rq   r   )rs   re   r1   r   r[   r[   rb   rf    s    
zTemplate.add_panelr   )re   ra  r~   c                 C  s$   || j v rtd| || j |< dS )a5  
        Add parameters to the template, which may then be referenced
        by the given name in the Jinja2 template.

        Arguments
        ---------
        name : str
          The name to refer to the panel by in the template
        value : object
          Any valid Jinja2 variable type.
        zThe name %s has already been used for another variable. Ensure each variable has a unique name by which it can be referenced in the template.N)rh   r  )rs   re   ra  r[   r[   rb   add_variable  s
    
zTemplate.add_variable)NN)r   r  r  r  rj   rf  rg  r  r[   r[   ru   rb   rB     s      rB   )pr  
__future__r   r   r   r   	functoolsr   pathlibr   r   typingr   r   r   r	   r
   r   r   r   r   r   r/  r]   Zbokeh.document.documentr   Zbokeh.modelsr   Zbokeh.settingsr   rM  Zpyviz_commsr   r   r   r   r   Zio.documentr   Zio.modelr   Zio.notebookr   Zio.notificationsr   Zio.resourcesr   r   r   r   r    r!   r"   r#   r$   r%   r&   Zio.saver'   Zio.stater(   r)   Zlayoutr*   r+   r,   Zmodels.comm_managerr-   Zpaner.   r/   r0   r1   rK  Z
pane.imager2   Zreactiver3   Z
theme.baser4   r5   r6   r7   utilr8   Zviewabler9   r:   r;   r<   Zwidgetsr=   Zwidgets.indicatorsr>   r?   Zbokeh.modelr@   Zbokeh.server.contextsrA   rB   Z	_TemplaterC   Zio.locationrD   rE   rG   r  rH   ZParameterizedrI   r  r  r[   r[   r[   rb   <module>   sd   04
   m  F