o
    W_j+                     @   s   d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZmZmZ ddlmZmZmZmZ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G dd deZdS )z&Section-related custom element classes    )absolute_importdivisionprint_functionunicode_literals)deepcopy)WD_HEADER_FOOTERWD_ORIENTATIONWD_SECTION_START)ST_SignedTwipsMeasureST_TwipsMeasure	XsdString)BaseOxmlElementOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOnec                   @   s(   e Zd ZdZedddZedddZdS )	CT_HdrFtrzM`w:hdr` and `w:ftr`, the root element for header and footer part respectivelyzw:p Z
successorszw:tblN)__name__
__module____qualname____doc__r   ptblr   r   r   AD:\Projects\ConvertPro\env\Lib\site-packages\docx\oxml\section.pyr      s    r   c                   @   s$   e Zd ZdZedeZedeZdS )CT_HdrFtrRefz4`w:headerReference` and `w:footerReference` elementsw:typezr:idN)	r   r   r   r   r   r   type_r   rIdr   r   r   r   r      s    
r   c                   @   sV   e Zd ZdZedeZedeZedeZ	edeZ
edeZedeZedeZd	S )

CT_PageMarz7
    ``<w:pgMar>`` element, defining page margins.
    zw:topzw:rightzw:bottomzw:leftzw:headerzw:footerzw:gutterN)r   r   r   r   r   r
   topr   rightbottomleftheaderfootergutterr   r   r   r   r    "   s    





r    c                   @   s4   e Zd ZdZedeZedeZedeej	dZ
dS )	CT_PageSzzI
    ``<w:pgSz>`` element, defining page dimensions and orientation.
    zw:wzw:hzw:orient)defaultN)r   r   r   r   r   r   whr   PORTRAITorientr   r   r   r   r(   /   s    


r(   c                   @   s  e Zd ZdZdZededZededZededd dZ	ed	ed
d dZ
ededd dZededd dZ[dd Zdd Zedd Zejdd Zdd Zedd Zejdd Zdd Z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d3d4 Zd5d6 Zed7d8 Zejd9d8 Zed:d; Z e jd<d; Z ed=d> Z!e!jd?d> Z!ed@dA Z"e"jdBdA Z"dS )C	CT_SectPrz@`w:sectPr` element, the container element for section properties)zw:footnotePrzw:endnotePrr   w:pgSzw:pgMarz
w:paperSrczw:pgBorderszw:lnNumTypezw:pgNumTypezw:colsz
w:formProtzw:vAlignzw:noEndnote	w:titlePgzw:textDirectionzw:bidizw:rtlGutterz	w:docGridzw:printerSettingszw:sectPrChangezw:headerReferencer   zw:footerReferencer      Nr/      r0      r1      c                 C      |   }||_||_|S )zxReturn newly added CT_HdrFtrRef element of *type_* with *rId*.

        The element tag is `w:footerReference`.
        )Z_add_footerReferencer   r   )selfr   r   footerReferencer   r   r   add_footerReferenceK      zCT_SectPr.add_footerReferencec                 C   r6   )zxReturn newly added CT_HdrFtrRef element of *type_* with *rId*.

        The element tag is `w:headerReference`.
        )Z_add_headerReferencer   r   )r7   r   r   headerReferencer   r   r   add_headerReferenceU   r:   zCT_SectPr.add_headerReferencec                 C      | j }|du r	dS |jS )z
        The value of the ``w:bottom`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)pgMarr#   r7   r>   r   r   r   bottom_margin_      zCT_SectPr.bottom_marginc                 C      |   }||_d S N)get_or_add_pgMarr#   r7   valuer>   r   r   r   r@   k      
c                 C   s   t | }|j  |S )z
        Return an exact duplicate of this ``<w:sectPr>`` element tree
        suitable for use in adding a section break. All rsid* attributes are
        removed from the root ``<w:sectPr>`` element.
        )r   Zattribclear)r7   Zclone_sectPrr   r   r   clonep   s   
zCT_SectPr.clonec                 C   r=   )z
        The value of the ``w:footer`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)r>   r&   r?   r   r   r   r&   z   rA   zCT_SectPr.footerc                 C   rB   rC   )rD   r&   rE   r   r   r   r&      rG   c                 C   s(   dt | }| |}|sdS |d S )zAReturn footerReference element of *type_* or None if not present.z!./w:footerReference[@w:type='%s']Nr   )r   to_xmlxpath)r7   r   pathZfooterReferencesr   r   r   get_footerReference   s
   
zCT_SectPr.get_footerReferencec                 C   s,   |  dt| }t|dkrdS |d S )zAReturn headerReference element of *type_* or None if not present.z!./w:headerReference[@w:type='%s']r   N)rK   r   rJ   len)r7   r   Zmatching_headerReferencesr   r   r   get_headerReference   s   zCT_SectPr.get_headerReferencec                 C   r=   )z
        The value of the ``w:gutter`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)r>   r'   r?   r   r   r   r'      rA   zCT_SectPr.gutterc                 C   rB   rC   )rD   r'   rE   r   r   r   r'      rG   c                 C   r=   )z
        The value of the ``w:header`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)r>   r%   r?   r   r   r   r%      rA   zCT_SectPr.headerc                 C   rB   rC   )rD   r%   rE   r   r   r   r%      rG   c                 C   r=   )z
        The value of the ``w:left`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)r>   r$   r?   r   r   r   left_margin   rA   zCT_SectPr.left_marginc                 C   rB   rC   )rD   r$   rE   r   r   r   rP      rG   c                 C   s   | j }|du r
tjS |jS )z
        The member of the ``WD_ORIENTATION`` enumeration corresponding to the
        value of the ``orient`` attribute of the ``<w:pgSz>`` child element,
        or ``WD_ORIENTATION.PORTRAIT`` if not present.
        N)pgSzr   r,   r-   r7   rQ   r   r   r   orientation   s   zCT_SectPr.orientationc                 C   rB   rC   )get_or_add_pgSzr-   r7   rF   rQ   r   r   r   rS      rG   c                 C   r=   )zz
        Value in EMU of the ``h`` attribute of the ``<w:pgSz>`` child
        element, or |None| if not present.
        N)rQ   r+   rR   r   r   r   page_height      zCT_SectPr.page_heightc                 C   rB   rC   )rT   r+   rU   r   r   r   rV      rG   c                 C   r=   )zz
        Value in EMU of the ``w`` attribute of the ``<w:pgSz>`` child
        element, or |None| if not present.
        N)rQ   r*   rR   r   r   r   
page_width   rW   zCT_SectPr.page_widthc                 C   rB   rC   )rT   r*   rU   r   r   r   rX      rG   c                 C   s"   |  d}t|dkr|d S dS )zCsectPr immediately preceding this one or None if this is the first.z./preceding::w:sectPr[1]r   N)rK   rN   )r7   Zpreceding_sectPrsr   r   r   preceding_sectPr   s   
zCT_SectPr.preceding_sectPrc                 C      |  |}|j}| | |S )zCReturn rId of w:footerReference child of *type_* after removing it.)rM   r   remove)r7   r   r8   r   r   r   r   remove_footerReference     

z CT_SectPr.remove_footerReferencec                 C   rZ   )zCReturn rId of w:headerReference child of *type_* after removing it.)rO   r   r[   )r7   r   r;   r   r   r   r   remove_headerReference  r]   z CT_SectPr.remove_headerReferencec                 C   r=   )z
        The value of the ``w:right`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)r>   r"   r?   r   r   r   right_margin  rA   zCT_SectPr.right_marginc                 C   rB   rC   )rD   r"   rE   r   r   r   r_   !  rG   c                 C   s$   | j }|du s|jdu rtjS |jS )z
        The member of the ``WD_SECTION_START`` enumeration corresponding to
        the value of the ``val`` attribute of the ``<w:type>`` child element,
        or ``WD_SECTION_START.NEW_PAGE`` if not present.
        N)typevalr	   NEW_PAGE)r7   r`   r   r   r   
start_type&  s   zCT_SectPr.start_typec                 C   s0   |d u s	|t ju r|   d S |  }||_d S rC   )r	   rb   Z_remove_typeZget_or_add_typera   )r7   rF   r`   r   r   r   rc   2  s
   
c                 C   s   | j }|du r	dS |jS )z2Value of `w:titlePg/@val` or |None| if not presentNF)titlePgra   )r7   rd   r   r   r   titlePg_val:  s   zCT_SectPr.titlePg_valc                 C   s"   |dv r
|    d S ||  _d S )N)NF)Z_remove_titlePgZget_or_add_titlePgra   )r7   rF   r   r   r   re   B  s   c                 C   r=   )z
        The value of the ``w:top`` attribute in the ``<w:pgMar>`` child
        element, as a |Length| object, or |None| if either the element or the
        attribute is not present.
        N)r>   r!   r?   r   r   r   
top_marginI  rA   zCT_SectPr.top_marginc                 C   rB   rC   )rD   r!   rE   r   r   r   rf   U  rG   )#r   r   r   r   Z_tag_seqr   r;   r8   r   r`   rQ   r>   rd   r9   r<   propertyr@   setterrI   r&   rM   rO   r'   r%   rP   rS   rV   rX   rY   r\   r^   r_   rc   re   rf   r   r   r   r   r.   :   s    






	





















r.   c                   @   s   e Zd ZdZedeZdS )CT_SectTypezD
    ``<w:sectType>`` element, defining the section start type.
    zw:valN)r   r   r   r   r   r	   ra   r   r   r   r   ri   [  s    ri   N)r   Z
__future__r   r   r   r   copyr   Zdocx.enum.sectionr   r   r	   Zdocx.oxml.simpletypesr
   r   r   Zdocx.oxml.xmlchemyr   r   r   r   r   r   r   r    r(   r.   ri   r   r   r   r   <module>   s   	  #