|
8 | 8 |
|
9 | 9 | from copy import deepcopy |
10 | 10 |
|
| 11 | +from ..enum.header import WD_HEADER_FOOTER |
11 | 12 | from ..enum.section import WD_ORIENTATION, WD_SECTION_START |
12 | 13 | from .simpletypes import ST_SignedTwipsMeasure, ST_TwipsMeasure |
13 | | -from .xmlchemy import BaseOxmlElement, OptionalAttribute, ZeroOrOne |
| 14 | +from .xmlchemy import ( |
| 15 | + BaseOxmlElement, OptionalAttribute, ZeroOrMore, ZeroOrOne |
| 16 | +) |
14 | 17 |
|
15 | 18 |
|
16 | 19 | class CT_PageMar(BaseOxmlElement): |
@@ -41,22 +44,18 @@ class CT_SectPr(BaseOxmlElement): |
41 | 44 | """ |
42 | 45 | ``<w:sectPr>`` element, the container element for section properties. |
43 | 46 | """ |
44 | | - __child_sequence__ = ( |
45 | | - 'w:footnotePr', 'w:endnotePr', 'w:type', 'w:pgSz', 'w:pgMar', |
46 | | - 'w:paperSrc', 'w:pgBorders', 'w:lnNumType', 'w:pgNumType', 'w:cols', |
47 | | - 'w:formProt', 'w:vAlign', 'w:noEndnote', 'w:titlePg', |
48 | | - 'w:textDirection', 'w:bidi', 'w:rtlGutter', 'w:docGrid', |
49 | | - 'w:printerSettings', 'w:sectPrChange', |
| 47 | + _tag_seq = ( |
| 48 | + 'w:headerReference', 'w:footerReference', 'w:footnotePr', |
| 49 | + 'w:endnotePr', 'w:type', 'w:pgSz', 'w:pgMar', 'w:paperSrc', |
| 50 | + 'w:pgBorders', 'w:lnNumType', 'w:pgNumType', 'w:cols', 'w:formProt', |
| 51 | + 'w:vAlign', 'w:noEndnote', 'w:titlePg', 'w:textDirection', 'w:bidi', |
| 52 | + 'w:rtlGutter', 'w:docGrid', 'w:printerSettings', 'w:sectPrChange', |
50 | 53 | ) |
51 | | - type = ZeroOrOne('w:type', successors=( |
52 | | - __child_sequence__[__child_sequence__.index('w:type')+1:] |
53 | | - )) |
54 | | - pgSz = ZeroOrOne('w:pgSz', successors=( |
55 | | - __child_sequence__[__child_sequence__.index('w:pgSz')+1:] |
56 | | - )) |
57 | | - pgMar = ZeroOrOne('w:pgMar', successors=( |
58 | | - __child_sequence__[__child_sequence__.index('w:pgMar')+1:] |
59 | | - )) |
| 54 | + headerReference = ZeroOrMore('w:headerReference', successors=_tag_seq[1:]) |
| 55 | + type = ZeroOrOne('w:type', successors=_tag_seq[5:]) |
| 56 | + pgSz = ZeroOrOne('w:pgSz', successors=_tag_seq[6:]) |
| 57 | + pgMar = ZeroOrOne('w:pgMar', successors=_tag_seq[7:]) |
| 58 | + del _tag_seq |
60 | 59 |
|
61 | 60 | @property |
62 | 61 | def bottom_margin(self): |
@@ -102,6 +101,17 @@ def footer(self, value): |
102 | 101 | pgMar = self.get_or_add_pgMar() |
103 | 102 | pgMar.footer = value |
104 | 103 |
|
| 104 | + def get_headerReference_of_type(self, type_member): |
| 105 | + """ |
| 106 | + Return the `w:headerReference` child having type attribute value |
| 107 | + associated with *type_member*, or |None| if not present. |
| 108 | + """ |
| 109 | + type_str = WD_HEADER_FOOTER.to_xml(type_member) |
| 110 | + matches = self.xpath('w:headerReference[@w:type="%s"]' % type_str) |
| 111 | + if matches: |
| 112 | + return matches[0] |
| 113 | + return None |
| 114 | + |
105 | 115 | @property |
106 | 116 | def gutter(self): |
107 | 117 | """ |
|
0 commit comments