ó
mÜJ]c           @` s®   d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ Z	 d d l
 Z
 d d l m Z d d l m Z d d l m Z d Z d
 e f d „  ƒ  YZ d „  Z d a d S(   u“   Encapsulate implicit state that is useful for Bokeh plotting APIs.

.. note::
    While ``State`` objects can also be manipulated explicitly, they are
    automatically configured when the functions :func:`~bokeh.io.output_file`,
    etc. from :ref:`bokeh.io` are used, so this is not necessary under
    typical usage.

Generating output for Bokeh plots requires coordinating several things:

:class:`~bokeh.document.Document`
    Groups together Bokeh models that may be shared between plots (e.g.,
    range or data source objects) into one common strucure.

:class:`~bokeh.resources.Resources`
    Control how JavaScript and CSS for the client library BokehJS are
    included and used in the generated output.

It is possible to handle the configuration of these things manually, and some
examples of doing this can be found in ``examples/models`` directory. When
developing sophisticated applications, it may be necessary or desirable to work
at this level. However, for general use this would quickly become burdensome.
This module provides a ``State`` class that encapsulates these objects and
ensures their proper configuration in many common usage scenarios.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   string_typesi   (   t   Document(   t	   Resourcesu   curstateu   Statet   Statec           B` s°   e  Z d  Z d „  Z e d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e	 j d „  ƒ Z	 d d	 d d
 „ Z d d „ Z d „  Z d „  Z d „  Z RS(   u8    Manage state related to controlling Bokeh output.

    c         C` s    d  |  _ i  |  _ |  j ƒ  d  S(   N(   t   Nonet   last_comms_handlet   uuid_to_servert   reset(   t   self(    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   __init__I   s    		c         C` s   |  j  S(   u`    A default :class:`~bokeh.document.Document` to use for all
        output operations.

        (   t	   _document(   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   documentP   s    c         C` s   | |  _  d  S(   N(   R   (   R   t   doc(    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyR   X   s    c         C` s   |  j  S(   uq   A dict with the default configuration for file output (READ ONLY)

        The dictionary value has the following form:

        .. code-block:: python

            {
                'filename'  : # filename to use when saving
                'resources' : # resources configuration
                'title'     : # a title for the HTML document
            }

        (   t   _file(   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   file\   s    c         C` s   |  j  S(   uN    Whether to generate notebook output on show operations. (READ ONLY)

        (   t	   _notebook(   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   notebookm   s    c         C` s   |  j  S(   u    Notebook type

        (   t   _notebook_type(   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   notebook_typet   s    c         C` s>   | d k s t | t ƒ r+ t d ƒ ‚ n  | j ƒ  |  _ d S(   u“    Notebook type, acceptable values are 'jupyter' as well as any names
        defined by external notebook hooks that have been installed.

        u   Notebook type must be a stringN(   R   t
   isinstanceR   t
   ValueErrort   lowerR   (   R   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyR   {   s    u
   Bokeh Plotu   cdnc         C` sW   i | d 6t  d | d | ƒ d 6| d 6|  _ t j j | ƒ rS t j d | ƒ n  d S(   u<   Configure output to a standalone HTML file.

        Calling ``output_file`` not clear the effects of any other calls to
        ``output_notebook``, etc. It adds an additional output destination
        (publishing to HTML files). Any other active output modes continue
        to be active.

        Args:
            filename (str) : a filename for saving the HTML document

            title (str, optional) : a title for the HTML document

            mode (str, optional) : how to include BokehJS (default: ``'cdn'``)

                One of: ``'inline'``, ``'cdn'``, ``'relative(-dev)'`` or
                ``'absolute(-dev)'``. See :class:`~bokeh.resources.Resources`
                for more details.

            root_dir (str, optional) : root dir to use for absolute resources
                (default: None)

                This value is ignored for other resource types, e.g. ``INLINE`` or ``CDN``.

        .. warning::
            The specified output file will be overwritten on every save, e.g.,
            every time ``show()`` or ``save()`` is called.

        u   filenamet   modet   root_diru	   resourcesu   titleu=   Session output file '%s' already exists, will be overwritten.N(   R   R   t   ost   patht   isfilet   logt   info(   R   t   filenamet   titleR   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   output_file‡   s    u   jupyterc         C` s   t  |  _ | |  _ d S(   uT   Generate output in notebook cells.

        Calling ``output_notebook`` not clear the effects of any other calls
        to ``output_file``, etc. It adds an additional output destination
        (publishing to notebook output cells). Any other active output modes
        continue to be active.

        Returns:
            None

        N(   t   TrueR   R   (   R   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   output_notebook­   s    	c         C` s   |  j  t ƒ  ƒ d S(   uü    Deactivate all currently active output modes and set ``curdoc()``
        to a fresh empty ``Document``.

        Subsequent calls to ``show()`` will not render until a new output mode
        is activated.

        Returns:
            None

        N(   t   _reset_with_docR   (   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyR   ¼   s    c         C` s   d |  _ t |  _ d |  _ d S(   uE    Reset output modes but DO NOT replace the default Document

        N(   R   R   t   FalseR   R   (   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   _reset_keeping_docË   s    		c         C` s   | |  _  |  j ƒ  d S(   uA    Reset output modes but DO replace the default Document

        N(   R   R(   (   R   R   (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyR&   Ó   s    	N(   t   __name__t
   __module__t   __doc__R   t   propertyR   t   setterR   R   R   R   R#   R%   R   R(   R&   (    (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyR   E   s   	&		c           C` s   t  d k r t ƒ  a  n  t  S(   uc    Return the current State object

    Returns:
      State : the current default State object

    N(   t   _STATER   R   (    (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   curstateÚ   s    (   u   curstateu   State(   R+   t
   __future__R    R   R   R   t   loggingt	   getLoggerR)   R   R   t   sixR   R   R   t	   resourcesR   t   __all__t   objectR   R/   R   R.   (    (    (    s-   lib/python2.7/site-packages/bokeh/io/state.pyt   <module>    s   " •	