-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hdr: add Settings.odd_and_even_pages_header_footer
Getter side.
- Loading branch information
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# encoding: utf-8 | ||
|
||
"""Custom element classes related to document settings""" | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from docx.oxml.xmlchemy import BaseOxmlElement, ZeroOrOne | ||
|
||
|
||
class CT_Settings(BaseOxmlElement): | ||
"""`w:settings` element, root element for the settings part""" | ||
|
||
_tag_seq = ( | ||
"w:writeProtection", "w:view", "w:zoom", "w:removePersonalInformation", | ||
"w:removeDateAndTime", "w:doNotDisplayPageBoundaries", | ||
"w:displayBackgroundShape", "w:printPostScriptOverText", | ||
"w:printFractionalCharacterWidth", "w:printFormsData", "w:embedTrueTypeFonts", | ||
"w:embedSystemFonts", "w:saveSubsetFonts", "w:saveFormsData", "w:mirrorMargins", | ||
"w:alignBordersAndEdges", "w:bordersDoNotSurroundHeader", | ||
"w:bordersDoNotSurroundFooter", "w:gutterAtTop", "w:hideSpellingErrors", | ||
"w:hideGrammaticalErrors", "w:activeWritingStyle", "w:proofState", | ||
"w:formsDesign", "w:attachedTemplate", "w:linkStyles", | ||
"w:stylePaneFormatFilter", "w:stylePaneSortMethod", "w:documentType", | ||
"w:mailMerge", "w:revisionView", "w:trackRevisions", "w:doNotTrackMoves", | ||
"w:doNotTrackFormatting", "w:documentProtection", "w:autoFormatOverride", | ||
"w:styleLockTheme", "w:styleLockQFSet", "w:defaultTabStop", "w:autoHyphenation", | ||
"w:consecutiveHyphenLimit", "w:hyphenationZone", "w:doNotHyphenateCaps", | ||
"w:showEnvelope", "w:summaryLength", "w:clickAndTypeStyle", | ||
"w:defaultTableStyle", "w:evenAndOddHeaders", "w:bookFoldRevPrinting", | ||
"w:bookFoldPrinting", "w:bookFoldPrintingSheets", | ||
"w:drawingGridHorizontalSpacing", "w:drawingGridVerticalSpacing", | ||
"w:displayHorizontalDrawingGridEvery", "w:displayVerticalDrawingGridEvery", | ||
"w:doNotUseMarginsForDrawingGridOrigin", "w:drawingGridHorizontalOrigin", | ||
"w:drawingGridVerticalOrigin", "w:doNotShadeFormData", "w:noPunctuationKerning", | ||
"w:characterSpacingControl", "w:printTwoOnOne", "w:strictFirstAndLastChars", | ||
"w:noLineBreaksAfter", "w:noLineBreaksBefore", "w:savePreviewPicture", | ||
"w:doNotValidateAgainstSchema", "w:saveInvalidXml", "w:ignoreMixedContent", | ||
"w:alwaysShowPlaceholderText", "w:doNotDemarcateInvalidXml", | ||
"w:saveXmlDataOnly", "w:useXSLTWhenSaving", "w:saveThroughXslt", | ||
"w:showXMLTags", "w:alwaysMergeEmptyNamespace", "w:updateFields", | ||
"w:hdrShapeDefaults", "w:footnotePr", "w:endnotePr", "w:compat", "w:docVars", | ||
"w:rsids", "m:mathPr", "w:attachedSchema", "w:themeFontLang", | ||
"w:clrSchemeMapping", "w:doNotIncludeSubdocsInStats", | ||
"w:doNotAutoCompressPictures", "w:forceUpgrade", "w:captions", | ||
"w:readModeInkLockDown", "w:smartTagType", "sl:schemaLibrary", | ||
"w:shapeDefaults", "w:doNotEmbedSmartTags", "w:decimalSymbol", "w:listSeparator" | ||
) | ||
evenAndOddHeaders = ZeroOrOne("w:evenAndOddHeaders", successors=_tag_seq[48:]) | ||
del _tag_seq | ||
|
||
@property | ||
def evenAndOddHeaders_val(self): | ||
"""value of `w:evenAndOddHeaders/@w:val` or |None| if not present.""" | ||
evenAndOddHeaders = self.evenAndOddHeaders | ||
if evenAndOddHeaders is None: | ||
return False | ||
return evenAndOddHeaders.val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# encoding: utf-8 | ||
|
||
"""Unit test suite for the docx.settings module""" | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import pytest | ||
|
||
from docx.settings import Settings | ||
|
||
from .unitutil.cxml import element | ||
|
||
|
||
class DescribeSettings(object): | ||
|
||
def it_knows_when_the_document_has_distinct_odd_and_even_headers( | ||
self, odd_and_even_get_fixture | ||
): | ||
settings_elm, expected_value = odd_and_even_get_fixture | ||
settings = Settings(settings_elm) | ||
|
||
odd_and_even_pages_header_footer = settings.odd_and_even_pages_header_footer | ||
|
||
assert odd_and_even_pages_header_footer is expected_value | ||
|
||
# fixtures ------------------------------------------------------- | ||
|
||
@pytest.fixture( | ||
params=[ | ||
("w:settings", False), | ||
("w:settings/w:evenAndOddHeaders", True), | ||
("w:settings/w:evenAndOddHeaders{w:val=0}", False), | ||
("w:settings/w:evenAndOddHeaders{w:val=1}", True), | ||
("w:settings/w:evenAndOddHeaders{w:val=true}", True), | ||
] | ||
) | ||
def odd_and_even_get_fixture(self, request): | ||
settings_cxml, expected_value = request.param | ||
settings_elm = element(settings_cxml) | ||
return settings_elm, expected_value |