o
    Z2hU                     @  s   d Z ddlm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 erldd	lmZ dd
l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# ddl$m%Z% G dd deZ&G dd de	Z'd	S )z'|Document| and closely related objects.    )annotations)IOTYPE_CHECKINGIteratorList)BlockItemContainer)
WD_SECTION)WD_BREAK)SectionSections)ElementProxyEmuN)CT_BodyCT_Document)DocumentPart)Settings)Length)ParagraphStyle_TableStyle)Table)	Paragraphc                      s  e Zd ZdZdI fddZdJdKddZdd ZdLdMddZ		dNdOddZe	j
fdPd"d#ZdQdRd'd(Zed)d* Zed+d, ZdSd.d/ZedTd1d2ZedUd3d4ZdVd6d7ZedWd9d:ZedXd<d=Zed>d? ZedYdAdBZedZdDdEZed[dGdHZ  ZS )\DocumentzWordprocessingML (WML) document.

    Not intended to be constructed directly. Use :func:`docx.Document` to open or create
    a document.
    elementr   partr   c                   s&   t t| | || _|| _d | _d S N)superr   __init___element_part_Document__body)selfr   r   	__class__ ^/home/skpark/git/infrasmart_work/infrasmart/venv/lib/python3.10/site-packages/docx/document.pyr   "   s   
zDocument.__init__    textstrlevelintc                 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 %dTitlez
Heading %d)
ValueErroradd_paragraph)r    r'   r)   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_run	add_breakr	   PAGE)r    	paragraphr#   r#   r$   add_page_break5   s   zDocument.add_page_breakNr/   str | ParagraphStyle | Nonereturnr   c                 C  s   | j ||S )a  Return paragraph newly added to the end of the document.

        The paragraph is 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_paragraphimage_path_or_streamstr | IO[bytes]widthint | Length | Noneheightc                 C  s   |    }||||S )a  Return new picture shape added in its own paragraph at 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.   r1   add_picture)r    r9   r;   r=   runr#   r#   r$   r>   G   s   zDocument.add_picture
start_typer   c                 C  s   | j j }||_t|| jS )zReturn a |Section| object newly 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.
        )r   bodyadd_section_breakr@   r
   r   )r    r@   
new_sectPrr#   r#   r$   add_sectionZ   s   zDocument.add_sectionrowscolsstr | _TableStyle | Nonec                 C  s   | j ||| j}||_|S )zAdd a table having row and column counts of `rows` and `cols` respectively.

        `style` may be a table style object or a table style name. If `style` is |None|,
        the table inherits the default table style of the document.
        )r8   	add_table_block_widthr/   )r    rE   rF   r/   tabler#   r#   r$   rH   d   s   zDocument.add_tablec                 C     | j jS )zGA |CoreProperties| object providing Dublin Core properties of document.)r   core_propertiesr    r#   r#   r$   rL   n      zDocument.core_propertiesc                 C  rK   )zThe |InlineShapes| collection for 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_shapesrM   r#   r#   r$   rO   s   s   zDocument.inline_shapesIterator[Paragraph | Table]c                 C  s
   | j  S )zHGenerate each `Paragraph` or `Table` in this document in document order.)r8   iter_inner_contentrM   r#   r#   r$   rQ   }   s   
zDocument.iter_inner_contentList[Paragraph]c                 C  rK   )zThe |Paragraph| instances 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.
        )r8   
paragraphsrM   r#   r#   r$   rS      s   zDocument.paragraphsc                 C  s   | j S )z+The |DocumentPart| object of this document.)r   rM   r#   r#   r$   r      s   zDocument.partpath_or_streamc                 C  s   | j | dS )zSave this document to `path_or_stream`.

        `path_or_stream` can be either a path to a filesystem location (a string) or a
        file-like object.
        N)r   save)r    rT   r#   r#   r$   rU      s   zDocument.saver   c                 C  s   t | j| jS )zD|Sections| object providing access to each section in this document.)r   r   r   rM   r#   r#   r$   sections   s   zDocument.sectionsr   c                 C  rK   )zDA |Settings| object providing access to the document-level settings.)r   settingsrM   r#   r#   r$   rW      rN   zDocument.settingsc                 C  rK   )zBA |Styles| object providing access to the styles in this document.)r   stylesrM   r#   r#   r$   rX      rN   zDocument.stylesList[Table]c                 C  rK   )aP  All |Table| instances 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.
        )r8   tablesrM   r#   r#   r$   rZ      s   	zDocument.tablesr   c                 C  s    | j d }t|j|j |j S )zGA |Length| object specifying the space between margins in last section.)rV   r   
page_widthleft_marginright_margin)r    sectionr#   r#   r$   rI      s   
zDocument._block_width_Bodyc                 C  s    | j du rt| jj| | _ | j S )z>The |_Body| instance containing the content for this document.N)r   r`   r   rA   rM   r#   r#   r$   r8      s   
zDocument._body)r   r   r   r   )r%   r&   )r'   r(   r)   r*   )r%   N)r'   r(   r/   r6   r7   r   )NN)r9   r:   r;   r<   r=   r<   )r@   r   r   )rE   r*   rF   r*   r/   rG   )r7   rP   )r7   rR   )r7   r   )rT   r:   )r7   r   )r7   r   )r7   rY   )r7   r   )r7   r`   )__name__
__module____qualname____doc__r   r0   r5   r.   r>   r   NEW_PAGErD   rH   propertyrL   rO   rQ   rS   r   rU   rV   rW   rX   rZ   rI   r8   __classcell__r#   r#   r!   r$   r      sB    




	


r   c                      s*   e Zd ZdZd
 fddZdd	 Z  ZS )r`   zoProxy for `<w:body>` element in this document.

    It's primary role is a container for document content.
    body_elmr   parentt.ProvidesStoryPartc                   s   t t| || || _d S r   )r   r`   r   r8   )r    rh   ri   r!   r#   r$   r      s   
z_Body.__init__c                 C  s   | j   | S )zReturn this |_Body| instance after clearing it of all content.

        Section properties for the main document story, if present, are preserved.
        )r8   clear_contentrM   r#   r#   r$   rk      s   
z_Body.clear_content)rh   r   ri   rj   )ra   rb   rc   rd   r   rk   rg   r#   r#   r!   r$   r`      s    r`   )(rd   
__future__r   typingr   r   r   r   docx.blkcntnrr   docx.enum.sectionr   docx.enum.textr	   docx.sectionr
   r   docx.sharedr   r   
docx.typestypestdocx.oxml.documentr   r   docx.parts.documentr   docx.settingsr   r   docx.styles.styler   r   
docx.tabler   docx.text.paragraphr   r   r`   r#   r#   r#   r$   <module>   s(    %