
    zYHh@                     H   d Z ddlmZ ddl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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mZmZ d	dlmZmZ d ZddddddddZ G d de      Z G d de      Z G d de      Z G d d      Z ejB                   G d de             Z"y)z,Interactive figures in the IPython notebook.    )	b64encodeN)Comm)display
JavascriptHTML)is_interactiveGcf)_Backend
CloseEventNavigationToolbar2   )FigureCanvasWebAggCoreFigureManagerWebAggNavigationToolbar2WebAgg)TimerTornadoTimerAsyncioc                  v   t        j                         D  cg c]R  } dj                  | j                  j                  j                         xs d| j                   | j                        T }} t               s+|j                  dt        t         j                                dj                  |      S c c} w )z
    Return a string showing the figure and connection status for the backend.

    This is intended as a diagnostic tool, and not for general use.
    z{fig} - {socket}zFigure )figsocketzFigures pending show: 
)r
   get_all_fig_managersformatcanvasfigure	get_labelnumweb_socketsr   appendlenfigsjoin)managerresults     Z/var/www/html/planif/env/lib/python3.12/site-packages/matplotlib/backends/backend_nbagg.pyconnection_infor&      s     //1
 	 	!!&&002 ,gkk]+&& 	" 	(F  .s388}o>?99Vs   AB6z
fa fa-homezfa fa-arrow-leftzfa fa-arrow-rightzfa fa-square-ozfa fa-arrowszfa fa-floppy-o)homebackforwardzoom_to_rectmovedownloadNc                       e Zd Zej                  dz   D  cg c]  \  }}}}|t
        v r||t
        |   |f c}}}}}} Zyc c}}}}}} w )NavigationIPy))DownloadzDownload plotr,   r,   N)__name__
__module____qualname__r   	toolitems_FONT_AWESOME_CLASSES).0texttooltip_text
image_filename_of_methodr4   s   000000r%   r.   r.   5   sZ     (11MN9 9CT<^ "77 '
3^E 9I 9s   !Ar.   c                        e Zd ZexZZ fdZed        Zd Z	d Z
d Zed        Zed fd	       Zd Zd	 Zd
 Zd Z xZS )FigureManagerNbAggc                 4    d| _         t        | 	  ||       y )NF)_shownsuper__init__)selfr   r   	__class__s      r%   r?   zFigureManagerNbAgg.__init__C   s    %    c                      ||       | |      t               r j                          j                          fd}j                  d|      S )Nc                 R    j                         t        j                         y N)mpl_disconnectr
   destroy)eventr   cidr#   s    r%   rG   z6FigureManagerNbAgg.create_with_canvas.<locals>.destroyO   s    !!#&KK rB   close_event)r   show	draw_idlempl_connect)clscanvas_classr   r   rG   r   rI   r#   s        @@@r%   create_with_canvasz%FigureManagerNbAgg.create_with_canvasG   sR    f%fc"LLN	!   8rB   c                 P    t        t        t        j                                      y rE   )r   r   r;   get_javascriptr@   s    r%   
display_jszFigureManagerNbAgg.display_jsV   s     	
-<<>?@rB   c                 p   | j                   s!| j                          | j                          n| j                  j	                          d| _         t        | d      r%| j                  j                  | j                         t               s-ddl	m
} |j                  j                  | j                  d        y y )NT_cidgcfr   r	   )r=   rT   _create_commr   rL   hasattrrF   rV   r   matplotlib._pylab_helpersr
   r!   popr   )r@   r
   s     r%   rK   zFigureManagerNbAgg.show\   s|    {{OOKK!!#
 4#KK&&t||45HHLL4(  rB   c                 2    d| _         | j                          y)zJ
        A special method to re-show the figure in the notebook.

        FN)r=   rK   rS   s    r%   reshowzFigureManagerNbAgg.reshowm   s    
 		rB   c                 ,    t        | j                        S rE   )boolr   rS   s    r%   	connectedzFigureManagerNbAgg.connectedu   s    D$$%%rB   c                    |t        j                         }n|}t        |   |       |j	                  t        j                  t              j                  dz  j                  d             ||j                         S y )N)streamzweb_backend/js/nbagg_mpl.jszutf-8)encoding)ioStringIOr>   rR   writepathlibPath__file__parent	read_textgetvalue)rN   ra   outputrA   s      r%   rR   z!FigureManagerNbAgg.get_javascripty   sr    >[[]FFf-gll8,3356ii1	3 >??$$ rB   c                 >    t        |       }| j                  |       |S rE   )
CommSocketadd_web_socketr@   comms     r%   rW   zFigureManagerNbAgg._create_comm   s    $D!rB   c                     | j                  d       t        | j                        D ]  }|j                           | j	                          y )Nclose)_send_eventlistr   on_closeclearup_closedrp   s     r%   rG   zFigureManagerNbAgg.destroy   s?    !))* 	DMMO	rB   c                     | j                   D ch c]  }|j                         r| c}| _         t        | j                         dk(  r%t        d| j                        j                          yyc c}w )zClear up any closed Comms.r   rJ   N)r   is_openr    r   r   _process)r@   r   s     r%   rw   z!FigureManagerNbAgg.clearup_closed   sb    151A1A 1v%~~/ # 1 t A%}dkk2;;= &1s   A.c                 ~    | j                   D ch c]  }|j                  j                  |k7  r| c}| _         y c c}w rE   )r   rq   comm_id)r@   r|   r   s      r%   remove_commzFigureManagerNbAgg.remove_comm   s9    151A1A ?v%{{22g= # ? ?s   ":rE   )r0   r1   r2   r.   _toolbar2_class
ToolbarClsr?   classmethodrP   rT   rK   r\   propertyr_   rR   rW   rG   rw   r}   __classcell__)rA   s   @r%   r;   r;   @   sr    #00Oj&  A)" & & 
% 
%
>?rB   r;   c                       e Zd ZeZy)FigureCanvasNbAggN)r0   r1   r2   r;   manager_class rB   r%   r   r      s    &MrB   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	rn   aL  
    Manages the Comm connection between IPython and the browser (client).

    Comms are 2 way, with the CommSocket being able to publish a message
    via the send_json method, and handle a message with on_message. On the
    JS side figure.send_message and figure.ws.onmessage do the sending and
    receiving respectively.

    c                     d  _          _        t        t        j                                _        t        t        d j                  z               	 t        dd j                  i       _         j                  j                   j                          j                  d _         fd} j                  j                  |       y # t        $ r}t        d      |d }~ww xY w)Nz<div id=%r></div>
matplotlibid)datazTUnable to create an IPython notebook Comm instance. Are you in the IPython notebook?Fc                 b    d_         j                  | d   d          j                          y )NTcontentr|   )
_ext_closer}   rw   )close_messager#   r@   s    r%   	_on_closez&CommSocket.__init__.<locals>._on_close   s.    "DOi 8 CD""$rB   )supports_binaryr#   struuiduuid4r   r   r   rq   AttributeErrorRuntimeErroron_msg
on_messager   rv   )r@   r#   errr   s   ``  r%   r?   zCommSocket.__init__   s    #

%	 	(499456	5\tyy0ABDI
 			),,	%
 			9%  	5  + ,145	5s   C 	C'C""C'c                 L    | j                   xs | j                  j                   S rE   )r   rq   _closedrS   s    r%   ry   zCommSocket.is_open   s    OO8tyy'8'899rB   c                 z    | j                         r	 | j                  j                          y y # t        $ r Y y w xY wrE   )ry   rq   rs   KeyErrorrS   s    r%   rv   zCommSocket.on_close   s9     <<>		!   s   . 	::c                 d    | j                   j                  dt        j                  |      i       y )Nr   )rq   sendjsondumps)r@   r   s     r%   	send_jsonzCommSocket.send_json   s     		

7 345rB   c                     | j                   r!| j                  j                  ddi|g       y t        |      j	                  d      }d| }| j                  j                  d|i       y )Nblobz	image/png)buffersasciizdata:image/png;base64,r   )r   rq   r   r   decode)r@   r   r   data_uris       r%   send_binaryzCommSocket.send_binary   s]    IINNFK04&NA T?))'2D/v6HIINNFH-.rB   c                     t        j                  |d   d         }|d   dk(  r+| j                          | j                  j	                          y |d   dk(  r|d   | _        y | j                  j                  |       y )Nr   r   typeclosingr   value)r   loadsrv   r#   rw   r   handle_json)r@   messages     r%   r   zCommSocket.on_message   sm     **WY/786?i'MMOLL'')V_ 11#*7#3D LL$$W-rB   N)
r0   r1   r2   __doc__r?   ry   rv   r   r   r   r   rB   r%   rn   rn      s%    &2:6/.rB   rn   c                       e Zd ZeZeZy)_BackendNbAggN)r0   r1   r2   r   FigureCanvasr;   FigureManagerr   rB   r%   r   r      s    $L&MrB   r   )#r   base64r   rc   r   rf   r   ipykernel.commr   IPython.displayr   r   r   r   r   rY   r
   matplotlib.backend_basesr   r   r   backend_webagg_corer   r   r   r   r   r&   r4   r.   r;   r   rn   exportr   r   rB   r%   <module>r      s    2
  	     5 5 % ) M MK K & "$ 
 9, 9\?, \?~'. 'J. J.Z 
'H ' 'rB   