XjOUdZddlmZddlmZddlmZmZmZm 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/GddZ0y )!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 BlockElementcteZdZUdZded<ded<ded<ded <ed d Zed d ZeddZ y) 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:tblc$|jdS)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 e/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/oxml/section.pyinner_content_elementsz CT_HdrFtr.inner_content_elements)szz+,,N)returnzList[CT_P | CT_Tbl]) __name__ __module__ __qualname____doc____annotations__rptblpropertyr,r$r-r+rrsGX   ++5R(A W ,C --r-rcJeZdZUdZedeZded<edeZ ded<y) CT_HdrFtrRefz5`w:headerReference` and `w:footerReference` elements.w:typer type_zr:idstrrIdN) r/r0r1r2rr r:r3rr<r$r-r+r8r83s0?/"E !3C3r-r8ceZdZUdZedeZded<edeZ ded<edeZ ded<ed eZ ded <ed eZ ded <ed eZ ded<edeZded<y) CT_PageMarz-```` element, defining page margins.zw:top Length | Nonetopzw:rightrightzw:bottombottomzw:leftleftzw:headerheaderzw:footerfooterzw:guttergutterN)r/r0r1r2rrr@r3rrArBrCrDrErFr$r-r+r>r><s7*&C-?E=.)FM,/D-.OFM.OFM.OFMr-r>c~eZdZUdZedeZded<edeZded<ede e jZ d ed <y ) CT_PageSzz?```` element, defining page dimensions and orientation.zw:wr?wzw:hhzw:orient)defaultr orientN) r/r0r1r2rrrIr3rJr PORTRAITrLr$r-r+rHrHVsSI( A}) A}/NN,C,CFNr-rHceZdZUdZded<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$<[dFd%ZdFd&ZedGd'Zej$dHd(ZdId)ZedGd*Zej$dHd+ZdJd,ZdJd-ZedGd.Zej$dHd/ZedGd0Zej$dHd1ZdKd2ZedGd3Zej$dHd4ZedLd5Zej$dMd6ZedGd7Zej$dNd8ZedGd9Zej$dNd:ZedOd;ZdPd<ZdQd=Z edGd>Z!e!j$dNd?Z!edRd@Z"e"j$dSdAZ"edTdBZ#e#j$dUdCZ#edGdDZ$e$j$dNdEZ$y)V 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:endnotePrr9w: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:footerReferencer9NzCT_SectType | NonetyperXzCT_PageSz | NonepgSzrYzCT_PageMar | NonepgMarrZzCT_OnOff | NonetitlePgcB|j}||_||_|S)zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`. The element tag is `w:footerReference`. )rTr:r<)r*r:r<footerReferences r+add_footerReferencezCT_SectPr.add_footerReference( 335 %!r-cB|j}||_||_|S)zxReturn newly added CT_HdrFtrRef element of `type_` with `rId`. The element tag is `w:headerReference`. )rUr:r<)r*r:r<headerReferences r+add_headerReferencezCT_SectPr.add_headerReferencerfr-c8|j}|y|jS)zValue of the `w:bottom` attr of `` child element, as |Length|. |None| when either the element or the attribute is not present. N)r`rBr*r`s r+ bottom_marginzCT_SectPr.bottom_margins   =||r-cx|j}|t|tr||_yt||_yN)rP isinstancerrBr*valuer`s r+rlzCT_SectPr.bottom_margin1%%' % E61Ju PVW\P] r-cPt|}|jj|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-c8|j}|y|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)r`rErks r+rEzCT_SectPr.footers  =||r-cx|j}|t|tr||_yt||_yrn)rProrrErps r+rEzCT_SectPr.footerrrr-cddtj|z}|j|}|sy|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_footerReferences825E5L5LU5SS::d+""r-cx|jdtj|z}t|dk(ry|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_headerReferencesC$(JJ /2B2I2I%2P P% ! ( )Q .(++r-c8|j}|y|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)r`rFrks r+rFzCT_SectPr.gutters   =||r-cx|j}|t|tr||_yt||_yrn)rProrrFrps r+rFzCT_SectPr.gutterrrr-c8|j}|y|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)r`rDrks r+rDzCT_SectPr.headers  =||r-cx|j}|t|tr||_yt||_yrn)rProrrDrps r+rDzCT_SectPr.headerrrr-c,tj|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$GGr-c8|j}|y|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)r`rCrks r+ left_marginzCT_SectPr.left_margins   =zzr-cx|j}|t|tr||_yt||_yrn)rProrrCrps r+rzCT_SectPr.left_margins/%%'#mz%/HU fUZm r-cV|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 rMrLr*r^s r+ orientationzCT_SectPr.orientations(yy <!** *{{r-cb|j}|r||_ytj|_yrn)rQr rMrLr*rqr^s r+rzCT_SectPr.orientation*s%##%$e .*A*A r-c8|j}|y|jS)ziValue in EMU of the `h` attribute of the `w:pgSz` child element. |None| if not present. N)r^rJrs r+ page_heightzCT_SectPr.page_height/ yy <vv r-c2|j}||_yrn)rQrJrs r+rzCT_SectPr.page_height:##%r-c8|j}|y|jS)zoValue in EMU of the ``w`` attribute of the ```` child element. |None| if not present. N)r^rIrs r+ page_widthzCT_SectPr.page_width?rr-c2|j}||_yrn)rQrIrs r+rzCT_SectPr.page_widthJrr-cN|jd}t|dkDr|dSdS)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_sectPrOs2!JJ'AB'*+<'='A #KtKr-c||j|}| td|j}|j||S)zCReturn rId of w:footerReference child of `type_` after removing it.z!CT_SectPr has no footer reference)r~ ValueErrorr<remove)r*r:rdr<s r+remove_footerReferencez CT_SectPr.remove_footerReferenceV@2259  "@A A!! O$ r-c||j|}| td|j}|j||S)zCReturn rId of w:headerReference child of `type_` after removing it.z!CT_SectPr has no header reference)rrr<r)r*r:rhr<s r+remove_headerReferencez CT_SectPr.remove_headerReference`rr-c8|j}|y|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)r`rArks r+ right_marginzCT_SectPr.right_marginjs   ={{r-c2|j}||_yrn)rPrArps r+rzCT_SectPr.right_margints%%' r-cn|j}| |jtjS|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_typeys0 yy <488+#,, ,xxr-c|||tjur|jy|j}||_yrn)rrrWrSr)r*rqr\s r+rzCT_SectPr.start_types9 =E%5%>%>>     ##%r-c8|j}|y|jS)zEValue of `w:titlePg/@val` or |False| if `./w:titlePg` is not present.F)rbr)r*rbs r+ titlePg_valzCT_SectPr.titlePg_vals,, ?{{r-cX|dvr|jyd|j_y)N)NFT)rVrRr)r*rqs r+rzCT_SectPr.titlePg_vals' M !  ",0D # # % )r-c8|j}|y|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)r`r@rks r+ top_marginzCT_SectPr.top_margins   =yyr-c2|j}||_yrn)rPr@rps r+rzCT_SectPr.top_margins%%' r-)r:r r<r;r.r8)r.r?)rqzint | Length | None)r.rO)r:r r.zCT_HdrFtrRef | None)r.zIterator[CT_P | CT_Tbl])r.r )rqzWD_ORIENTATION | None)rqr?)r.zCT_SectPr | None)r:r r.r;)r:r )r.r)rqWD_SECTION_START | None)r.bool)rqz bool | None)%r/r0r1r2r3_tag_seqrrhrdrr\r^r`rbrerir6rlsetterrwrEr~rrFrDrrrrrrrrrrrrr$r-r+rOrOdsCK..,,....4444''$$H,!!4JO !4JO(Xab\ D 'Xab\D  )hqrl E  )  G_ ^^   ]]^^#, ]]^^   ]]^^H\\  BBLL 11 r-rOc.eZdZUdZedeZded<y) CT_SectTypez:```` element, defining the section start type.zw:valrrN)r/r0r1r2rrrr3r$r-r+rrsD#4!$C r-rceZdZUdZdZded<dZded<d dZeddZ ddZ dd Z e dd Z dd Ze dd Zy)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_xpathc||_yrn)_sectPr)r*sectPrs r+__init__z"_SectBlockElementIterator.__init__s  r-c.||jS)zIGenerate each CT_P or CT_Tbl element within extents governed by `sectPr`.)_iter_sect_block_elements)clsrs r+rz2_SectBlockElementIterator.iter_sect_block_elementss6{4466r-c#K|j|j}}|j|}|dk(rdn|j||dz }|j ||dD]}|yw)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_elementssz,, ]]6* Q ;;GJQRNrHrOrrr$r-r+rs-";;'PP%SS")-) i)--,4?44  CCL /d d r-