o
    4\                     @   sp   d Z ddlmZmZmZm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 G dd	 d	e	Zd
S )z;Styles object, container for all objects in the styles part    )absolute_importdivisionprint_functionunicode_literals)warn)ElementProxy)	BabelFish)LatentStyles)	BaseStyleStyleFactoryc                   @   sz   e Zd ZdZdZdd Zdd Zdd Zd	d
 ZdddZ	dd Z
dd Zdd Zedd Zdd Zdd Zdd ZdS )StyleszProvides access to the styles defined in a document.

    Accessed using the :attr:`.Document.styles` property. Supports ``len()``, iteration,
    and dictionary-style access by style name.
     c                 C   s,   t |}| jjD ]
}|j|kr dS q	dS )z6
        Enables `in` operator on style name.
        TF)r   ui2internal_element	style_lstZname_val)selfnameZinternal_namestyler   r   BD:\Projects\ConvertPro\env\Lib\site-packages\docx\styles\styles.py__contains__   s   

zStyles.__contains__c                 C   s\   | j t|}|durt|S | j |}|dur(d}t|tdd t|S td| )z
        Enables dictionary-style access by UI name. Lookup by style id is
        deprecated, triggers a warning, and will be removed in a near-future
        release.
        NzFstyle lookup by style_id is deprecated. Use style name as key instead.   )
stacklevelzno style with name '%s')	r   Zget_by_namer   r   r   	get_by_idr   UserWarningKeyError)r   keyZ	style_elmmsgr   r   r   __getitem__"   s   zStyles.__getitem__c                 C   s   dd | j jD S )Nc                 s   s    | ]}t |V  qd S N)r   ).0r   r   r   r   	<genexpr>8   s    z"Styles.__iter__.<locals>.<genexpr>)r   r   r   r   r   r   __iter__7   s   zStyles.__iter__c                 C   s   t | jjS r   )lenr   r   r!   r   r   r   __len__:   s   zStyles.__len__Fc                 C   s6   t |}|| v rtd| | j|||}t|S )z
        Return a newly added style object of *style_type* and identified
        by *name*. A builtin style can be defined by passing True for the
        optional *builtin* argument.
        z$document already contains style '%s')r   r   
ValueErrorr   Zadd_style_of_typer   )r   r   
style_typebuiltin
style_namer   r   r   r   	add_style=   s   
zStyles.add_stylec                 C   s    | j |}|du rdS t|S )z
        Return the default style for *style_type* or |None| if no default is
        defined for that type (not common).
        N)r   Zdefault_forr   )r   r&   r   r   r   r   defaultK   s   zStyles.defaultc                 C   s   |du r	|  |S | ||S )zReturn the style of *style_type* matching *style_id*.

        Returns the default for *style_type* if *style_id* is not found or is |None|, or
        if the style having *style_id* is not of *style_type*.
        N)r*   
_get_by_id)r   style_idr&   r   r   r   r   U   s   
zStyles.get_by_idc                 C   s.   |du rdS t |tr| ||S | ||S )a  
        Return the id of the style corresponding to *style_or_name*, or
        |None| if *style_or_name* is |None|. If *style_or_name* is not
        a style object, the style is looked up using *style_or_name* as
        a style name, raising |ValueError| if no style with that name is
        defined. Raises |ValueError| if the target style is not of
        *style_type*.
        N)
isinstancer
   _get_style_id_from_style_get_style_id_from_name)r   Zstyle_or_namer&   r   r   r   get_style_id_   s
   	
zStyles.get_style_idc                 C   s   t | j S )z
        A |LatentStyles| object providing access to the default behaviors for
        latent styles and the collection of |_LatentStyle| objects that
        define overrides of those defaults for a particular named latent
        style.
        )r	   r   Zget_or_add_latentStylesr!   r   r   r   latent_styleso   s   zStyles.latent_stylesc                 C   s0   | j |}|du s|j|kr| |S t|S )z
        Return the style of *style_type* matching *style_id*. Returns the
        default for *style_type* if *style_id* is not found or if the style
        having *style_id* is not of *style_type*.
        N)r   r   typer*   r   )r   r,   r&   r   r   r   r   r+   y   s   
zStyles._get_by_idc                 C   s   |  | | |S )a  
        Return the id of the style of *style_type* corresponding to
        *style_name*. Returns |None| if that style is the default style for
        *style_type*. Raises |ValueError| if the named style is not found in
        the document or does not match *style_type*.
        )r.   )r   r(   r&   r   r   r   r/      s   zStyles._get_style_id_from_namec                 C   s4   |j |krtd|j |f || |krdS |jS )z
        Return the id of *style*, or |None| if it is the default style of
        *style_type*. Raises |ValueError| if style is not of *style_type*.
        z'assigned style is type %s, need type %sN)r2   r%   r*   r,   )r   r   r&   r   r   r   r.      s   
zStyles._get_style_id_from_styleN)F)__name__
__module____qualname____doc__	__slots__r   r   r"   r$   r)   r*   r   r0   propertyr1   r+   r/   r.   r   r   r   r   r      s     




		r   N)r6   Z
__future__r   r   r   r   warningsr   Zdocx.sharedr   Zdocx.stylesr   Zdocx.styles.latentr	   Zdocx.styles.styler
   r   r   r   r   r   r   <module>   s   