
    hMh                         d 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 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Ze	 G d de                      ZdS )z^Output class.

Represents a widget that can be used to display output within the widget area.
    Nwraps   )	DOMWidget)
TypedTuple)register   )"__jupyter_widgets_output_version__)UnicodeDict)InteractiveShellclear_output)get_ipythonc                   V   e Zd ZdZ ed                              d          Z ed                              d          Z ed                              d          Z ed                              d          Z	 ee
                              d          Z ee
                              d          Z edd	                              d          Z e e            d
                              d          ZdZd ZddZd Zd Zd Zd Zd Zd Zd ZdS )Outputa  Widget used as a context manager to display output.

    This widget can capture and display stdout, stderr, and rich output.  To use
    it, create an instance of it and display it.

    You can then use the widget as a context manager: any output produced while in the
    context will be captured and displayed in the widget instead of the standard output
    area.

    You can also use the .capture() method to decorate a function or a method. Any output
    produced by the function will then go to the output widget. This is useful for
    debugging widget callbacks, for example.

    Example::
        import ipywidgets as widgets
        from IPython.display import display
        out = widgets.Output()
        display(out)

        print('prints to output area')

        with out:
            print('prints to output widget')

        @out.capture()
        def func():
            print('prints to output widget')
    
OutputViewT)syncOutputModelz@jupyter-widgets/output z(Parent message id of messages to capture)helpz-The output messages synced from the frontend.)traitr   r   c                 T    | 5  t          |i | ddd           dS # 1 swxY w Y   dS )z
        Clear the content of the output widget.

        Parameters
        ----------

        wait: bool
            If True, wait to clear the output until new output is
            available to replace it. Default: False
        Nr   )selfpargskwargss      `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipywidgets/widgets/widget_output.pyr   zOutput.clear_outputA   s      	+ 	+%*6***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   !!Fc                       fd}|S )a  
        Decorator to capture the stdout and stderr of a function.

        Parameters
        ----------

        clear_output: bool
            If True, clear the content of the output widget at every
            new function call. Default: False

        wait: bool
            If True, wait to clear the output until new output is
            available to replace it. This is only used if clear_output
            is also True.
            Default: False
        c                 F     t                      fd            }|S )Nc                  j    r j         i  5   | i |cd d d            S # 1 swxY w Y   d S )Nr   )argsr   
clear_argsclear_kwargsr   funcr   s     r   innerz8Output.capture.<locals>.capture_decorator.<locals>.innerb   s     C%D%zB\BBB 1 140001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   (,,r   )r$   r%   r"   r#   r   r   s   ` r   capture_decoratorz)Output.capture.<locals>.capture_decoratora   sH    4[[1 1 1 1 1 1 1 1 [1
 L     )r   r   r"   r#   r&   s   ```` r   capturezOutput.captureP   s6    "	 	 	 	 	 	 	 	 ! r'   c                    |                                   t                      }d}|rt          |dd          |j        }n)| j        "t          | j        dd          | j        j        }|rzd}t          |d          r|                                }nt          |d          r|j        }|r<|                    d          r)|d         d         | _	        | xj
        dz  c_
        dS dS dS dS )z3Called upon entering output widget context manager.Nkernel
get_parent_parent_headerheadermsg_idr   )_flushr   getattrr+   commhasattrr,   r-   getr/   _Output__counter)r   ipr+   parents       r   	__enter__zOutput.__enter__k   s   ]] 	&'"h--9YFFY"wty(D'I'I'UY%F 
	$Fv|,, /**,,!122 /. $&**X.. $$X.x8!#
	$ 
	$$ $ $ $r'   c                 "   d}|t                      }|r|}|                    |||fd           n| j        t          | j        dd          t          | j        j        dd          k| j        j        }|                    |j        dd                    t          j	        |||                    gt          |j                  |j        d           |                                  | xj        d	z  c_        | j        dk    rd| _        |rd
ndS )z2Called upon exiting output widget context manager.Nr   )	tb_offsetr+   send_responseerrorr   )	tracebackevalueenamer   T)r   showtracebackr2   r1   r+   r;   iopub_socketjoinr=   format_exceptionreprr!   __name__r0   r5   r/   )r   etyper>   tbr+   r6   s         r   __exit__zOutput.__exit__   s%   B   %!4 BBBB)'DIx66BDI,otDDP)$$V%8%-#%779+EeVUW+X+X#Y#Y"Z#FK00#n& &   	!>QDK 'tt4'r'   c                 ~    t           j                                         t           j                                         dS )z Flush stdout and stderr buffers.N)sysstdoutflushstderr)r   s    r   r0   zOutput._flush   s0    

r'   c                 0    | xj         d||dfz  c_         dS )zAppend a stream output.stream)output_typenametextN)outputs)r   rR   stream_names      r   _append_stream_outputzOutput._append_stream_output   s(    $k4HH
 	
r'   c                 4    |                      |d           dS )z!Append text to the stdout stream.rK   rT   NrU   r   rR   s     r   append_stdoutzOutput.append_stdout   !    ""4X">>>>>r'   c                 4    |                      |d           dS )z!Append text to the stderr stream.rM   rW   NrX   rY   s     r   append_stderrzOutput.append_stderr   r[   r'   c                     t          j                    j        j        } ||          \  }}| xj        d||dfz  c_        dS )a  Append a display object as an output.

        Parameters
        ----------
        display_object : IPython.core.display.DisplayObject
            The object to display (e.g., an instance of
            `IPython.display.Markdown` or `IPython.display.Image`).
        display_data)rP   datametadataN)r   instancedisplay_formatterformatrS   )r   display_objectfmtr`   ra   s        r   append_display_datazOutput.append_display_data   sW     '));B^,,h-$ 
 	
r'   N)F)rE   
__module____qualname____doc__r   tag
_view_name_model_name_view_module_model_moduler
   _view_module_version_model_module_versionr/   r   r   rS   r5   r   r)   r8   rH   r0   rU   rZ   r]   rg   r(   r'   r   r   r      s        8 &&***55J'-((,,$,77K745599t9DDLG566:::EEM"7#EFFJJPTJUU#G$FGGKKQUKVVWRHIIIMMSWMXXFjttvv,[\\\``fj`kkGI+ + +! ! ! !6$ $ $,( ( (8  

 
 
? ? ?? ? ?
 
 
 
 
r'   r   )rj   rJ   	functoolsr   	domwidgetr   trait_typesr   widgetr   _versionr
   	traitletsr   r   IPython.core.interactiveshellr   IPython.displayr   IPythonr   r=   r   r(   r'   r   <module>r{      s   
 


                   # # # # # #       9 9 9 9 9 9 # # # # # # # # : : : : : : ( ( ( ( ( (          	i
 i
 i
 i
 i
Y i
 i
 
i
 i
 i
r'   