o
    W_I                     @   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mZ ddlmZmZ G dd	 d	eZG d
d deZdS )z&|Document| and closely related objects    )absolute_importdivisionprint_functionunicode_literals)BlockItemContainer)
WD_SECTION)WD_BREAK)SectionSections)ElementProxyEmuc                       s   e Zd ZdZdZ fddZd*ddZd	d
 Zd+ddZd,ddZ	e
jfddZd-ddZedd Zedd Zedd Zedd Zdd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Z  ZS ).DocumentzWordprocessingML (WML) document.

    Not intended to be constructed directly. Use :func:`docx.Document` to open or create
    a document.
    )_partZ__bodyc                    s    t t| | || _d | _d S N)superr   __init__r   _Document__body)selfelementpart	__class__ =D:\Projects\ConvertPro\env\Lib\site-packages\docx\document.pyr      s   
zDocument.__init__    c                 C   sB   d|  kr
dksn t d| |dkrdnd| }| ||S )a  Return a heading paragraph newly added to the end of the document.

        The heading paragraph will contain *text* and have its paragraph style
        determined by *level*. If *level* is 0, the style is set to `Title`. If *level*
        is 1 (or omitted), `Heading 1` is used. Otherwise the style is set to `Heading
        {level}`. Raises |ValueError| if *level* is outside the range 0-9.
        r   	   z"level must be in range 0-9, got %dZTitlez
Heading %d)
ValueErroradd_paragraph)r   textlevelstyler   r   r   add_heading   s   zDocument.add_headingc                 C   s   |   }| tj |S )z=Return newly |Paragraph| object containing only a page break.)r   add_runZ	add_breakr   ZPAGE)r   Z	paragraphr   r   r   add_page_break)   s   zDocument.add_page_breakNc                 C   s   | j ||S )a  
        Return a paragraph newly added to the end of the document, populated
        with *text* and having paragraph style *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.
        )_bodyr   )r   r   r!   r   r   r   r   /   s   	zDocument.add_paragraphc                 C   s   |    }||||S )a  
        Return a new picture shape added in its own paragraph at the end of
        the document. The picture contains the image at
        *image_path_or_stream*, scaled based on *width* and *height*. If
        neither width nor height is specified, the picture appears at its
        native size. If only one is specified, it is used to compute
        a scaling factor that is then applied to the unspecified dimension,
        preserving the aspect ratio of the image. The native size of the
        picture is calculated using the dots-per-inch (dpi) value specified
        in the image file, defaulting to 72 dpi if no value is specified, as
        is often the case.
        )r   r#   add_picture)r   Zimage_path_or_streamwidthheightrunr   r   r   r&   :   s   zDocument.add_picturec                 C   s   | j j }||_t|| jS )a  
        Return a |Section| object representing a new section added at the end
        of the document. The optional *start_type* argument must be a member
        of the :ref:`WdSectionStart` enumeration, and defaults to
        ``WD_SECTION.NEW_PAGE`` if not provided.
        )_elementbodyZadd_section_break
start_typer	   r   )r   r,   Z
new_sectPrr   r   r   add_sectionJ   s   zDocument.add_sectionc                 C   s   | j ||| j}||_|S )a%  
        Add a table having row and column counts of *rows* and *cols*
        respectively and table style of *style*. *style* may be a paragraph
        style object or a paragraph style name. If *style* is |None|, the
        table inherits the default table style of the document.
        )r%   	add_table_block_widthr!   )r   Zrowscolsr!   tabler   r   r   r.   U   s   zDocument.add_tablec                 C      | j jS )zx
        A |CoreProperties| object providing read/write access to the core
        properties of this document.
        )r   core_propertiesr   r   r   r   r3   `      zDocument.core_propertiesc                 C   r2   )a!  
        An |InlineShapes| object providing access to the inline shapes in
        this document. An inline shape is a graphical object, such as
        a picture, contained in a run of text and behaving like a character
        glyph, being flowed like other text in a paragraph.
        )r   inline_shapesr4   r   r   r   r6   h   s   zDocument.inline_shapesc                 C   r2   )z
        A list of |Paragraph| instances corresponding to the paragraphs in
        the document, in document order. Note that paragraphs within revision
        marks such as ``<w:ins>`` or ``<w:del>`` do not appear in this list.
        )r%   
paragraphsr4   r   r   r   r7   r   s   zDocument.paragraphsc                 C   s   | j S )z=
        The |DocumentPart| object of this document.
        )r   r4   r   r   r   r   {   s   zDocument.partc                 C   s   | j | dS )z
        Save this document to *path_or_stream*, which can be either a path to
        a filesystem location (a string) or a file-like object.
        N)r   save)r   Zpath_or_streamr   r   r   r8      s   zDocument.savec                 C   s   t | j| jS )zD|Sections| object providing access to each section in this document.)r
   r*   r   r4   r   r   r   sections   s   zDocument.sectionsc                 C   r2   )zp
        A |Settings| object providing access to the document-level settings
        for this document.
        )r   settingsr4   r   r   r   r:      r5   zDocument.settingsc                 C   r2   )zT
        A |Styles| object providing access to the styles in this document.
        )r   stylesr4   r   r   r   r;      s   zDocument.stylesc                 C   r2   )az  
        A list of |Table| instances corresponding to the tables in the
        document, in document order. Note that only tables appearing at the
        top level of the document appear in this list; a table nested inside
        a table cell does not appear. A table within revision marks such as
        ``<w:ins>`` or ``<w:del>`` will also not appear in the list.
        )r%   tablesr4   r   r   r   r<      s   	zDocument.tablesc                 C   s    | j d }t|j|j |j S )z
        Return a |Length| object specifying the width of available "writing"
        space between the margins of the last section of this document.
        )r9   r   Z
page_widthZleft_marginZright_margin)r   sectionr   r   r   r/      s   
zDocument._block_widthc                 C   s    | j du rt| jj| | _ | j S )zP
        The |_Body| instance containing the content for this document.
        N)r   _Bodyr*   r+   r4   r   r   r   r%      s   
zDocument._body)r   r   )r   N)NNr   )__name__
__module____qualname____doc__	__slots__r   r"   r$   r   r&   r   ZNEW_PAGEr-   r.   propertyr3   r6   r7   r   r8   r9   r:   r;   r<   r/   r%   __classcell__r   r   r   r   r      s>    





	








r   c                       s(   e Zd ZdZ fddZdd Z  ZS )r?   za
    Proxy for ``<w:body>`` element in this document, having primarily a
    container role.
    c                    s   t t| || || _d S r   )r   r?   r   r%   )r   Zbody_elmparentr   r   r   r      s   
z_Body.__init__c                 C   s   | j   | S )z
        Return this |_Body| instance after clearing it of all content.
        Section properties for the main document story, if present, are
        preserved.
        )r%   clear_contentr4   r   r   r   rH      s   
z_Body.clear_content)r@   rA   rB   rC   r   rH   rF   r   r   r   r   r?      s    r?   N)rC   Z
__future__r   r   r   r   Zdocx.blkcntnrr   Zdocx.enum.sectionr   Zdocx.enum.textr   Zdocx.sectionr	   r
   Zdocx.sharedr   r   r   r?   r   r   r   r   <module>   s    0