;iOUdZddlmZddlmZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZmZmZddlmZdd lmZdd lmZmZmZdd lmZdd lmZdd lm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'dZ(de)d<Gdde Z*Gdde Z+Gdde Z,Gdde Z-Gdde Z.Gdde Z/GddZ0d S)!z'Section-related custom element classes.) annotations)deepcopy)CallableIteratorListSequencecast)etree) TypeAlias)WD_HEADER_FOOTERWD_ORIENTATIONWD_SECTION_START)nsmap)CT_OnOff)ST_SignedTwipsMeasureST_TwipsMeasure XsdString)CT_Tbl)CT_P)BaseOxmlElementOptionalAttributeRequiredAttribute ZeroOrMore ZeroOrOne)Length lazypropertyz CT_P | CT_Tblr BlockElementceZdZUdZded<ded<ded<ded <ed d Zed d ZeddZ dS) CT_HdrFtrzN`w:hdr` and `w:ftr`, the root element for header and footer part respectively.zCallable[[], CT_P]add_pz List[CT_P]p_lstz List[CT_Tbl]tbl_lstzCallable[[CT_Tbl], CT_Tbl] _insert_tblzw:p successorszw:tblreturnList[CT_P | CT_Tbl]c,|dS)zGenerate all `w:p` and `w:tbl` elements in this header or footer. Elements appear in document order. Elements shaded by nesting in a `w:ins` or other "wrapper" element will not be included. z./w:p | ./w:tbl)xpathselfs EC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\docx/oxml/section.pyinner_content_elementsz CT_HdrFtr.inner_content_elements)szz+,,,N)r'r() __name__ __module__ __qualname____doc____annotations__rptblpropertyr.r$r/r-rrsXX++++ 5R(((A *W , , ,C ---X---r/rcXeZdZUdZedeZded<edeZ ded<dS) CT_HdrFtrRefz5`w:headerReference` and `w:footerReference` elements.w:typer type_zr:idstrrIdN) r0r1r2r3rr r;r4rr=r$r/r-r9r93sd??//"E! 33C333333r/r9ceZdZUdZedeZded<edeZ ded<edeZ ded<ed eZ ded <ed eZ ded <ed eZ ded<edeZded<dS) CT_PageMarz-```` element, defining page margins.zw:top Length | Nonetopzw:rightrightzw:bottombottomzw:leftleftzw:headerheaderzw:footerfooterzw:guttergutterN)r0r1r2r3rrrAr4rrBrCrDrErFrGr$r/r-r?r?<sW77**&C-,?E.-)F,+/D.-OF.-OF.-OFr/r?ceZdZUdZedeZded<edeZded<ede e j Z d ed <d S) CT_PageSzz?```` element, defining page dimensions and orientation.zw:wr@wzw:hhzw:orient)defaultr orientN) r0r1r2r3rrrJr4rKr PORTRAITrMr$r/r-rIrIVsII(( A)( A/.NN,CFr/rIc~eZdZUdZded<ded<ded<ded <d ed <d ed <d ed<d ed<dZedeZedeZe deddZ ded<e deddZ ded<e deddZ ded <e d!ed"dZ d#ed$<[dXd+ZdXd,ZedYd.ZejdZd1Zd[d2ZedYd3ZejdZd4Zd\d6Zd\d7ZedYd8ZejdZd9ZedYd:ZejdZd;Zd]d=ZedYd>ZejdZd?Zed^dAZejd_dCZedYdDZejd`dEZedYdFZejd`dGZedadIZdbdJZdcdKZ edYdLZ!e!jd`dMZ!edddOZ"e"jdedQZ"edfdSZ#e#jdgdUZ#edYdVZ$e$jd`dWZ$dS)h CT_SectPrzA`w:sectPr` element, the container element for section properties.zCallable[[], CT_PageMar]get_or_add_pgMarzCallable[[], CT_PageSz]get_or_add_pgSzzCallable[[], CT_OnOff]get_or_add_titlePgzCallable[[], CT_SectType]get_or_add_typezCallable[[], CT_HdrFtrRef]_add_footerReference_add_headerReferencezCallable[[], None]_remove_titlePg _remove_type)z w:footnotePrz w:endnotePrr:w:pgSzw:pgMarz w:paperSrcz w:pgBordersz w:lnNumTypez w:pgNumTypezw:colsz w:formProtzw:vAlignz w:noEndnote w:titlePgzw:textDirectionzw:bidiz w:rtlGutterz w:docGridzw:printerSettingszw:sectPrChangezw:headerReferencer%zw:footerReferencer:NzCT_SectType | NonetyperYzCT_PageSz | NonepgSzrZzCT_PageMar | NonepgMarr[zCT_OnOff | NonetitlePgr;r r=r<r'r9cJ|}||_||_|S)zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`. The element tag is `w:footerReference`. )rUr;r=)r,r;r=footerReferences r-add_footerReferencezCT_SectPr.add_footerReference+ 3355 %!r/cJ|}||_||_|S)zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`. The element tag is `w:headerReference`. )rVr;r=)r,r;r=headerReferences r-add_headerReferencezCT_SectPr.add_headerReferencergr/r@c&|j}|dS|jS)zValue of the `w:bottom` attr of `` child element, as |Length|. |None| when either the element or the attribute is not present. N)rarCr,ras r- bottom_marginzCT_SectPr.bottom_margins   =4|r/valueint | Length | Nonec|}|t|tr|nt||_dSN)rQ isinstancerrCr,rnras r-rmzCT_SectPr.bottom_margin>%%'' % E61J1J uuPVW\P]P] r/cVt|}|j|S)zReturn an exact duplicate of this ```` element tree suitable for use in adding a section break. All rsid* attributes are removed from the root ```` element. )rattribclear)r, cloned_sectPrs r-clonezCT_SectPr.clones* ! ""$$$r/c&|j}|dS|jS)aDistance from bottom edge of page to bottom edge of the footer. This is 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)rarFrls r-rFzCT_SectPr.footers  =4|r/c|}|t|tr|nt||_dSrq)rQrrrrFrss r-rFzCT_SectPr.footerrtr/CT_HdrFtrRef | Nonecrdtj|z}||}|sdS|dS)zAReturn footerReference element of `type_` or None if not present.z!./w:footerReference[@w:type='%s']Nr)r to_xmlr*)r,r;pathfooterReferencess r-get_footerReferencezCT_SectPr.get_footerReferencesB25E5LU5S5SS::d++ 4""r/c|dtj|z}t|dkrdS|dS)zAReturn headerReference element of `type_` or None if not present.z!./w:headerReference[@w:type='%s']rN)r*r r~len)r,r;matching_headerReferencess r-get_headerReferencezCT_SectPr.get_headerReferencesP$(JJ /2B2I%2P2P P% % ! ( ) )Q . .4(++r/c&|j}|dS|jS)zThe value of the ``w:gutter`` attribute in the ```` child element, as a |Length| object, or |None| if either the element or the attribute is not present.N)rarGrls r-rGzCT_SectPr.gutters   =4|r/c|}|t|tr|nt||_dSrq)rQrrrrGrss r-rGzCT_SectPr.gutterrtr/c&|j}|dS|jS)zDistance from top edge of page to top edge of header. This value comes from the `w:header` attribute on the `w:pgMar` child element. |None| if either the element or the attribute is not present. N)rarErls r-rEzCT_SectPr.headers  =4|r/c|}|t|tr|nt||_dSrq)rQrrrrErss r-rEzCT_SectPr.headerrtr/Iterator[CT_P | CT_Tbl]c6t|S)zGenerate all `w:p` and `w:tbl` elements in this section. Elements appear in document order. Elements shaded by nesting in a `w:ins` or other "wrapper" element will not be included. )_SectBlockElementIteratoriter_sect_block_elementsr+s r-iter_inner_contentzCT_SectPr.iter_inner_contents )AA$GGGr/c&|j}|dS|jS)zThe value of the ``w:left`` attribute in the ```` child element, as a |Length| object, or |None| if either the element or the attribute is not present.N)rarDrls r- left_marginzCT_SectPr.left_margins   =4zr/c|}|t|tr|nt||_dSrq)rQrrrrDrss r-rzCT_SectPr.left_margins;%%''#mz%/H/HmUUfUZmm r/r c:|j}| tjS|jS)z`WD_ORIENTATION` member indicating page-orientation for this section. This is the value of the `orient` attribute on the `w:pgSz` child, or `WD_ORIENTATION.PORTRAIT` if not present. )r_r rNrMr,r_s r- orientationzCT_SectPr.orientations!y <!* *{r/WD_ORIENTATION | NonecX|}|r|n tj|_dSrq)rRr rNrMr,rnr_s r-rzCT_SectPr.orientation*s*##%%$Aee.*A r/c&|j}|dS|jS)ziValue in EMU of the `h` attribute of the `w:pgSz` child element. |None| if not present. N)r_rKrs r- page_heightzCT_SectPr.page_height/ y <4v r/c<|}||_dSrq)rRrKrs r-rzCT_SectPr.page_height:##%%r/c&|j}|dS|jS)zoValue in EMU of the ``w`` attribute of the ```` child element. |None| if not present. N)r_rJrs r- page_widthzCT_SectPr.page_width?rr/c<|}||_dSrq)rRrJrs r-rzCT_SectPr.page_widthJrr/CT_SectPr | Nonecf|d}t|dkr|dndS)zCSectPr immediately preceding this one or None if this is the first.z./preceding::w:sectPr[1]rN)r*r)r,preceding_sectPrss r-preceding_sectPrzCT_SectPr.preceding_sectPrOs;!JJ'ABB'*+<'='='A'A ##tKr/c||}|td|j}|||S)zCReturn rId of w:footerReference child of `type_` after removing it.Nz!CT_SectPr has no footer reference)r ValueErrorr=remove)r,r;rer=s r-remove_footerReferencez CT_SectPr.remove_footerReferenceVI22599  "@AA A! O$$$ r/c||}|td|j}|||S)zCReturn rId of w:headerReference child of `type_` after removing it.Nz!CT_SectPr has no header reference)rrr=r)r,r;rir=s r-remove_headerReferencez CT_SectPr.remove_headerReference`rr/c&|j}|dS|jS)zThe value of the ``w:right`` attribute in the ```` child element, as a |Length| object, or |None| if either the element or the attribute is not present.N)rarBrls r- right_marginzCT_SectPr.right_marginjs   =4{r/c<|}||_dSrq)rQrBrss r-rzCT_SectPr.right_margints%%'' r/rcH|j}||j tjS|jS)zThe member of the ``WD_SECTION_START`` enumeration corresponding to the value of the ``val`` attribute of the ```` child element, or ``WD_SECTION_START.NEW_PAGE`` if not present.)r]valrNEW_PAGE)r,r]s r- start_typezCT_SectPr.start_typeys' y <48+#, ,xr/WD_SECTION_START | Nonec||tjur|dS|}||_dSrq)rrrXrTr)r,rnr]s r-rzCT_SectPr.start_typesH =E%5%>>>       F##%%r/boolc&|j}|dS|jS)zEValue of `w:titlePg/@val` or |False| if `./w:titlePg` is not present.NF)rcr)r,rcs r- titlePg_valzCT_SectPr.titlePg_vals, ?5{r/ bool | Nonecl|dvr|dSd|_dS)N)NFT)rWrSr)r,rns r-rzCT_SectPr.titlePg_vals? M ! !  " " " " ",0D # # % % ) ) )r/c&|j}|dS|jS)zThe value of the ``w:top`` attribute in the ```` child element, as a |Length| object, or |None| if either the element or the attribute is not present.N)rarArls r- top_marginzCT_SectPr.top_margins   =4yr/c<|}||_dSrq)rQrArss r-rzCT_SectPr.top_margins%%'' r/)r;r r=r<r'r9)r'r@)rnro)r'rP)r;r r'r|)r'r)r'r )rnr)rnr@)r'r)r;r r'r<)r;r )r'r)rnr)r'r)rnr)%r0r1r2r3r4_tag_seqrrirerr]r_rarcrfrjr7rmsetterryrFrrrGrErrrrrrrrrrrrr$r/r-rPrPdsKK....,,,,........44444444''''$$$$H,!j!4JJJO j!4JJJO(yXabb\   D'YXabb\D )yhqrrl   E )y    G X^^^^   X  ]^^^]^####,,,,X ]^^^]^   X  ]^^^]^HHHHX\\\\   X BBBBXXLLLXL XXX1111 Xr/rPc6eZdZUdZedeZded<dS) CT_SectTypez:```` element, defining the section start type.zw:valrrN)r0r1r2r3rrrr4r$r/r-rrsHDD#4#4!$$Cr/rceZdZUdZdZded<dZded<ddZedd Z dd Z ddZ e ddZ ddZe ddZdS)rzGenerates the block-item XML elements in a section. A block-item element is a `CT_P` (paragraph) or a `CT_Tbl` (table). Nzetree.XPath | None_compiled_blocks_xpath_compiled_count_xpathsectPrrPc||_dSrq)_sectPr)r,rs r-__init__z"_SectBlockElementIterator.__init__s  r/r'Iterator[BlockElement]c<||S)zIGenerate each CT_P or CT_Tbl element within extents governed by `sectPr`.)_iter_sect_block_elements)clsrs r-rz2_SectBlockElementIterator.iter_sect_block_elementsss6{{44666r/c#K|j|j}}||}|dkrdn|||dz }|||dD]}|VdS)z0Generate each CT_P or CT_Tbl element in section.rN)r_sectPrsindex%_count_of_blocks_in_and_above_section_blocks_in_and_above_section)r,rsectPrs sectPr_idxn_blks_to_skipelements r-rz3_SectBlockElementIterator._iter_sect_block_elementss, ]]6** Q A;;GJQRNrs---"""""";;;;;;;;;;;;;;''''''PPPPPPPPPP%%%%%%SSSSSSSSSS""""""))))))-,,,,,,,) ))))--------,44444?4444        CCCCCCCCL /d d d d d d d d d d r/