
    Xhg                         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y)    N   )
CoreWidget)	DOMWidget)ValueWidget)register)UnicodeCUnicodeBool)CByteMemoryViewc                        e Zd ZdZ ed      j                  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                 r    | j                  |      }d|vr| j                  ||      }|||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.
        formatvalue )_load_file_value_guess_format)clstagfilenamekwargsr   r   s         S/var/www/html/myenv/lib/python3.12/site-packages/ipywidgets/widgets/widget_media.py
_from_filez_Media._from_file   sQ     $$X.6!&&sH5F!#)x ))&))    c                 Z    t        |t              r|j                  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   s1    $ c3**W%C5U5f55r   c                 4    | j                  |      }|| _        y)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       |j                         S t        |d      5 }|j                         cd d d        S # 1 sw Y   y xY w)Nreadrb)getattrr)   open)r   r   fs      r   r   z_Media._load_file_valueY   sG    8VT*6==?"h%  vvx     s   AAc                     t        |dd       }|xs |}	 t        j                  |      \  }}|j                  dj	                  |            sy |t        dj	                  |            d  S # t        $ r Y y 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1HE1##ELL$56U\\#./011 		s   8A+ A+ +	A76A7c                    | j                   j                  }g }dj                  | j                  d d j	                               }| j                  j
                  dkD  r|d d dz   |d   z   }|j                  |       t        || #         D ]>  }|dk(  r	t        t        | |            }|j                  dj                  ||             @ dj                  |      }dj                  ||      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     ^^,,
 	 ''

3B(?(?(AB	::r!!#2u,Yr]:I#d.0 	;Cg~c*+EY--c59:		;
 IIi(	z955r   )r;   
__module____qualname____doc__r   r   r   classmethodr   r$   r'   r   r   rF   __classcell__r:   s   @r   r   r      s     !LMQQW[Q\E* *. 6 6.      6 6r   r   c                   0    e Zd ZdZ ed      j                  d      Z ed      j                  d      Z edd      j                  d      Z e	d	      j                  d      Z
 e	d
      j                  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        |   |i | y 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                 ,    | j                  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)4J,'+++6K U!;<@@d@KF 4 558SdS^ 
 5 669ctcn * ; ;%r   rN   c                      e Zd ZdZ ed      j                  d      Z ed      j                  d      Z edd      j                  d      Z e	d	      j                  d      Z
 e	d
      j                  d      Z edd      j                  d      Z edd      j                  d      Z edd      j                  d      Zed        Zd Zy)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                 ,    | j                  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      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   re   c                   V   e Zd ZdZ ed      j                  d      Z ed      j                  d      Z edd      j                  d      Z e	dd	      j                  d      Z
 e	dd
      j                  d      Z e	dd      j                  d      Zed        Zd Zy)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                 ,    | j                  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)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   rp   )r0   widget_corer   	domwidgetr   valuewidgetr   widgetr   	traitletsr   r	   r
   trait_typesr   r   rN   re   rp   r   r   r   <module>r}      s     #   $  - - ( 
t6YZ t6 
t6n 
%F % 
%@ 
%F % 
%< 
%F % 
%r   