
    ge                     "   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
mZmZmZ ddlmZ dd	lmZ e G d
 deee                      Ze G d de                      Ze G d de                      Ze G d de                      ZdS )    N   )
CoreWidget)	DOMWidget)ValueWidget)register)UnicodeCUnicodeBytesBool)bytes_serialization)	text_typec                        e Zd ZdZ  ed          j        dddieZed             Z	ed             Z
d Zed	             Zed
             Z fdZ xZS )_Mediaa+  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 byte string.helpsyncTc                     |                      |          }d|vr|                     ||          }|||d<    | dd|i|S )aB  
        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.
        formatNvalue )_load_file_value_guess_format)clstagfilenamekwargsr   r   s         ?lib/python3.11/site-packages/ipywidgets/widgets/widget_media.py
_from_filez_Media._from_file   sb     $$X..6!!&&sH55F!#)x s)))&)))    c                 p    t          |t                    r|                    d          } | |d          S )aq  
        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   )
isinstancer   encode)r   r!   r   s      r   from_urlz_Media.from_url5   s<    $ c9%% 	&**W%%CsU++++r   c                 >    |                      |          }|| _        dS )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_filez_Media.set_value_from_fileM   s"     %%h//


r   c                     t          |dd           |                                S t          |d          5 }|                                cd d d            S # 1 swxY w Y   d S )Nreadrb)getattrr)   open)r   r   fs      r   r   z_Media._load_file_valueZ   s    8VT**6==??"h%%  vvxx                                   s   AAAc                 &   t          |dd           }|p|}	 t          j        |          \  }}|                    d                    |                    sd S |t          d                    |                    d          S # t          $ r Y d S w xY w)Nnamez{}/)r+   	mimetypes
guess_type
startswithr   len	Exception)r   r   r   r/   mtype_s         r   r   z_Media._guess_formatb   s     x..x	 +D11HE1##ELL$5$566 tU\\#..//0011 	 	 	44	s   ?B )B 
BBc                 $   | j         j        }g }t          | j                  }|                    dd          \  }}|d d         }t          |          dk    rd                    ||dd                   }|                    dd|           t          ||           	                                D ]@}|dk    r	t          t          | |                    }	|                    |d|	           Ad	                    |          }|d
|dS )N'r   d   z	{}'{}...'r   r   =z, ())	__class____name__reprr   splitr3   r   appendsuper
_repr_keysstrr+   join)r&   r   
class_name	signature	sig_valueprefixrestcontentkeyr   r>   s             r   	_get_reprz_Media._get_reprq   s$    ^,
 	$$	 sA..ss)w<<##**671S5>BBIGGGYY7888d##..00 	5 	5Cg~~c**++EUU34444IIi((	%::yyy11r   r   )r?   
__module____qualname____doc__r
   r   r   r   classmethodr   r$   r'   r   r   rN   __classcell__r>   s   @r   r   r      s          ?EE9:::>``D`L_``E* * [*. , , [,.       [    [2 2 2 2 2 2 2 2 2r   r   c                   |    e Zd ZdZ ed                              d          Z ed                              d          Z edd                              d          Z e	d	                              d          Z
 e	d
                              d          Z fdZed             Zd Z xZS )Imagea  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.
    	ImageViewTr   
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                 H     t          t          |           j        |i | d S N)rC   rV   __init__)r&   argsr   r>   s      r   r]   zImage.__init__   s+    #eT#T4V44444r   c                       | j         d|fi |S )Nimager   r   r   r   s      r   	from_filezImage.from_file       s~gx::6:::r   c                 6    |                      t                    S r\   )rN   rV   r&   s    r   __repr__zImage.__repr__       ~~e$$$r   )r?   rO   rP   rQ   r   r   
_view_name_model_namer   r	   widthheightr]   rR   rc   rg   rS   rT   s   @r   rV   rV      s,       	 	 %%))t)44J',''+++66K WU!;<<<@@d@KKFH 4 5 5 558SdS^^ 
X 5 6 6 669ctcnn 5 5 5 5 5 ; ; [;% % % % % % %r   rV   c                   2   e Zd ZdZ ed                              d          Z ed                              d          Z edd                              d          Z e	d	                              d          Z
 e	d
                              d          Z edd                              d          Z edd                              d          Z edd                              d          Zed             Zd ZdS )Videoa  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.
    	VideoViewTrX   
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                       | j         d|fi |S )Nvideora   rb   s      r   rc   zVideo.from_file   rd   r   c                 6    |                      t                    S r\   )rN   rn   rf   s    r   rg   zVideo.__repr__   rh   r   N)r?   rO   rP   rQ   r   r   ri   rj   r   r	   rk   rl   r   autoplayloopcontrolsrR   rc   rg   r   r   r   rn   rn      sw       	 	 %%))t)44J',''+++66K WU!;<<<@@d@KKFH9:::>>D>IIEX;<<<@@d@KKFtDPQQQUU[_U``H4_```ddjndooDtDtuuuyy  @Dy  E  EH; ; [;% % % % %r   rn   c                      e Zd ZdZ ed                              d          Z ed                              d          Z edd                              d          Z e	dd	                              d          Z
 e	dd
                              d          Z e	dd                              d          Zed             Zd ZdS )Audioa  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.
    	AudioViewTrX   
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                       | j         d|fi |S )Naudiora   rb   s      r   rc   zAudio.from_file   rd   r   c                 6    |                      t                    S r\   )rN   ry   rf   s    r   rg   zAudio.__repr__   rh   r   N)r?   rO   rP   rQ   r   r   ri   rj   r   r   ru   rv   rw   rR   rc   rg   r   r   r   ry   ry      s/       	 	 %%))t)44J',''+++66K WU!;<<<@@d@KKFtDPQQQUU[_U``H4_```ddjndooDtDtuuuyy  @Dy  E  EH; ; [;% % % % %r   ry   )r0   widget_corer   	domwidgetr   valuewidgetr   widgetr   	traitletsr   r	   r
   r   trait_typesr   utilr   r   rV   rn   ry   r   r   r   <module>r      s       # # # # # #             $ $ $ $ $ $       4 4 4 4 4 4 4 4 4 4 4 4 , , , , , ,       
u2 u2 u2 u2 u2YZ u2 u2 
u2p 
% % % % %F % % 
%@ 
% % % % %F % % 
%< 
% % % % %F % % 
% % %r   