ó
/¾I]c           @   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 m Z d d l m Z d d	 l m Z e d
 e e e f d „  ƒ  Yƒ Z e d e f d „  ƒ  Yƒ Z e d e f d „  ƒ  Yƒ Z e d e f d „  ƒ  Yƒ Z d S(   iÿÿÿÿNi   (   t
   CoreWidget(   t	   DOMWidget(   t   ValueWidget(   t   register(   t   Unicodet   CUnicodet   Bytest   Bool(   t   bytes_serialization(   t	   text_typet   _Mediac           B   sz   e  Z d  Z e d d ƒ j d e e  Z e d „  ƒ Z	 e d „  ƒ Z
 d „  Z e d „  ƒ Z e d „  ƒ Z d	 „  Z RS(
   s+  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.
    t   helps    The media data as a byte string.t   syncc         K   sY   |  j  | ƒ } d | k rI |  j | | ƒ } | d k	 rI | | d <qI n  |  d | |  S(   sB  
        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.
        t   formatt   valueN(   t   _load_file_valuet   _guess_formatt   None(   t   clst   tagt   filenamet   kwargsR   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt
   _from_file   s    c         K   s4   t  | t ƒ r! | j d ƒ } n  |  d | d d ƒ S(   sq  
        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.
        s   utf-8R   R   t   url(   t
   isinstanceR	   t   encode(   R   R   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt   from_url5   s    c         C   s   |  j  | ƒ } | |  _ d S(   sÃ   
        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   (   t   selfR   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt   set_value_from_fileM   s    	c         C   sH   t  | d d  ƒ d  k	 r" | j ƒ  St | d ƒ  } | j ƒ  SWd  QXd  S(   Nt   readt   rb(   t   getattrR   R   t   open(   R   R   t   f(    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyR   Z   s    
c         C   sƒ   t  | d d  ƒ } | p | } yL t j | ƒ \ } } | j d j | ƒ ƒ sR d  S| t d j | ƒ ƒ SWn t k
 r~ d  SXd  S(   Nt   names   {}/(   R   R   t	   mimetypest
   guess_typet
   startswithR   t   lent	   Exception(   R   R   R   R"   t   mtypet   _(    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyR   b   s    c   
      C   s  |  j  j } g  } t |  j ƒ } | j d d ƒ \ } } | d  } t | ƒ d k rq d j | | d d !ƒ } n  | j d d | f ƒ x[ t | |  ƒ j	 ƒ  D]D } | d k r¶ qž n  t
 t |  | ƒ ƒ }	 | j d	 | |	 f ƒ qž Wd
 j | ƒ } d | | f S(   Nt   'i   iÿÿÿÿid   s	   {}'{}...'i    s   %s=%sR   s   %s=%rs   , s   %s(%s)(   t	   __class__t   __name__t   reprR   t   splitR&   R   t   appendt   supert
   _repr_keyst   strR   t   join(
   R   R   t
   class_namet	   signaturet	   sig_valuet   prefixt   restt   contentt   keyR   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt	   _get_reprq   s    
(   R,   t
   __module__t   __doc__R   R   t   TrueR   R   t   classmethodR   R   R   R   R   R;   (    (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyR
      s   		t   Imagec           B   s³   e  Z d  Z e d ƒ j d e ƒ Z e d ƒ j d e ƒ Z e d d d ƒj d e ƒ Z e	 d d ƒ j d e ƒ Z
 e	 d d ƒ j d e ƒ Z d	 „  Z e d
 „  ƒ Z d „  Z RS(   s–  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.
    t	   ImageViewR   t
   ImageModelt   pngR   s   The format of the image.sF   Width of the image in pixels. Use layout.width for styling the widget.sH   Height of the image in pixels. Use layout.height for styling the widget.c         O   s   t  t |  ƒ j | | Ž  d  S(   N(   R0   R@   t   __init__(   R   t   argsR   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRD   ž   s    c         K   s   |  j  d | |  S(   Nt   image(   R   (   R   R   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt	   from_file¡   s    c         C   s   |  j  t ƒ S(   N(   R;   R@   (   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt   __repr__¥   s    (   R,   R<   R=   R   R   R>   t
   _view_namet   _model_nameR   R   t   widtht   heightRD   R?   RG   RH   (    (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyR@   ˆ   s   			t   Videoc           B   s  e  Z d  Z e d ƒ j d e ƒ Z e d ƒ j d e ƒ Z e d d d ƒj d e ƒ Z e	 d d ƒ j d e ƒ Z
 e	 d d ƒ j d e ƒ Z e e d d	 ƒj d e ƒ Z e e d d
 ƒj d e ƒ Z e e d d ƒj d e ƒ Z e d „  ƒ Z d „  Z RS(   s•  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.
    t	   VideoViewR   t
   VideoModelt   mp4R   s   The format of the video.s   Width of the video in pixels.s   Height of the video in pixels.s/   When true, the video starts when it's displayedsB   When true, the video will start from the beginning after finishingsS   Specifies that video controls should be displayed (such as a play/pause button etc)c         K   s   |  j  d | |  S(   Nt   video(   R   (   R   R   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRG   À   s    c         C   s   |  j  t ƒ S(   N(   R;   RM   (   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRH   Ä   s    (   R,   R<   R=   R   R   R>   RI   RJ   R   R   RK   RL   R   t   autoplayt   loopt   controlsR?   RG   RH   (    (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRM   ©   s   t   Audioc           B   sÎ   e  Z d  Z e d ƒ j d e ƒ Z e d ƒ j d e ƒ Z e d d d ƒj d e ƒ Z e	 e d d ƒj d e ƒ Z
 e	 e d d ƒj d e ƒ Z e	 e d d	 ƒj d e ƒ Z e d
 „  ƒ Z d „  Z RS(   s•  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.
    t	   AudioViewR   t
   AudioModelt   mp3R   s   The format of the audio.s/   When true, the audio starts when it's displayedsB   When true, the audio will start from the beginning after finishingsS   Specifies that audio controls should be displayed (such as a play/pause button etc)c         K   s   |  j  d | |  S(   Nt   audio(   R   (   R   R   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRG   Ý   s    c         C   s   |  j  t ƒ S(   N(   R;   RU   (   R   (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRH   á   s    (   R,   R<   R=   R   R   R>   RI   RJ   R   R   RR   RS   RT   R?   RG   RH   (    (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyRU   È   s   (   R#   t   widget_coreR    t	   domwidgetR   t   valuewidgetR   t   widgetR   t	   traitletsR   R   R   R   t   trait_typesR   t   utilR	   R
   R@   RM   RU   (    (    (    s>   lib/python2.7/site-packages/ipywidgets/widgets/widget_media.pyt   <module>   s   "x 