U
    \	a                     @   s>  d Z ddlZddlZddlZddlmZ ddlZddlZddlZ	ddlm
Z
mZmZ eeZddddd	gZeje	 d
Zeje	 d
gZdZede ZdddddddddddddddddhZd1dd Zd2d!d"Zd#d Zejd3d%dZd&d' Z d(d) Z!d*d+ Z"d,d- Z#d.d/ Z$e  Z%da&g Z'd0d	 Z(e(  dS )4aD  
Core functions and attributes for the matplotlib style library:

``use``
    Select style sheet to override the current matplotlib settings.
``context``
    Context manager to use a style sheet temporarily.
``available``
    List available style sheets.
``library``
    A dictionary of style names and matplotlib settings.
    N)Path)_apirc_params_from_filercParamsDefaultusecontext	availablelibraryreload_libraryZstylelibZmplstylez([\S]+).%s$interactivebackendzbackend.qt4zwebagg.portzwebagg.addresszwebagg.port_retrieszwebagg.open_in_browserZbackend_fallbackZtoolbartimezonedatapathzfigure.max_open_warningzfigure.raise_windowzsavefig.directoryztk.window_focuszdocstring.hardcopyz
date.epochTc                 C   s<   i }| D ].}|t kr*|r6td| q| | ||< q|S )NzJStyle includes a parameter, '{0}', that is not related to style.  Ignoring)STYLE_BLACKLISTr   Zwarn_externalformat)dwarnokey r   9/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/style/core.py _remove_blacklisted_style_params-   s    r   c                 C   s   t jt| |d d S )Nr   )mplZrcParamsupdater   )r   r   r   r   r   _apply_style:   s    r   c                    s   ddd t | ttfs"t| dr*| g}n| } fdd|D }|D ]} t | ttfs`t|  qD| dkrt  ttdd W 5 Q R X qD| tkrtt|   qDzt	| dd	}t| W qD t
k
r } zt
d
| |W 5 d}~X Y qDX qDdS )a]  
    Use Matplotlib style settings from a style specification.

    The style name of 'default' is reserved for reverting back to
    the default style settings.

    .. note::

       This updates the `.rcParams` with the settings from the style.
       `.rcParams` not defined in the style are kept.

    Parameters
    ----------
    style : str, dict, Path or list
        A style specification. Valid options are:

        +------+-------------------------------------------------------------+
        | str  | The name of a style or a path/URL to a style file. For a    |
        |      | list of available style names, see `style.available`.       |
        +------+-------------------------------------------------------------+
        | dict | Dictionary with valid key/value pairs for                   |
        |      | `matplotlib.rcParams`.                                      |
        +------+-------------------------------------------------------------+
        | Path | A path-like object which is a path to a style file.         |
        +------+-------------------------------------------------------------+
        | list | A list of style specifiers (str, Path or dict) applied from |
        |      | first to last in the list.                                  |
        +------+-------------------------------------------------------------+

    defaultZclassic)Zmpl20Zmpl15keysc                 3   s(   | ] }t |tr ||n|V  qd S N)
isinstancestrget).0sZstyle_aliasr   r   	<genexpr>e   s   zuse.<locals>.<genexpr>Fr   Zuse_default_templatez|{!r} not found in the style library and input is not a valid URL or path; see `style.available` for list of available stylesN)r   r    r   hasattrr   r   Z'suppress_matplotlib_deprecation_warningr   r	   r   IOErrorr   )stylestylesrcerrr   r$   r   r   >   s8    


Fc              	   c   s2   t    |rt   t|  dV  W 5 Q R X dS )a	  
    Context manager for using style settings temporarily.

    Parameters
    ----------
    style : str, dict, Path or list
        A style specification. Valid options are:

        +------+-------------------------------------------------------------+
        | str  | The name of a style or a path/URL to a style file. For a    |
        |      | list of available style names, see `style.available`.       |
        +------+-------------------------------------------------------------+
        | dict | Dictionary with valid key/value pairs for                   |
        |      | `matplotlib.rcParams`.                                      |
        +------+-------------------------------------------------------------+
        | Path | A path-like object which is a path to a style file.         |
        +------+-------------------------------------------------------------+
        | list | A list of style specifiers (str, Path or dict) applied from |
        |      | first to last in the list.                                  |
        +------+-------------------------------------------------------------+

    after_reset : bool
        If True, apply style after resetting settings to their defaults;
        otherwise, apply style on top of the current settings.
    N)r   Z
rc_contextZ
rcdefaultsr   )r)   Zafter_resetr   r   r   r   |   s
    
c                  C   s   t t} | S )z+Load style library defined in this package.)read_style_directoryBASE_LIBRARY_PATH)r	   r   r   r   load_base_library   s    r/   c                  c   s8   t D ].} tj| } tj| rtj| r| V  qd S r   )USER_LIBRARY_PATHSospath
expanduserexistsisdir)stylelib_pathr   r   r   iter_user_libraries   s    r7   c                 C   s"   t  D ]}t|}t| | q| S )z0Update style library with user-defined rc files.)r7   r-   update_nested_dict)r	   r6   r*   r   r   r   update_user_library   s    
r9   c              
   C   sh   t  }t| dt D ]H}tjdd}t|dd||j< W 5 Q R X |D ]}t	d||j
 qLq|S )z3Return dictionary of styles defined in *style_dir*.z*.T)recordFr&   z	In %s: %s)dictr   globSTYLE_EXTENSIONwarningscatch_warningsr   stem_logwarningmessage)Z	style_dirr*   r2   Zwarnswr   r   r   r-      s     r-   c                 C   s(   |  D ]\}}| |i | q| S )a  
    Update nested dict (only level of nesting) with new values.

    Unlike `dict.update`, this assumes that the values of the parent dict are
    dicts (or dict-like), so you shouldn't replace the nested dict if it
    already exists. Instead you should update the sub-dict.
    )items
setdefaultr   )Z	main_dictZnew_dictnameZrc_dictr   r   r   r8      s    	r8   c                   C   s    t tatt tdd< dS )zReload the style library.N)r9   _base_libraryr	   sortedr   r   r   r   r   r   r
      s    )T)T)F))__doc__
contextlibloggingr1   pathlibr   rer>   Z
matplotlibr   r   r   r   	getLogger__name__rA   __all__r2   joinZget_data_pathr.   Zget_configdirr0   r=   compileZSTYLE_FILE_PATTERNr   r   r   r   contextmanagerr   r/   r7   r9   r-   r8   rH   r	   r   r
   r   r   r   r   <module>   s^   
            

>!