;iGpdZddlmZddlmZmZmZmZmZddl m Z ddl m Z ddl mZddlmZmZddlmZdd lmZdd lmZer&dd l mZmZdd lmZdd lmZddlmZddl m!Z!ddlm"Z"GddZ#Gddee#Z$Gdde Z%Gdde%Z&Gdde%Z'dS)z/The |Section| object and related proxy classes.) annotations) TYPE_CHECKINGIteratorListSequenceoverload)BlockItemContainer)WD_HEADER_FOOTER)CT_P) FooterPart HeaderPart) lazyproperty)Table) Paragraph)WD_ORIENTATIONWD_SECTION_START) CT_Document) CT_SectPr) DocumentPart) StoryPart)LengthceZdZdZd4fd Zed5d Zejd6d Zed7dZejd8dZed9dZ ed:dZ ed9dZ ed:dZ e d9dZed5dZejd6dZed5dZejd6dZe d:dZed5dZejd6dZd;dZed5d Zejd6d!Zedd'Zed5d(Zejd>d)Zed?d+Zed5d,Zejd>d-Zed@d/ZejdAd1Zed5d2Zejd>d3ZxZS)BSectionz}Document section, providing access to section and page setup settings. Also provides access to headers and footers. sectPrr document_partrcrtt|||_||_dSN)superr__init___sectPr_document_part)selfrr __class__s @C:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\docx/section.pyrzSection.__init__s4 gt%%''' +return Length | Nonec|jjS)zRead/write. Bottom margin for pages in this section, in EMU. `None` when no bottom margin has been specified. Assigning |None| removes any bottom-margin setting. r bottom_marginr"s r$r*zSection.bottom_margin#s|))r%valueint | Length | Nonec||j_dSrr)r"r,s r$r*zSection.bottom_margin,s%* """r%boolc|jjS)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 titlePg_valr+s r$"different_first_page_header_footerz*Section.different_first_page_header_footer0s|''r%c||j_dSrr2r/s r$r4z*Section.different_first_page_header_footer9#(    r%_FootercLt|j|jtjS)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. )r7r r!r EVEN_PAGEr+s r$even_page_footerzSection.even_page_footer=t|T%8:J:TUUUr%_HeadercLt|j|jtjS)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. )r<r r!r r9r+s r$even_page_headerzSection.even_page_headerFr;r%cLt|j|jtjS)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. )r7r r!r FIRST_PAGEr+s r$first_page_footerzSection.first_page_footerOt|T%8:J:UVVVr%cLt|j|jtjS)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+s r$first_page_headerzSection.first_page_headerXrBr%cLt|j|jtjS)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. )r7r r!r PRIMARYr+s r$footerzSection.footerat|T%8:J:RSSSr%c|jjS)zDistance from bottom edge of page to bottom edge of the footer. Read/write. |None| if no setting is present in the XML. r rGr+s r$footer_distancezSection.footer_distancejs |""r%c||j_dSrrJr/s r$rKzSection.footer_distancer# r%c|jjS)ai|Length| object representing page gutter size in English Metric Units. Read/write. The page gutter is extra spacing added to the `inner` margin to ensure even margins after page binding. Generally only used in book-bound documents with double-sided and facing pages. This setting applies to all pages in this section. r gutterr+s r$rPzSection.guttervs|""r%c||j_dSrrOr/s r$rPzSection.gutterrMr%cLt|j|jtjS)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 rFr+s r$headerzSection.headerrHr%c|jjS)zDistance from top edge of page to top edge of header. Read/write. |None| if no setting is present in the XML. Assigning |None| causes default value to be used. r rSr+s r$header_distancezSection.header_distances|""r%c||j_dSrrUr/s r$rVzSection.header_distancerMr%Iterator[Paragraph | Table]c#K|jD]9}t|trt ||nt ||V:dS)zlGenerate each Paragraph or Table object in this `section`. Items appear in document order. N)r iter_inner_content isinstancer rr)r"elements r$rZzSection.iter_inner_contentsl |6688 d dG/9'4/H/Hb9Wd+++eT[]aNbNb c c c c d dr%c|jjS)zk|Length| object representing the left margin for all pages in this section in English Metric Units.r left_marginr+s r$r_zSection.left_margins|''r%c||j_dSrr^r/s r$r_zSection.left_marginr6r%rc|jjS)z:ref:`WdOrientation` member specifying page orientation for this section. One of ``WD_ORIENT.PORTRAIT`` or ``WD_ORIENT.LANDSCAPE``. r orientationr+s r$rczSection.orientations |''r%WD_ORIENTATION | Nonec||j_dSrrbr/s r$rczSection.orientationr6r%c|jjS)a)Total page height used for this section. This value is 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+s r$rhzSection.page_heights|''r%c||j_dSrrgr/s r$rhzSection.page_heightr6r%c|jjS)aATotal page width used for this section. This value is like "paper size" and includes 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+s r$rlzSection.page_widths|&&r%c||j_dSrrkr/s r$rlzSection.page_width"' r%rc|jSr)r!r+s r$partz Section.parts ""r%c|jjS)zl|Length| object representing the right margin for all pages in this section in English Metric Units.r right_marginr+s r$rszSection.right_margins|((r%c||j_dSrrrr/s r$rszSection.right_margins$) !!!r%rc|jjS)zType of page-break (if any) inserted at the start of this section. For exmple, ``WD_SECTION_START.ODD_PAGE`` if the section should begin on the next odd page, possibly inserting two page-breaks instead of one. r start_typer+s r$rwzSection.start_types|&&r%WD_SECTION_START | Nonec||j_dSrrvr/s r$rwzSection.start_typernr%c|jjS)zj|Length| object representing the top margin for all pages in this section in English Metric Units.r top_marginr+s r$r|zSection.top_margins|&&r%c||j_dSrr{r/s r$r|zSection.top_marginrnr%)rrrr)r&r')r,r-r&r0)r,r0)r&r7)r&r<)r&rX)r&r)r,rd)r,r')r&r)r&r)r,rx)__name__ __module__ __qualname____doc__rpropertyr*setterr4r:r>rArDrrGrKrPrSrVrZr_rcrhrlrprsrwr| __classcell__r#s@r$rrs ,,,,,, ***X*++++(((X((.)))/.)VVVXVVVVXVWWWXWWWWXWTTT\T###X#$$$$ # # #X # ]$$$]$TTT\T###X#$$$$dddd(((X( ))))(((X())))(((X()))) ' ' 'X '((((###X#)))X) ****'''X'(((('''X' ((((((((r%rcleZdZdZdfd Zedd ZeddZddZddZddZxZ S)SectionszSequence of |Section| objects corresponding to the sections in the document. Supports ``len()``, iteration, and indexed access. document_elmrrrcrtt|||_||_dSr)rrr _document_elmr!)r"rrr#s r$rzSections.__init__s5 h&&((()+r%keyintr&rcdSrr"rs r$ __getitem__zSections.__getitem__ s03r%slice List[Section]cdSrrrs r$rzSections.__getitem__s8;r% int | sliceSection | List[Section]ct|trfdjj|DSt jj|jS)Nc:g|]}t|jSr)rr!).0rr"s r$ z(Sections.__getitem__..s6 344r%)r[rr sectPr_lstrr!rs` r$rzSections.__getitem__sk c5 ! ! "0;C@ t)4S94;NOOOr%Iterator[Section]c#VK|jjD]}t||jVdSr)rrrr!)r"rs r$__iter__zSections.__iter__sA(3 7 7F&$"566 6 6 6 6 7 7r%c4t|jjSr)lenrrr+s r$__len__zSections.__len__s4%0111r%)rrrr)rrr&r)rrr&r)rrr&r)r&r)r&r) rrrrrrrrrrrs@r$rrs ,,,,,, 333X3 ;;;X;PPPP777722222222r%rceZdZdZddZedd ZejddZeddZddZ eddZ ddZ edZ ddZ eddZeddZdS) _BaseHeaderFooterz)Base class for header and footer classes.rrrrheader_footer_indexr c0||_||_||_dSr)r r! _hdrftr_index)r"rrrs r$rz_BaseHeaderFooter.__init__$s!  +0r%r&r0c|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+s r$is_linked_to_previousz'_BaseHeaderFooter.is_linked_to_previous.s'''r%r,Nonect|}||jkrdS|dur|dS|dS)NT)r0r_drop_definition_add_definition)r"r, new_states r$rz'_BaseHeaderFooter.is_linked_to_previous<s[KK 2 2 2 F     ! ! # # # # #  " " " " "r%HeaderPart | FooterPartc*|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+s r$rpz_BaseHeaderFooter.partGs**,,,r%c td)z&Return newly-added header/footer part.$must be implemented by each subclassNotImplementedErrorr+s r$rz!_BaseHeaderFooter._add_definitionR!"HIIIr%c td)zE|HeaderPart| or |FooterPart| object containing header/footer content.rrr+s r$ _definitionz_BaseHeaderFooter._definitionV""HIIIr%c td)zJRemove header/footer part containing the definition of this header/footer.rrr+s r$rz"_BaseHeaderFooter._drop_definition[rr%c4|jS)z7`w:hdr` or `w:ftr` element, root of header/footer part.)rr\r+s r$_elementz_BaseHeaderFooter._element_s**,,44r%c|jr|jS|j}|r|S|S)aReturn 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. )rr_prior_headerfooterrr)r"prior_headerfooters r$rz(_BaseHeaderFooter._get_or_add_definitiondsM   $# #!5  ?%<<>> >##%%%r%c td)zHTrue if this header/footer has a related part containing its definition.rrr+s r$rz!_BaseHeaderFooter._has_definitionxrr%_Header | _Footer | Nonec td)zn|_Header| or |_Footer| proxy on prior sectPr element. Returns None if this is first section. rrr+s r$rz%_BaseHeaderFooter._prior_headerfooter}s ""HIIIr%N)rrrrrr r~)r,r0r&r)r&r)r&r)r&r)rrrrrrrrrprrrrrrrrr%r$rr!s_331111 ( ( (X (!###"!#---X-JJJJJJJXJJJJJ55X5&&&&(JJJXJJJJXJJJr%rcdeZdZdZd dZedZdZed dZed Z d S) r7aPage 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. r&r c~|j\}}|j|j||S)zReturn newly-added footer part.)r!add_footer_partr add_footerReferencer)r" footer_partrIds r$rz_Footer._add_definition<.>>@@ S (();SAAAr%c|j|j}|J|j|jS)z6|FooterPart| object containing content of this footer.)r get_footerReferencerr!rrr"footerReferences r$rz_Footer._definitionB,::4;MNN***"../BCCCr%cx|j|j}|j|dS)zDRemove footer definition (footer part) associated with this section.N)r remove_footerReferencerr!drop_relr"rs r$rz_Footer._drop_definitions7l11$2DEE $$S)))))r%r0cH|j|j}|duS)z-True if a footer is defined for this section.N)r rrrs r$rz_Footer._has_definition',::4;MNNd**r%cX|jj}|dnt||j|jS)zI|_Footer| proxy on prior sectPr element or None if this is first section.N)r preceding_sectPrr7r!rr"rs r$rz_Footer._prior_headerfooter9 <8 ' D)4+>@RSS r%N)r&r r~ rrrrrrrrrrrr%r$r7r7s DDXD*** +++X+   X   r%r7cbeZdZdZdZedZdZed dZedZ d S) r<aPage 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~|j\}}|j|j||S)zReturn newly-added header part.)r!add_header_partr add_headerReferencer)r" header_partrs r$rz_Header._add_definitionrr%c|j|j}|J|j|jS)z6|HeaderPart| object containing content of this header.)r get_headerReferencerr!rrr"headerReferences r$rz_Header._definitionrr%cx|j|j}|j|dS)z6Remove header definition associated with this section.N)r remove_headerReferencerr!drop_header_partrs r$rz_Header._drop_definitions7l11$2DEE ,,S11111r%r&r0cH|j|j}|duS)z8True if a header is explicitly defined for this section.N)r rrrs r$rz_Header._has_definitionrr%cX|jj}|dnt||j|jS)zI|_Header| proxy on prior sectPr element or None if this is first section.N)r rr<r!rrs r$rz_Header._prior_headerfooterrr%Nr~rrr%r$r<r<s DDXD222 +++X+   X   r%r<N)(r __future__rtypingrrrrr docx.blkcntnrr docx.enum.sectionr docx.oxml.text.paragraphr docx.parts.hdrftrr r docx.sharedr docx.tablerdocx.text.paragraphrrrdocx.oxml.documentrdocx.oxml.sectionrdocx.parts.documentrdocx.parts.storyrrrrrr7r<rr%r$rsC55""""""DDDDDDDDDDDDDD,,,,,,......))))))44444444$$$$$$))))))#BBBBBBBB......++++++000000******""""""e(e(e(e(e(e(e(e(P22222x 222BbJbJbJbJbJ*bJbJbJJ+ + + + + + + + \+ + + + + + + + + + r%