
    ^h                         S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SS	K
Jr  SS
KJrJr  SSKJr  SSKJr  SSKJr  SSKr\	 " S S\5      5       rg)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                      \ rS rSrSr\" S5      R                  SS9r\" S5      R                  SS9r\" S5      R                  SS9r	\" S5      R                  SS9r
\" \5      R                  SS9r\" \5      R                  SS9r\" SS	S
9R                  SS9r\" \" 5       SS9R                  SS9rSrS rSS jrS rS rS rS rS rS rS rSrg)Output   aU  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                 R    U    [        U0 UD6  SSS5        g! , (       d  f       g= f)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      Z/home/james-whalen/.local/lib/python3.13/site-packages/ipywidgets/widgets/widget_output.pyr   Output.clear_outputA   s     %*6* TTs   
&c                     ^ ^^^ UUUU 4S jnU$ )as  
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                 :   >^  [        T 5      UUUU U4S j5       nU$ )Nc                     > T(       a  TR                   " T0 TD6  T   T" U 0 UD6sS S S 5        $ ! , (       d  f       g = f)Nr   )argsr   
clear_argsclear_kwargsr   funcr   s     r   inner8Output.capture.<locals>.capture_decorator.<locals>.innerb   s3    %%zB\B00 TTs   /
=r   )r&   r'   r$   r%   r   r   s   ` r   capture_decorator)Output.capture.<locals>.capture_decoratora   s%    4[1 1 1
 L     )r   r   r$   r%   r)   s   ```` r   captureOutput.captureP   s    "	 	 ! r+   c                 
   U R                  5         [        5       nSnU(       a  [        USS5      b  UR                  nO;U R                  b.  [        U R                  SS5      b  U R                  R                  nU(       a  Sn[        US5      (       a  UR                  5       nO[        US5      (       a  UR                  nU(       a:  UR                  S5      (       a#  US   S   U l	        U =R                  S-  sl
        gggg)z3Called upon entering output widget context manager.Nkernel
get_parent_parent_headerheadermsg_idr   )_flushr   getattrr0   commhasattrr1   r2   getr4   _Output__counter)r   ipr0   parents       r   	__enter__Output.__enter__k   s    ]'"h-9YYFYY"wtyy(D'I'UYY%%FFv|,,**,!122..&**X..$X.x8!# /v r+   c                 f   SnUb  [        5       nU(       a  UnUR                  XU4SS9  OU R                  b  [        U R                  SS5      b  [        U R                  R                  SS5      by  U R                  R                  nUR                  UR                  SSR                  [        R                  " XU5      5      /[        UR                  5      UR                  S.5        U R                  5         U =R                  S	-  sl        U R                  S:X  a  SU l        U(       a  S
$ S$ )z2Called upon exiting output widget context manager.Nr   )	tb_offsetr0   send_responseerrorr   )	tracebackevalueenamer   T)r   showtracebackr7   r6   r0   rA   iopub_socketjoinrC   format_exceptionreprr#   __name__r5   r:   r4   )r   etyperD   tbr0   r;   s         r   __exit__Output.__exit__   s   B  %!4 B))'DIIx6BDII,,otDP))$$V%8%8%-#%779+E+EeUW+X#Y"Z#FKK0#nn& 	!>>QDK t'4'r+   c                 |    [         R                  R                  5         [         R                  R                  5         g)z Flush stdout and stderr buffers.N)sysstdoutflushstderr)r   s    r   r5   Output._flush   s"    



r+   c                 6    U =R                   SX!S.4-  sl         g)zAppend a stream output.stream)output_typenametextN)outputs)r   rZ   stream_names      r   _append_stream_outputOutput._append_stream_output   s    $kH
 	
r+   c                 $    U R                  USS9  g)z!Append text to the stdout stream.rR   r\   Nr]   r   rZ   s     r   append_stdoutOutput.append_stdout       ""4X">r+   c                 $    U R                  USS9  g)z!Append text to the stderr stream.rT   r`   Nra   rb   s     r   append_stderrOutput.append_stderr   re   r+   c                     [         R                  " 5       R                  R                  nU" U5      u  p4U =R                  SUUS.4-  sl        g)zAppend 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)rX   datametadataN)r   instancedisplay_formatterformatr[   )r   display_objectfmtrk   rl   s        r   append_display_dataOutput.append_display_data   sK     '');;BB^,-$
 	
r+   )r4   N)F)rK   
__module____qualname____firstlineno____doc__r   tag
_view_name_model_name_view_module_model_moduler
   _view_module_version_model_module_versionr4   r   r   r[   r:   r   r-   r=   rN   r5   r]   rc   rg   rr   __static_attributes__r,   r+   r   r   r      s   8 &***5J-(,,$,7K4599t9DL56:::EM"#EFJJPTJU#$FGKKQUKVRHIMMSWMXFtv,[\``fj`kGI+!6$,(8

??
r+   r   )rw   rQ   	functoolsr   	domwidgetr   trait_typesr   widgetr   _versionr
   	traitletsr   r   IPython.core.interactiveshellr   IPython.displayr   IPythonr   rC   r   r,   r+   r   <module>r      sI   
     #  9 # : (  	i
Y i
 
i
r+   