
    mjR'                     x    d dl Z d dlZd dlmZ d dlmZ ddlmZ d Zd Z	d Z
d	 Zd
 Zd ZddZ G d d      Zy)    N)Path)Callable   )to_pretty_htmlc                 &    t        | t              ryy)Npx )
isinstanceint)vs    A/DATA/.local/lib/python3.12/site-packages/trame_client/ui/core.pycss_unitr      s    !S    c                     | j                   }| j                  }| d|j                   d| j                   d}|j                   d| j
                   }||| j                  d| j                  S )N:/index.html?ui=&reconnect=auto_idsrcstyleiframe_base_urlserverporttemplate_namename_template_nameiframe_styleiframe_attrslayoutbase_urlr   r   elem_ids        r   iframe_url_builder_defaultr&          %%H]]F*Afkk]/&2F2F1GW  Qv4456G $$ 

	 r   c                     | j                   }| j                  }| d|j                   d| j                   d}|j                   d| j
                   }||| j                  d| j                  S )N/r   r   r   r   r   r"   s        r   iframe_url_builder_serverproxyr*   %   r'   r   c                 r   ddl m} t        j                  j	                  dd      }| j
                  }| d|j                   d}d| j                   d|j                   d	}| d
| }|j                   d| j                   }t        j                  j	                  d      }|rt        |      j                         rt        |      dz  |j                  z  }	| d|j                   d}d| j                   d|j                   d	}| d
| }|	j                         sxt        j                  |j                  t        |	j!                               d       |j"                  j%                         D ]"  \  }
}|	|
z  }t        j                  ||d       $ ||| j&                   |       d| j(                  S )Nr   )get_kernel_idTRAME_JUPYTER_ENDPOINTz/trame-jupyter-serverr)   /index.htmlui=z&server=z&wsProxy&reconnect=auto?r   TRAME_JUPYTER_WWWserversz	/servers/T)dirs_exist_ok)r   r   r   zdata-kernel-id)utils.jupyterr,   osenvirongetr   client_typer   r   r   r   existsshutilcopytree_wwwstrresolveserveitemsr    r!   )r#   r,   www_endpointr   url_base	url_queryr   r%   www_path
server_wwwsub_pathsrc_dirdst_dirs                r   $iframe_url_builder_jupyter_extensionrI   5   s   -::>>":<STL]]Fq!3!3 4K@Hf**+8FKK=@WXIJa	{
#CQv4456G zz~~12HDN))+(^i/&++=
"^9V[[ME&&&'x}<ST 	 
!I;'  "OOFKKZ-?-?-A)BRVW%+\\%7%7%9!'$x/E &:
 $$'/	
 

 r   c                     | j                   }t        j                  d    d|j                   d}d| j                   d}| d| }|j
                   d| j                   }||| j                  d| j                  S )	NJUPYTERHUB_SERVICE_PREFIXproxy/r.   r/   r   r0   r   r   )	r   r5   r6   r   r   r   r   r    r!   )r#   r   rB   rC   r   r%   s         r   iframe_url_builder_jupyter_hubrM   X   s    ]]F::12
36&++kR  f**+?;IJa	{
#CQv4456G $$ 

	 r   c                 @   t         j                  j                  d      }| j                  }t         j                  d    d| d|j                   d}d| j
                   d}| d| }|j                   d	| j                   }||| j                  d
| j                  S )NHOSTNAMErK   rL   r   r.   r/   r   r0   r   r   )
r5   r6   r7   r   r   r   r   r   r    r!   )r#   hostr   rB   rC   r   r%   s          r   #iframe_url_builder_jupyter_hub_hostrQ   i   s    ::>>*%D]]F**89:&a}T_`Hf**+?;IJa	{
#CQv4456G $$ 

	 r   c                    t        | t              r| S | dk(  rdt        j                  v rd} t        j                  j	                  d|       }t
        }|dk(  rt        }|S |dk(  rt        }|S |dk(  rt        }|S |dk(  rt        }|S )NdefaultrK   zjupyter-hubTRAME_IFRAME_BUILDERserverproxyzjupyter-extensionzjupyter-hub-host)
r
   r   r5   r6   r7   r&   r*   rI   rM   rQ   )r   builder_typebuilders      r   get_iframe_builderrX   y   s    $! y8BJJF::>>"8$?L(G}$0 N 
,	,6 N 
	&0 N 
+	+5Nr   c                   .   e Zd ZdZ	 	 	 	 	 ddZed        Zed        Zej                  d        Zed        Z	e	j                  d        Z	ed        Z
d	 Zed
        Zed        Zed        Zed        Zd Zd Zd Zd Zed        Zed        Zd Zy)AbstractLayoutas  
    A layout is responsible for a section if not all the ui of your application.
    It follow the same logic as any HTML container except that it also have to
    evaluate its content so it can be reflected on the client side.
    Usually to do that you will need call `flush_content` or by using it as a ContextManager.

    A layout needs to be bound to a server
    c                    || _         || _        || _        d| | _        d| j                   j                  | j                  <   d| t        |       d| t        |       d| _        i | _        || _        t        |      | _
        y )Ntrame__template_r	   zborder: none; width: z
; height: ;)_server_current_root_original_rootr   stater   r    r!   r   rX   _iframe_builder)	selfr^   
_root_elemr   widthheightr$   iframe_builderkwargss	            r   __init__zAbstractLayout.__init__   s     '( 0@244../3E78E?:K:V\U]^fgm^n]oopq'1.Ar   c                      | j                   dd S )z:Layout template name without the 'trame__template_' prefix   N)r   rc   s    r   r   zAbstractLayout.template_name   s     ""23''r   c                     | j                   S )z[Instance of iframe builder responsible for generating the iframe tag for mainly for Jupyter)rb   rl   s    r   rg   zAbstractLayout.iframe_builder   s     ###r   c                 $    t        |      | _        y)z
        Set iframe builder after construction.
        Method expect a name of built-in (default, serverproxy, jupyter-extension, jupyter-hub)
        or an actual function.
        N)rX   rb   )rc   
name_or_fns     r   rg   zAbstractLayout.iframe_builder   s      2*=r   c                     | j                   S )z
        Top level Vue component. Useful for providing / injecting into children components.
        Setting makes old root child of new root.
        )r_   rl   s    r   rootzAbstractLayout.root   s     !!!r   c                 x    |r8| j                   |k7  r(|xj                  | j                   gz  c_        || _         yyy)z[Swap the current root with a new one by adding the previous one as a child of that new one.N)r_   children)rc   new_roots     r   rq   zAbstractLayout.root   s=     **h6$"4"4!55!)D 78r   c                 .    | j                   j                  S )zT
        Compute corresponding layout String which represent the html part.
        )rq   htmlrl   s    r   rv   zAbstractLayout.html   s    
 yy~~r   c                 ,    t        | j                        S N)r   rv   rl   s    r   __repr__zAbstractLayout.__repr__   s    dii((r   c                     | j                   S )zReturn the server)r^   rl   s    r   r   zAbstractLayout.server   s     ||r   c                 .    | j                   j                  S )zReturn the server.controller)r^   
controllerrl   s    r   r|   zAbstractLayout.controller   s     ||&&&r   c                 .    | j                   j                  S )zReturn the server.state)r^   ra   rl   s    r   ra   zAbstractLayout.state   s     ||!!!r   c                     | j                   j                  s!| j                   j                  dddddd       | j                   j                  S )zStart the server as a background task (if not already started)
        and return the future that represent the status of that task.taskr   FT)	exec_moder   open_browsershow_connection_infodisable_loggingtimeout)r   runningstartreadyrl   s    r   r   zAbstractLayout.ready   sL     {{""KK "%* $   {{   r   c                 ^    | j                   | j                  j                  | j                  <   y)zPush new content to clientN)rv   r^   ra   r   rl   s    r   flush_contentzAbstractLayout.flush_content   s     26))4../r   c                 :    | j                   j                          | S rx   )r`   	__enter__rl   s    r   r   zAbstractLayout.__enter__  s    %%'r   c                 ^    | j                   j                  |||       | j                          y rx   )r`   __exit__r   )rc   exc_type	exc_valueexc_tracebacks       r   r   zAbstractLayout.__exit__	  s&    $$Xy-Hr   c                     | j                   j                  sy| j                  |       }dj                  d |j	                         D              }d| dS )Na+  
<div>
The server is not running.
Before displaying a trame layout you should await it to make sure it is ready.
You should run the following code before displaying a layout.
<pre style="padding: 5px; border: solid 1px rgb(224,224,224); background: rgb(245,245,245);">await layout.ready</pre>
</div> c              3   D   K   | ]  \  }}| d t        |       d  yw)z=""N)r=   ).0keyvalues      r   	<genexpr>z2AbstractLayout._jupyter_content.<locals>.<genexpr>  s*      "
6H
Use2c%j\#6Hs    z<iframe z
></iframe>)r   r   rg   joinr@   )rc   
attributesattributes_strs      r   _jupyter_contentzAbstractLayout._jupyter_content  s\    {{""
 ((.
 "
6@6F6F6H"
 
 .)44r   c                 <    ddl m}  || j                               S )zMConvert the UI into a ipywidget so it can be embedded in an ipywidget layout.r   )HTML)r   )ipywidgets.widgetsr   r   )rc   r   s     r   	ipywidgetzAbstractLayout.ipywidget"  s     	,$//122r   c                 X    | j                   j                  sy| j                  |       d   S )z!Return application url if startedzServer is not runningr   )r   r   rg   rl   s    r   urlzAbstractLayout.url)  s*     {{""*""4(//r   c                     ddl m}m} t        j                  j                  d      r || j                         d       y 	  || j                         y # t        $ r  || j                         d       Y y w xY w)Nr   )display_htmldisplayTRAME_IPYWIDGETS_DISABLET)raw)	IPython.displayr   r   r5   r6   r7   r   r   ImportError)rc   r   r   s      r   _ipython_display_z AbstractLayout._ipython_display_1  s_    9::>>45..0d;@' @T224$?@s   A !A98A9N)mainz100%600pxzhttp://localhostrS   )__name__
__module____qualname____doc__ri   propertyr   rg   setterrq   rv   ry   r   r|   ra   r   r   r   r   r   r   r   r    r   r   rZ   rZ      s7    # B* ( ( $ $ > > " " 
[[* *  )   ' ' " " ! !<5" 3 3 0 0	@r   rZ   )rS   )r5   r:   pathlibr   typingr   utils.formatterr   r   r&   r*   rI   rM   rQ   rX   rZ   r   r   r   <module>r      sF    	    ,   F" 4g@ g@r   