B
    _                 @   s`   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 G d	d
 d
eZdS )z 
Paragraph-related proxy types.
    )absolute_importdivisionprint_functionunicode_literals   )WD_STYLE_TYPE   )ParagraphFormat)Run)Parentedc                   s   e Zd ZdZ fddZdddZedd Zejd	d Zd
d Z	dddZ
edd Zedd Zedd Zejdd Zedd Zejdd Zdd Z  ZS )	Paragraphz2
    Proxy object wrapping ``<w:p>`` element.
    c                s    t t| | | | _| _d S )N)superr   __init___p_element)selfpparent)	__class__ E/var/www/html/venv/lib/python3.7/site-packages/docx/text/paragraph.pyr      s    zParagraph.__init__Nc             C   s,   | j  }t|| }|r||_|r(||_|S )a  
        Append a run to this paragraph containing *text* and having character
        style identified by style ID *style*. *text* can contain tab
        (``\t``) characters, which are converted to the appropriate XML form
        for a tab. *text* can also include newline (``\n``) or carriage
        return (``\r``) characters, each of which is converted to a line
        break.
        )r   Zadd_rr
   textstyle)r   r   r   rrunr   r   r   add_run   s    	

zParagraph.add_runc             C   s   | j jS )a  
        A member of the :ref:`WdParagraphAlignment` enumeration specifying
        the justification setting for this paragraph. A value of |None|
        indicates the paragraph has no directly-applied alignment value and
        will inherit its alignment value from its style hierarchy. Assigning
        |None| to this property removes any directly-applied alignment value.
        )r   	alignment)r   r   r   r   r   *   s    	zParagraph.alignmentc             C   s   || j _d S )N)r   r   )r   valuer   r   r   r   5   s    c             C   s   | j   | S )z
        Return this same paragraph after removing all its content.
        Paragraph-level formatting, such as style, is preserved.
        )r   clear_content)r   r   r   r   clear9   s    
zParagraph.clearc             C   s(   |   }|r|| |dk	r$||_|S )a  
        Return a newly created paragraph, inserted directly before this
        paragraph. If *text* is supplied, the new paragraph contains that
        text in a single run. If *style* is provided, that style is assigned
        to the new paragraph.
        N)_insert_paragraph_beforer   r   )r   r   r   Z	paragraphr   r   r   insert_paragraph_beforeA   s    
z!Paragraph.insert_paragraph_beforec             C   s
   t | jS )z
        The |ParagraphFormat| object providing access to the formatting
        properties for this paragraph, such as line spacing and indentation.
        )r	   r   )r   r   r   r   paragraph_formatO   s    zParagraph.paragraph_formatc                s    fdd j jD S )zl
        Sequence of |Run| instances corresponding to the <w:r> elements in
        this paragraph.
        c                s   g | ]}t | qS r   )r
   ).0r   )r   r   r   
<listcomp>]   s    z"Paragraph.runs.<locals>.<listcomp>)r   Zr_lst)r   r   )r   r   runsW   s    zParagraph.runsc             C   s   | j j}| j|tjS )a  
        Read/Write. |_ParagraphStyle| object representing the style assigned
        to this paragraph. If no explicit style is assigned to this
        paragraph, its value is the default paragraph style for the document.
        A paragraph style name can be assigned in lieu of a paragraph style
        object. Assigning |None| removes any applied style, making its
        effective value the default paragraph style for the document.
        )r   r   partZ	get_styler   	PARAGRAPH)r   style_idr   r   r   r   _   s    
zParagraph.stylec             C   s   | j |tj}|| j_d S )N)r&   Zget_style_idr   r'   r   r   )r   Zstyle_or_namer(   r   r   r   r   l   s    
c             C   s"   d}x| j D ]}||j7 }qW |S )ao  
        String formed by concatenating the text of each run in the paragraph.
        Tabs and line breaks in the XML are mapped to ``\t`` and ``\n``
        characters respectively.

        Assigning text to this property causes all existing paragraph content
        to be replaced with a single run containing the assigned text.
        A ``\t`` character in the text is mapped to a ``<w:tab/>`` element
        and each ``\n`` or ``\r`` character is mapped to a line break.
        Paragraph-level formatting, such as style, is preserved. All
        run-level formatting, such as bold or italic, is removed.
         )r%   r   )r   r   r   r   r   r   r   s   s    zParagraph.textc             C   s   |    | | d S )N)r   r   )r   r   r   r   r   r      s    c             C   s   | j  }t|| jS )zd
        Return a newly created paragraph, inserted directly before this
        paragraph.
        )r   Zadd_p_beforer   Z_parent)r   r   r   r   r   r       s    
z"Paragraph._insert_paragraph_before)NN)NN)__name__
__module____qualname____doc__r   r   propertyr   setterr   r!   r"   r%   r   r   r    __classcell__r   r   )r   r   r      s   

r   N)r-   
__future__r   r   r   r   Z
enum.styler   Zparfmtr	   r   r
   sharedr   r   r   r   r   r   <module>   s   