
    hMhg                        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 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Bool)CByteMemoryViewc                        e Zd ZdZ ed                              d          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 memory view of bytes.helpTsyncc                     |                      |          }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         _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipywidgets/widgets/widget_media.py
_from_filez_Media._from_file   sb     $$X..6!!&&sH55F!#)x s)))&)))    c                 l    t          |t                    r|                    d          } | d|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   r   )
isinstancestrencode)r   r    r   s      r   from_urlz_Media.from_url4   sD    $ c3 	&**W%%Cs5U55f555r   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_fileL   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_valueY   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_formata   s     x..x	 +D11HE1##ELL$5$566 tU\\#..//0011 	 	 	44	s   ?B )B 
BBc                 8   | j         j        }g }d                    | j        d d                                                   }| j        j        dk    r|d d         dz   |d         z   }|                    |           t          ||                                           D ]O}|dk    r	t          t          | |                    }|                    d                    ||                     Pd                    |          }d                    ||          S )	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_reprz_Media._get_reprp   s    ^,
 	 ''
3B3(?(?(A(ABB	:r!!!#2#u,Yr]:I###d##..00 	; 	;Cg~~c**++EY--c599::::IIi((	z9555r   )r;   
__module____qualname____doc__r   r   r   classmethodr   r$   r'   r   r   rF   __classcell__r:   s   @r   r   r      s          O!LMMMQQW[Q\\E* * [*. 6 6 [6.       [    [6 6 6 6 6 6 6 6 6r   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.
    	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                      j        |i | d S N)r?   __init__)r&   argsr   r:   s      r   rT   zImage.__init__   s%    $)&)))))r   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 rS   )rF   rN   r&   s    r   __repr__zImage.__repr__       ~~e$$$r   )r;   rG   rH   rI   r   r   
_view_name_model_namer   r	   widthheightrT   rJ   rZ   r^   rK   rL   s   @r   rN   rN      s,       	 	 %%))t)44J',''+++66K WU!;<<<@@d@KKFH 4 5 5 558SdS^^ 
X 5 6 6 669ctcnn * * * * * ; ; [;% % % % % % %r   rN   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.
    	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                       | j         d|fi |S )NvideorX   rY   s      r   rZ   zVideo.from_file   r[   r   c                 6    |                      t                    S rS   )rF   re   r]   s    r   r^   zVideo.__repr__   r_   r   N)r;   rG   rH   rI   r   r   r`   ra   r   r	   rb   rc   r
   autoplayloopcontrolsrJ   rZ   r^   r   r   r   re   re      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   re   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.
    	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                       | j         d|fi |S )NaudiorX   rY   s      r   rZ   zAudio.from_file   r[   r   c                 6    |                      t                    S rS   )rF   rp   r]   s    r   r^   zAudio.__repr__   r_   r   N)r;   rG   rH   rI   r   r   r`   ra   r   r
   rl   rm   rn   rJ   rZ   r^   r   r   r   rp   rp      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   rp   )r0   widget_corer   	domwidgetr   valuewidgetr   widgetr   	traitletsr   r	   r
   trait_typesr   r   rN   re   rp   r   r   r   <module>r}      s{       # # # # # #             $ $ $ $ $ $       - - - - - - - - - - ( ( ( ( ( ( 
t6 t6 t6 t6 t6YZ t6 t6 
t6n 
% % % % %F % % 
%@ 
% % % % %F % % 
%< 
% % % % %F % % 
% % %r   