o
    tfg                     @   s   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
 d
eeeZeG dd deZeG dd deZeG dd deZdS )    N   )
CoreWidget)	DOMWidget)ValueWidget)register)UnicodeCUnicodeBool)CByteMemoryViewc                       sj   e Zd ZdZeddjddZedd Zedd	 Z	d
d Z
edd Zedd Z fddZ  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                 K   s@   |  |}d|vr| ||}|du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   r   r   h/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/ipywidgets/widgets/widget_media.py
_from_file   s   
z_Media._from_filec                 K   s(   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   Nr   )
isinstancestrencode)r   r   r   r   r   r   from_url4   s   

z_Media.from_urlc                 C   s   |  |}|| _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   r   r   r   set_value_from_fileL   s   
	
z_Media.set_value_from_filec                 C   sN   t |dd d ur| S t|d}| W  d    S 1 s w   Y  d S )Nreadrb)getattrr"   open)r   r   fr   r   r   r   Y   s
   $z_Media._load_file_valuec                 C   sf   t |dd }|p	|}zt|\}}|d|sW d S |td|d  W S  ty2   Y d S w )Nnamez{}/)r$   	mimetypes
guess_type
startswithr   len	Exception)r   r   r   r'   mtype_r   r   r   r   a   s   z_Media._guess_formatc                    s   | j j}g }d| jd d  }| jjdkr$|d d d |d  }|| t||  D ]}|dkr7q0t	t
| |}|d|| q0d|}d||S )	Nz
value={!r}(   z...r   z{}={!r}z, z{}({}))	__class____name__r   r   tobytesnbytesappendsuperZ
_repr_keysr   r$   join)r    r   
class_name	signatureZ	sig_valuekeyr   r1   r   r   	_get_reprp   s   

z_Media._get_repr)r2   
__module____qualname____doc__r
   r   r   classmethodr   r   r!   r   r   r<   __classcell__r   r   r;   r   r      s    




r   c                       s   e Zd ZdZedjddZedjddZedddjddZe	d	djddZ
e	d
djddZ fddZedd Zdd Z  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.
    Z	ImageViewTr   Z
ImageModelZ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                    s   t  j|i | d S N)r6   __init__)r    argsr   r;   r   r   rD      s   zImage.__init__c                 K      | j d|fi |S )Nimager   r   r   r   r   r   r   	from_file      zImage.from_filec                 C   
   |  tS rC   )r<   rB   r    r   r   r   __repr__      
zImage.__repr__)r2   r=   r>   r?   r   r   
_view_name_model_namer   r   widthheightrD   r@   rJ   rN   rA   r   r   r;   r   rB      s    

rB   c                   @   s   e Zd ZdZedjddZedjddZedddjddZe	d	djddZ
e	d
djddZedddjddZedddjddZedddjddZedd Zd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.
    Z	VideoViewTr   Z
VideoModelZ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                 K   rF   )NZvideorH   rI   r   r   r   rJ      rK   zVideo.from_filec                 C   rL   rC   )r<   rT   rM   r   r   r   rN      rO   zVideo.__repr__N)r2   r=   r>   r?   r   r   rP   rQ   r   r   rR   rS   r	   autoplayloopcontrolsr@   rJ   rN   r   r   r   r   rT      s    

rT   c                   @   s   e Zd ZdZedjddZedjddZedddjddZe	dd	djddZ
e	dd
djddZe	dddjddZedd Zd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.
    Z	AudioViewTr   Z
AudioModelZ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                 K   rF   )NZaudiorH   rI   r   r   r   rJ      rK   zAudio.from_filec                 C   rL   rC   )r<   rX   rM   r   r   r   rN      rO   zAudio.__repr__N)r2   r=   r>   r?   r   r   rP   rQ   r   r	   rU   rV   rW   r@   rJ   rN   r   r   r   r   rX      s    

rX   )r(   Zwidget_corer   Z	domwidgetr   Zvaluewidgetr   Zwidgetr   Z	traitletsr   r   r	   Ztrait_typesr
   r   rB   rT   rX   r   r   r   r   <module>   s   w 