o
    a]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 G dd de	ZG d	d
 d
eZG dd deZG dd deZG dd deZdS )z.The |Section| object and related proxy classes    )absolute_importdivisionprint_functionunicode_literals)BlockItemContainer)Sequence)WD_HEADER_FOOTER)lazypropertyc                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
SectionszSequence of |Section| objects corresponding to the sections in the document.

    Supports ``len()``, iteration, and indexed access.
    c                       t t|   || _|| _d S N)superr
   __init___document_elm_document_part)selfZdocument_elmdocument_part	__class__ <D:\Projects\ConvertPro\env\Lib\site-packages\docx\section.pyr         
zSections.__init__c                    s8   t |tr fdd jj| D S t jj|  jS )Nc                    s   g | ]}t | jqS r   )Sectionr   ).0sectPrr   r   r   
<listcomp>   s    
z(Sections.__getitem__.<locals>.<listcomp>)
isinstanceslicer   
sectPr_lstr   r   )r   keyr   r   r   __getitem__   s
   


zSections.__getitem__c                 c   s"    | j jD ]	}t|| jV  qd S r   )r   r   r   r   )r   r   r   r   r   __iter__    s   zSections.__iter__c                 C   s   t | jjS r   )lenr   r   r   r   r   r   __len__$   s   zSections.__len__)	__name__
__module____qualname____doc__r   r!   r"   r$   __classcell__r   r   r   r   r
      s    r
   c                       s  e Zd ZdZ fddZedd Zejdd Zedd Zej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ejdd Zedd Zej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ed"d# Zejd$d# Zed%d& Zejd'd& Zed(d) Zejd*d) Zed+d, Zejd-d, Zed.d/ Zejd0d/ Zed1d2 Zejd3d2 Z  ZS )4r   z}Document section, providing access to section and page setup settings.

    Also provides access to headers and footers.
    c                    r   r   )r   r   r   _sectPrr   )r   r   r   r   r   r   r   .   r   zSection.__init__c                 C      | j jS )z
        |Length| object representing the bottom margin for all pages in this
        section in English Metric Units.
        r*   bottom_marginr   r   r   r   r-   3      zSection.bottom_marginc                 C      || j _d S r   r,   r   valuer   r   r   r-   ;      c                 C   r+   )zTrue if this section displays a distinct first-page header and footer.

        Read/write. The definition of the first-page header and footer are accessed
        using :attr:`.first_page_header` and :attr:`.first_page_footer` respectively.
        r*   ZtitlePg_valr   r   r   r   "different_first_page_header_footer?      z*Section.different_first_page_header_footerc                 C   r/   r   r3   r0   r   r   r   r4   H   r2   c                 C      t | j| jtjS )z|_Footer| object defining footer content for even pages.

        The content of this footer definition is ignored unless the document setting
        :attr:`~.Settings.odd_and_even_pages_header_footer` is set True.
        )_Footerr*   r   r   	EVEN_PAGEr   r   r   r   even_page_footerL      zSection.even_page_footerc                 C   r6   )z|_Header| object defining header content for even pages.

        The content of this header definition is ignored unless the document setting
        :attr:`~.Settings.odd_and_even_pages_header_footer` is set True.
        )_Headerr*   r   r   r8   r   r   r   r   even_page_headerU   r:   zSection.even_page_headerc                 C   r6   )z|_Footer| object defining footer content for the first page of this section.

        The content of this footer definition is ignored unless the property
        :attr:`.different_first_page_header_footer` is set True.
        )r7   r*   r   r   
FIRST_PAGEr   r   r   r   first_page_footer^   r:   zSection.first_page_footerc                 C   r6   )z|_Header| object defining header content for the first page of this section.

        The content of this header definition is ignored unless the property
        :attr:`.different_first_page_header_footer` is set True.
        )r;   r*   r   r   r=   r   r   r   r   first_page_headerg   r:   zSection.first_page_headerc                 C   r6   )z|_Footer| object representing default page footer for this section.

        The default footer is used for odd-numbered pages when separate odd/even footers
        are enabled. It is used for both odd and even-numbered pages otherwise.
        )r7   r*   r   r   PRIMARYr   r   r   r   footerp   r:   zSection.footerc                 C   r+   )z
        |Length| object representing the distance from the bottom edge of the
        page to the bottom edge of the footer. |None| if no setting is present
        in the XML.
        r*   rA   r   r   r   r   footer_distancey   r5   zSection.footer_distancec                 C   r/   r   rB   r0   r   r   r   rC      r2   c                 C   r+   )z
        |Length| object representing the page gutter size in English Metric
        Units for all pages in this section. The page gutter is extra spacing
        added to the *inner* margin to ensure even margins after page
        binding.
        r*   gutterr   r   r   r   rE         zSection.gutterc                 C   r/   r   rD   r0   r   r   r   rE      r2   c                 C   r6   )z|_Header| object representing default page header for this section.

        The default header is used for odd-numbered pages when separate odd/even headers
        are enabled. It is used for both odd and even-numbered pages otherwise.
        )r;   r*   r   r   r@   r   r   r   r   header   r:   zSection.headerc                 C   r+   )z
        |Length| object representing the distance from the top edge of the
        page to the top edge of the header. |None| if no setting is present
        in the XML.
        r*   rG   r   r   r   r   header_distance   r5   zSection.header_distancec                 C   r/   r   rH   r0   r   r   r   rI      r2   c                 C   r+   )z}
        |Length| object representing the left margin for all pages in this
        section in English Metric Units.
        r*   left_marginr   r   r   r   rK      r.   zSection.left_marginc                 C   r/   r   rJ   r0   r   r   r   rK      r2   c                 C   r+   )z
        Member of the :ref:`WdOrientation` enumeration specifying the page
        orientation for this section, one of ``WD_ORIENT.PORTRAIT`` or
        ``WD_ORIENT.LANDSCAPE``.
        r*   orientationr   r   r   r   rM      r5   zSection.orientationc                 C   r/   r   rL   r0   r   r   r   rM      r2   c                 C   r+   )a"  
        Total page height used for this section, inclusive of all edge spacing
        values such as margins. Page orientation is taken into account, so
        for example, its expected value would be ``Inches(8.5)`` for
        letter-sized paper when orientation is landscape.
        r*   page_heightr   r   r   r   rO      rF   zSection.page_heightc                 C   r/   r   rN   r0   r   r   r   rO      r2   c                 C   r+   )a   
        Total page width used for this section, inclusive of all edge spacing
        values such as margins. Page orientation is taken into account, so
        for example, its expected value would be ``Inches(11)`` for
        letter-sized paper when orientation is landscape.
        r*   
page_widthr   r   r   r   rQ      rF   zSection.page_widthc                 C   r/   r   rP   r0   r   r   r   rQ      r2   c                 C   r+   )z~
        |Length| object representing the right margin for all pages in this
        section in English Metric Units.
        r*   right_marginr   r   r   r   rS      r.   zSection.right_marginc                 C   r/   r   rR   r0   r   r   r   rS      r2   c                 C   r+   )z
        The member of the :ref:`WdSectionStart` enumeration corresponding to
        the initial break behavior of this section, e.g.
        ``WD_SECTION.ODD_PAGE`` if the section should begin on the next odd
        page.
        r*   
start_typer   r   r   r   rU      rF   zSection.start_typec                 C   r/   r   rT   r0   r   r   r   rU      r2   c                 C   r+   )z|
        |Length| object representing the top margin for all pages in this
        section in English Metric Units.
        r*   
top_marginr   r   r   r   rW      r.   zSection.top_marginc                 C   r/   r   rV   r0   r   r   r   rW     r2   )r%   r&   r'   r(   r   propertyr-   setterr4   r9   r<   r>   r?   r	   rA   rC   rE   rG   rI   rK   rM   rO   rQ   rS   rU   rW   r)   r   r   r   r   r   (   s~    











	








	

	



	

r   c                   @   s   e Zd ZdZdd Zedd Zejdd Zedd Zd	d
 Z	edd Z
dd Zedd Zdd Zedd Zedd ZdS )_BaseHeaderFooterz(Base class for header and footer classesc                 C   s   || _ || _|| _d S r   )r*   r   _hdrftr_index)r   r   r   Zheader_footer_indexr   r   r   r   	  s   
z_BaseHeaderFooter.__init__c                 C   s   | j  S )a  ``True`` if this header/footer uses the definition from the prior section.

        ``False`` if this header/footer has an explicit definition.

        Assigning ``True`` to this property removes the header/footer definition for
        this section, causing it to "inherit" the corresponding definition of the prior
        section. Assigning ``False`` causes a new, empty definition to be added for this
        section, but only if no definition is already present.
        )_has_definitionr   r   r   r   is_linked_to_previous  s   z'_BaseHeaderFooter.is_linked_to_previousc                 C   s6   t |}|| jkrd S |du r|   d S |   d S )NT)boolr]   _drop_definition_add_definition)r   r1   Z	new_stater   r   r   r]     s   
c                 C   s   |   S )zThe |HeaderPart| or |FooterPart| for this header/footer.

        This overrides `BlockItemContainer.part` and is required to support image
        insertion and perhaps other content like hyperlinks.
        )_get_or_add_definitionr   r   r   r   part'  s   	z_BaseHeaderFooter.partc                 C      t d)z&Return newly-added header/footer part.$must be implemented by each subclassNotImplementedErrorr   r   r   r   r`   2     z!_BaseHeaderFooter._add_definitionc                 C   rc   )zE|HeaderPart| or |FooterPart| object containing header/footer content.rd   re   r   r   r   r   _definition6     z_BaseHeaderFooter._definitionc                 C   rc   )zJRemove header/footer part containing the definition of this header/footer.rd   re   r   r   r   r   r_   ;  rg   z"_BaseHeaderFooter._drop_definitionc                 C   s
   |   jS )z7`w:hdr` or `w:ftr` element, root of header/footer part.)ra   elementr   r   r   r   _element?  s   
z_BaseHeaderFooter._elementc                 C   s&   | j r| jS | j}|r| S |  S )a  Return HeaderPart or FooterPart object for this section.

        If this header/footer inherits its content, the part for the prior header/footer
        is returned; this process continue recursively until a definition is found. If
        the definition cannot be inherited (because the header/footer belongs to the
        first section), a new definition is added for that first section and then
        returned.
        )r\   rh   _prior_headerfooterra   r`   )r   Zprior_headerfooterr   r   r   ra   D  s   z(_BaseHeaderFooter._get_or_add_definitionc                 C   rc   )zHTrue if this header/footer has a related part containing its definition.rd   re   r   r   r   r   r\   X  ri   z!_BaseHeaderFooter._has_definitionc                 C   rc   )zn|_Header| or |_Footer| proxy on prior sectPr element.

        Returns None if this is first section.
        rd   re   r   r   r   r   rl   ]  r.   z%_BaseHeaderFooter._prior_headerfooterN)r%   r&   r'   r(   r   rX   r]   rY   rb   r`   rh   r_   rk   ra   r\   rl   r   r   r   r   rZ     s(    







rZ   c                   @   D   e Zd ZdZdd Zedd Zdd Zedd	 Zed
d Z	dS )r7   a  Page footer, used for all three types (default, even-page, and first-page).

    Note that, like a document or table cell, a footer must contain a minimum of one
    paragraph and a new or otherwise "empty" footer contains a single empty paragraph.
    This first paragraph can be accessed as `footer.paragraphs[0]` for purposes of
    adding content to it. Using :meth:`add_paragraph()` by itself to add content will
    leave an empty paragraph above the newly added one.
    c                 C   "   | j  \}}| j| j| |S )zReturn newly-added footer part.)r   Zadd_footer_partr*   Zadd_footerReferencer[   )r   footer_partrIdr   r   r   r`   p     z_Footer._add_definitionc                 C      | j | j}| j|jS )z6|FooterPart| object containing content of this footer.)r*   get_footerReferencer[   r   ro   rp   r   ZfooterReferencer   r   r   rh   v     z_Footer._definitionc                 C      | j | j}| j| dS )zDRemove footer definition (footer part) associated with this section.N)r*   Zremove_footerReferencer[   r   Zdrop_relr   rp   r   r   r   r_   |     z_Footer._drop_definitionc                 C      | j | j}|du rdS dS )z-True if a footer is defined for this section.NFT)r*   rs   r[   rt   r   r   r   r\        z_Footer._has_definitionc                 C   $   | j j}|du r
dS t|| j| jS )zI|_Footer| proxy on prior sectPr element or None if this is first section.N)r*   preceding_sectPrr7   r   r[   r   r|   r   r   r   rl        z_Footer._prior_headerfooterN
r%   r&   r'   r(   r`   rX   rh   r_   r\   rl   r   r   r   r   r7   f      	

r7   c                   @   rm   )r;   a  Page header, used for all three types (default, even-page, and first-page).

    Note that, like a document or table cell, a header must contain a minimum of one
    paragraph and a new or otherwise "empty" header contains a single empty paragraph.
    This first paragraph can be accessed as `header.paragraphs[0]` for purposes of
    adding content to it. Using :meth:`add_paragraph()` by itself to add content will
    leave an empty paragraph above the newly added one.
    c                 C   rn   )zReturn newly-added header part.)r   Zadd_header_partr*   Zadd_headerReferencer[   )r   header_partrp   r   r   r   r`     rq   z_Header._add_definitionc                 C   rr   )z6|HeaderPart| object containing content of this header.)r*   get_headerReferencer[   r   r   rp   r   ZheaderReferencer   r   r   rh     ru   z_Header._definitionc                 C   rv   )z6Remove header definition associated with this section.N)r*   Zremove_headerReferencer[   r   Zdrop_header_partrw   r   r   r   r_     rx   z_Header._drop_definitionc                 C   ry   )z8True if a header is explicitly defined for this section.NFT)r*   r   r[   r   r   r   r   r\     rz   z_Header._has_definitionc                 C   r{   )zI|_Header| proxy on prior sectPr element or None if this is first section.N)r*   r|   r;   r   r[   r}   r   r   r   rl     r~   z_Header._prior_headerfooterNr   r   r   r   r   r;     r   r;   N)r(   Z
__future__r   r   r   r   Zdocx.blkcntnrr   Zdocx.compatr   Zdocx.enum.sectionr   Zdocx.sharedr	   r
   objectr   rZ   r7   r;   r   r   r   r   <module>   s    _`,