
    ^hg                         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
JrJr  SSKJr  \ " S	 S
\\\5      5       r\ " S S\5      5       r\ " S S\5      5       r\ " S S\5      5       rg)    N   )
CoreWidget)	DOMWidget)ValueWidget)register)UnicodeCUnicodeBool)CByteMemoryViewc                      ^  \ rS rSrSr\" SS9R                  SS9r\S 5       r	\S 5       r
S	 r\S
 5       r\S 5       rU 4S jrSrU =r$ )_Media   a  Base class for Image, Audio and Video widgets.

The `value` of this widget accepts a byte string.  The byte string is the
raw data that you want the browser to display.

If you pass `"url"` to the `"format"` trait, `value` will be interpreted
as a URL as bytes encoded in UTF-8.
z)The media data as a memory view of bytes.helpTsyncc                 t    U R                  U5      nSU;  a  U R                  X5      nUb  XSS'   U " SSU0UD6$ )z
Create an :class:`Media` from a local file.

Parameters
----------
filename: str
    The location of a file to read into the value from disk.

**kwargs:
    The keyword arguments for `Media`

Returns an `Media` with the value set from the filename.
formatvalue )_load_file_value_guess_format)clstagfilenamekwargsr   r   s         Y/home/james-whalen/.local/lib/python3.13/site-packages/ipywidgets/widgets/widget_media.py
_from_file_Media._from_file   sM     $$X.6!&&s5F!#)x ))&))    c                 d    [        U[        5      (       a  UR                  S5      nU " SUSS.UD6$ )a!  
Create an :class:`Media` from a URL.

:code:`Media.from_url(url)` is equivalent to:

.. code-block: python

    med = Media(value=url, format='url')

But both unicode and bytes arguments are allowed for ``url``.

Parameters
----------
url: [str, bytes]
    The location of a URL to load.
zutf-8url)r   r   r   )
isinstancestrencode)r   r"   r   s      r   from_url_Media.from_url4   s4    $ c3**W%C5U5f55r    c                 2    U R                  U5      nX l        g)z
Convenience method for reading a file into `value`.

Parameters
----------
filename: str
    The location of a file to read into value from disk.
N)r   r   )selfr   r   s      r   set_value_from_file_Media.set_value_from_fileL   s     %%h/
r    c                     [        USS 5      b  UR                  5       $ [        US5       nUR                  5       sS S S 5        $ ! , (       d  f       g = f)Nreadrb)getattrr-   open)r   r   fs      r   r   _Media._load_file_valueY   s>    8VT*6==?"h%vvx &%%s   A
Ac                 
   [        USS 5      nU=(       d    Un [        R                  " U5      u  pEUR                  SR	                  U5      5      (       d  g U[        SR	                  U5      5      S  $ ! [         a     g f = f)Nnamez{}/)r/   	mimetypes
guess_type
startswithr   len	Exception)r   r   r   r4   mtype_s         r   r   _Media._guess_formata   s~     x.x	 ++D1HE##ELL$566U\\#./011 		s   =A5 A5 5
BBc                   > U R                   R                  n/ nSR                  U R                  S S R	                  5       5      nU R                  R
                  S:  a  US S S-   US   -   nUR                  U5        [        X]#  5        H?  nUS:X  a  M  [        [        X5      5      nUR                  SR                  XV5      5        MA     SR                  U5      nSR                  X#5      $ )	Nz
value={!r}(   z...r   z{}={!r}z, z{}({}))	__class____name__r   r   tobytesnbytesappendsuper
_repr_keysr$   r/   join)r)   r   
class_name	signature	sig_valuekeyr   r@   s          r   	_get_repr_Media._get_reprp   s     ^^,,
 	 ''

3B(?(?(AB	::r!!#2u,Yr]:I#.0Cg~*+EY--c9:	 1
 IIi(	z55r    )r   )rA   
__module____qualname____firstlineno____doc__r   r   r   classmethodr   r&   r*   r   r   rL   __static_attributes____classcell__r@   s   @r   r   r      s     !LMQQW[Q\E* *. 6 6.      6 6r    r   c                   
  ^  \ rS rSrSr\" S5      R                  SS9r\" S5      R                  SS9r\" SSS	9R                  SS9r	\
" S
S	9R                  SS9r\
" SS	9R                  SS9rU 4S jr\S 5       rS rSrU =r$ )Image   az  Displays an image as a widget.

The `value` of this widget accepts a byte string.  The byte string is the
raw image data that you want the browser to display.  You can explicitly
define the format of the byte string using the `format` trait (which
defaults to "png").

If you pass `"url"` to the `"format"` trait, `value` will be interpreted
as a URL as bytes encoded in UTF-8.
	ImageViewTr   
ImageModelpngzThe format of the image.r   zFWidth of the image in pixels. Use layout.width for styling the widget.zHHeight of the image in pixels. Use layout.height for styling the widget.c                 &   > [         TU ]  " U0 UD6  g N)rE   __init__)r)   argsr   r@   s      r   r^   Image.__init__   s    $)&)r    c                 *    U R                   " SU40 UD6$ )Nimager   r   r   r   s      r   	from_fileImage.from_file       ~~gx:6::r    c                 ,    U R                  [        5      $ r]   )rL   rW   r)   s    r   __repr__Image.__repr__       ~~e$$r    r   )rA   rN   rO   rP   rQ   r   r   
_view_name_model_namer   r	   widthheightr^   rR   re   rj   rS   rT   rU   s   @r   rW   rW      s    	 %))t)4J,'+++6K U!;<@@d@KF 4 558SdS^ 
 5 669ctcn * ; ;% %r    rW   c                   n   \ rS rSrSr\" S5      R                  SS9r\" S5      R                  SS9r\" SSS	9R                  SS9r	\
" S
S	9R                  SS9r\
" SS	9R                  SS9r\" SSS	9R                  SS9r\" SSS	9R                  SS9r\" SSS	9R                  SS9r\S 5       rS rSrg)Video   ay  Displays a video as a widget.

The `value` of this widget accepts a byte string.  The byte string is the
raw video data that you want the browser to display.  You can explicitly
define the format of the byte string using the `format` trait (which
defaults to "mp4").

If you pass `"url"` to the `"format"` trait, `value` will be interpreted
as a URL as bytes encoded in UTF-8.
	VideoViewTr   
VideoModelmp4zThe format of the video.r   zWidth of the video in pixels.zHeight of the video in pixels.z/When true, the video starts when it's displayedzBWhen true, the video will start from the beginning after finishingzSSpecifies that video controls should be displayed (such as a play/pause button etc)c                 *    U R                   " SU40 UD6$ )Nvideorc   rd   s      r   re   Video.from_file   rg   r    c                 ,    U R                  [        5      $ r]   )rL   rr   ri   s    r   rj   Video.__repr__   rl   r    r   N)rA   rN   rO   rP   rQ   r   r   rm   rn   r   r	   ro   rp   r
   autoplayloopcontrolsrR   re   rj   rS   r   r    r   rr   rr      s    	 %))t)4J,'+++6K U!;<@@d@KF9:>>D>IE;<@@d@KFDPQUU[_U`H_`ddjndoDDtuyy  @Dy  EH; ;%r    rr   c                   "   \ rS rSrSr\" S5      R                  SS9r\" S5      R                  SS9r\" SSS	9R                  SS9r	\
" SS
S	9R                  SS9r\
" SSS	9R                  SS9r\
" SSS	9R                  SS9r\S 5       rS rSrg)Audio   ay  Displays a audio as a widget.

The `value` of this widget accepts a byte string.  The byte string is the
raw audio data that you want the browser to display.  You can explicitly
define the format of the byte string using the `format` trait (which
defaults to "mp3").

If you pass `"url"` to the `"format"` trait, `value` will be interpreted
as a URL as bytes encoded in UTF-8.
	AudioViewTr   
AudioModelmp3zThe format of the audio.r   z/When true, the audio starts when it's displayedzBWhen true, the audio will start from the beginning after finishingzSSpecifies that audio controls should be displayed (such as a play/pause button etc)c                 *    U R                   " SU40 UD6$ )Naudiorc   rd   s      r   re   Audio.from_file   rg   r    c                 ,    U R                  [        5      $ r]   )rL   r   ri   s    r   rj   Audio.__repr__   rl   r    r   N)rA   rN   rO   rP   rQ   r   r   rm   rn   r   r
   r|   r}   r~   rR   re   rj   rS   r   r    r   r   r      s    	 %))t)4J,'+++6K U!;<@@d@KFDPQUU[_U`H_`ddjndoDDtuyy  @Dy  EH; ;%r    r   )r5   widget_corer   	domwidgetr   valuewidgetr   widgetr   	traitletsr   r	   r
   trait_typesr   r   rW   rr   r   r   r    r   <module>r      s     #   $  - - ( 
t6YZ t6 
t6n 
%F % 
%@ 
%F % 
%< 
%F % 
%r    