ps-python-docx 1.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docx/__init__.py +68 -0
- docx/api.py +37 -0
- docx/blkcntnr.py +101 -0
- docx/comments.py +163 -0
- docx/dml/__init__.py +0 -0
- docx/dml/color.py +112 -0
- docx/document.py +275 -0
- docx/drawing/__init__.py +59 -0
- docx/enum/__init__.py +0 -0
- docx/enum/base.py +150 -0
- docx/enum/dml.py +103 -0
- docx/enum/section.py +86 -0
- docx/enum/shape.py +19 -0
- docx/enum/style.py +452 -0
- docx/enum/table.py +136 -0
- docx/enum/text.py +367 -0
- docx/exceptions.py +18 -0
- docx/image/__init__.py +23 -0
- docx/image/bmp.py +43 -0
- docx/image/constants.py +172 -0
- docx/image/exceptions.py +13 -0
- docx/image/gif.py +38 -0
- docx/image/helpers.py +86 -0
- docx/image/image.py +234 -0
- docx/image/jpeg.py +425 -0
- docx/image/png.py +253 -0
- docx/image/tiff.py +289 -0
- docx/opc/__init__.py +0 -0
- docx/opc/constants.py +306 -0
- docx/opc/coreprops.py +142 -0
- docx/opc/exceptions.py +12 -0
- docx/opc/oxml.py +247 -0
- docx/opc/package.py +219 -0
- docx/opc/packuri.py +109 -0
- docx/opc/part.py +247 -0
- docx/opc/parts/__init__.py +0 -0
- docx/opc/parts/coreprops.py +48 -0
- docx/opc/phys_pkg.py +119 -0
- docx/opc/pkgreader.py +254 -0
- docx/opc/pkgwriter.py +115 -0
- docx/opc/rel.py +153 -0
- docx/opc/shared.py +31 -0
- docx/opc/spec.py +24 -0
- docx/oxml/__init__.py +261 -0
- docx/oxml/comments.py +124 -0
- docx/oxml/coreprops.py +298 -0
- docx/oxml/document.py +88 -0
- docx/oxml/drawing.py +11 -0
- docx/oxml/exceptions.py +10 -0
- docx/oxml/ns.py +109 -0
- docx/oxml/numbering.py +109 -0
- docx/oxml/parser.py +62 -0
- docx/oxml/section.py +537 -0
- docx/oxml/settings.py +138 -0
- docx/oxml/shape.py +299 -0
- docx/oxml/shared.py +52 -0
- docx/oxml/simpletypes.py +434 -0
- docx/oxml/styles.py +341 -0
- docx/oxml/table.py +977 -0
- docx/oxml/text/__init__.py +0 -0
- docx/oxml/text/font.py +333 -0
- docx/oxml/text/hyperlink.py +45 -0
- docx/oxml/text/pagebreak.py +278 -0
- docx/oxml/text/paragraph.py +106 -0
- docx/oxml/text/parfmt.py +392 -0
- docx/oxml/text/run.py +307 -0
- docx/oxml/xmlchemy.py +696 -0
- docx/package.py +110 -0
- docx/parts/__init__.py +0 -0
- docx/parts/comments.py +51 -0
- docx/parts/document.py +182 -0
- docx/parts/hdrftr.py +53 -0
- docx/parts/image.py +80 -0
- docx/parts/numbering.py +32 -0
- docx/parts/settings.py +50 -0
- docx/parts/story.py +95 -0
- docx/parts/styles.py +42 -0
- docx/parts/theme.py +53 -0
- docx/py.typed +0 -0
- docx/section.py +479 -0
- docx/settings.py +35 -0
- docx/shape.py +103 -0
- docx/shared.py +382 -0
- docx/styles/__init__.py +40 -0
- docx/styles/latent.py +198 -0
- docx/styles/style.py +264 -0
- docx/styles/styles.py +147 -0
- docx/table.py +537 -0
- docx/templates/default-comments.xml +12 -0
- docx/templates/default-docx-template/[Content_Types].xml +17 -0
- docx/templates/default-docx-template/_rels/.rels +7 -0
- docx/templates/default-docx-template/customXml/_rels/item1.xml.rels +4 -0
- docx/templates/default-docx-template/customXml/item1.xml +2 -0
- docx/templates/default-docx-template/customXml/itemProps1.xml +6 -0
- docx/templates/default-docx-template/docProps/app.xml +36 -0
- docx/templates/default-docx-template/docProps/core.xml +13 -0
- docx/templates/default-docx-template/docProps/thumbnail.jpeg +0 -0
- docx/templates/default-docx-template/word/_rels/document.xml.rels +11 -0
- docx/templates/default-docx-template/word/document.xml +11 -0
- docx/templates/default-docx-template/word/fontTable.xml +61 -0
- docx/templates/default-docx-template/word/numbering.xml +201 -0
- docx/templates/default-docx-template/word/settings.xml +53 -0
- docx/templates/default-docx-template/word/styles.xml +11844 -0
- docx/templates/default-docx-template/word/stylesWithEffects.xml +11800 -0
- docx/templates/default-docx-template/word/theme/theme1.xml +318 -0
- docx/templates/default-docx-template/word/webSettings.xml +5 -0
- docx/templates/default-footer.xml +27 -0
- docx/templates/default-header.xml +27 -0
- docx/templates/default-settings.xml +26 -0
- docx/templates/default-styles.xml +190 -0
- docx/templates/default.docx +0 -0
- docx/text/__init__.py +0 -0
- docx/text/font.py +472 -0
- docx/text/hyperlink.py +121 -0
- docx/text/pagebreak.py +104 -0
- docx/text/paragraph.py +173 -0
- docx/text/parfmt.py +286 -0
- docx/text/run.py +257 -0
- docx/text/tabstops.py +123 -0
- docx/theme.py +67 -0
- docx/types.py +34 -0
- ps_python_docx-1.3.0.dist-info/METADATA +77 -0
- ps_python_docx-1.3.0.dist-info/RECORD +126 -0
- ps_python_docx-1.3.0.dist-info/WHEEL +5 -0
- ps_python_docx-1.3.0.dist-info/licenses/LICENSE +20 -0
- ps_python_docx-1.3.0.dist-info/top_level.txt +1 -0
docx/text/paragraph.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Paragraph-related proxy types."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING, Iterator, List, cast
|
|
6
|
+
|
|
7
|
+
from docx.enum.style import WD_STYLE_TYPE
|
|
8
|
+
from docx.oxml.text.run import CT_R
|
|
9
|
+
from docx.shared import StoryChild
|
|
10
|
+
from docx.styles.style import ParagraphStyle
|
|
11
|
+
from docx.text.hyperlink import Hyperlink
|
|
12
|
+
from docx.text.pagebreak import RenderedPageBreak
|
|
13
|
+
from docx.text.parfmt import ParagraphFormat
|
|
14
|
+
from docx.text.run import Run
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
import docx.types as t
|
|
18
|
+
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
|
19
|
+
from docx.oxml.text.paragraph import CT_P
|
|
20
|
+
from docx.styles.style import CharacterStyle
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Paragraph(StoryChild):
|
|
24
|
+
"""Proxy object wrapping a `<w:p>` element."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, p: CT_P, parent: t.ProvidesStoryPart):
|
|
27
|
+
super(Paragraph, self).__init__(parent)
|
|
28
|
+
self._p = self._element = p
|
|
29
|
+
|
|
30
|
+
def add_run(self, text: str | None = None, style: str | CharacterStyle | None = None) -> Run:
|
|
31
|
+
"""Append run containing `text` and having character-style `style`.
|
|
32
|
+
|
|
33
|
+
`text` can contain tab (``\\t``) characters, which are converted to the
|
|
34
|
+
appropriate XML form for a tab. `text` can also include newline (``\\n``) or
|
|
35
|
+
carriage return (``\\r``) characters, each of which is converted to a line
|
|
36
|
+
break. When `text` is `None`, the new run is empty.
|
|
37
|
+
"""
|
|
38
|
+
r = self._p.add_r()
|
|
39
|
+
run = Run(r, self)
|
|
40
|
+
if text:
|
|
41
|
+
run.text = text
|
|
42
|
+
if style:
|
|
43
|
+
run.style = style
|
|
44
|
+
return run
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def alignment(self) -> WD_PARAGRAPH_ALIGNMENT | None:
|
|
48
|
+
"""A member of the :ref:`WdParagraphAlignment` enumeration specifying the
|
|
49
|
+
justification setting for this paragraph.
|
|
50
|
+
|
|
51
|
+
A value of |None| indicates the paragraph has no directly-applied alignment
|
|
52
|
+
value and will inherit its alignment value from its style hierarchy. Assigning
|
|
53
|
+
|None| to this property removes any directly-applied alignment value.
|
|
54
|
+
"""
|
|
55
|
+
return self._p.alignment
|
|
56
|
+
|
|
57
|
+
@alignment.setter
|
|
58
|
+
def alignment(self, value: WD_PARAGRAPH_ALIGNMENT):
|
|
59
|
+
self._p.alignment = value
|
|
60
|
+
|
|
61
|
+
def clear(self):
|
|
62
|
+
"""Return this same paragraph after removing all its content.
|
|
63
|
+
|
|
64
|
+
Paragraph-level formatting, such as style, is preserved.
|
|
65
|
+
"""
|
|
66
|
+
self._p.clear_content()
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def contains_page_break(self) -> bool:
|
|
71
|
+
"""`True` when one or more rendered page-breaks occur in this paragraph."""
|
|
72
|
+
return bool(self._p.lastRenderedPageBreaks)
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def hyperlinks(self) -> List[Hyperlink]:
|
|
76
|
+
"""A |Hyperlink| instance for each hyperlink in this paragraph."""
|
|
77
|
+
return [Hyperlink(hyperlink, self) for hyperlink in self._p.hyperlink_lst]
|
|
78
|
+
|
|
79
|
+
def insert_paragraph_before(
|
|
80
|
+
self, text: str | None = None, style: str | ParagraphStyle | None = None
|
|
81
|
+
) -> Paragraph:
|
|
82
|
+
"""Return a newly created paragraph, inserted directly before this paragraph.
|
|
83
|
+
|
|
84
|
+
If `text` is supplied, the new paragraph contains that text in a single run. If
|
|
85
|
+
`style` is provided, that style is assigned to the new paragraph.
|
|
86
|
+
"""
|
|
87
|
+
paragraph = self._insert_paragraph_before()
|
|
88
|
+
if text:
|
|
89
|
+
paragraph.add_run(text)
|
|
90
|
+
if style is not None:
|
|
91
|
+
paragraph.style = style
|
|
92
|
+
return paragraph
|
|
93
|
+
|
|
94
|
+
def iter_inner_content(self) -> Iterator[Run | Hyperlink]:
|
|
95
|
+
"""Generate the runs and hyperlinks in this paragraph, in the order they appear.
|
|
96
|
+
|
|
97
|
+
The content in a paragraph consists of both runs and hyperlinks. This method
|
|
98
|
+
allows accessing each of those separately, in document order, for when the
|
|
99
|
+
precise position of the hyperlink within the paragraph text is important. Note
|
|
100
|
+
that a hyperlink itself contains runs.
|
|
101
|
+
"""
|
|
102
|
+
for r_or_hlink in self._p.inner_content_elements:
|
|
103
|
+
yield (
|
|
104
|
+
Run(r_or_hlink, self)
|
|
105
|
+
if isinstance(r_or_hlink, CT_R)
|
|
106
|
+
else Hyperlink(r_or_hlink, self)
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def paragraph_format(self):
|
|
111
|
+
"""The |ParagraphFormat| object providing access to the formatting properties
|
|
112
|
+
for this paragraph, such as line spacing and indentation."""
|
|
113
|
+
return ParagraphFormat(self._element)
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def rendered_page_breaks(self) -> List[RenderedPageBreak]:
|
|
117
|
+
"""All rendered page-breaks in this paragraph.
|
|
118
|
+
|
|
119
|
+
Most often an empty list, sometimes contains one page-break, but can contain
|
|
120
|
+
more than one is rare or contrived cases.
|
|
121
|
+
"""
|
|
122
|
+
return [RenderedPageBreak(lrpb, self) for lrpb in self._p.lastRenderedPageBreaks]
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def runs(self) -> List[Run]:
|
|
126
|
+
"""Sequence of |Run| instances corresponding to the <w:r> elements in this
|
|
127
|
+
paragraph."""
|
|
128
|
+
return [Run(r, self) for r in self._p.r_lst]
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def style(self) -> ParagraphStyle | None:
|
|
132
|
+
"""Read/Write.
|
|
133
|
+
|
|
134
|
+
|_ParagraphStyle| object representing the style assigned to this paragraph. If
|
|
135
|
+
no explicit style is assigned to this paragraph, its value is the default
|
|
136
|
+
paragraph style for the document. A paragraph style name can be assigned in lieu
|
|
137
|
+
of a paragraph style object. Assigning |None| removes any applied style, making
|
|
138
|
+
its effective value the default paragraph style for the document.
|
|
139
|
+
"""
|
|
140
|
+
style_id = self._p.style
|
|
141
|
+
style = self.part.get_style(style_id, WD_STYLE_TYPE.PARAGRAPH)
|
|
142
|
+
return cast(ParagraphStyle, style)
|
|
143
|
+
|
|
144
|
+
@style.setter
|
|
145
|
+
def style(self, style_or_name: str | ParagraphStyle | None):
|
|
146
|
+
style_id = self.part.get_style_id(style_or_name, WD_STYLE_TYPE.PARAGRAPH)
|
|
147
|
+
self._p.style = style_id
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def text(self) -> str:
|
|
151
|
+
"""The textual content of this paragraph.
|
|
152
|
+
|
|
153
|
+
The text includes the visible-text portion of any hyperlinks in the paragraph.
|
|
154
|
+
Tabs and line breaks in the XML are mapped to ``\\t`` and ``\\n`` characters
|
|
155
|
+
respectively.
|
|
156
|
+
|
|
157
|
+
Assigning text to this property causes all existing paragraph content to be
|
|
158
|
+
replaced with a single run containing the assigned text. A ``\\t`` character in
|
|
159
|
+
the text is mapped to a ``<w:tab/>`` element and each ``\\n`` or ``\\r``
|
|
160
|
+
character is mapped to a line break. Paragraph-level formatting, such as style,
|
|
161
|
+
is preserved. All run-level formatting, such as bold or italic, is removed.
|
|
162
|
+
"""
|
|
163
|
+
return self._p.text
|
|
164
|
+
|
|
165
|
+
@text.setter
|
|
166
|
+
def text(self, text: str | None):
|
|
167
|
+
self.clear()
|
|
168
|
+
self.add_run(text)
|
|
169
|
+
|
|
170
|
+
def _insert_paragraph_before(self):
|
|
171
|
+
"""Return a newly created paragraph, inserted directly before this paragraph."""
|
|
172
|
+
p = self._p.add_p_before()
|
|
173
|
+
return Paragraph(p, self._parent)
|
docx/text/parfmt.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"""Paragraph-related proxy types."""
|
|
2
|
+
|
|
3
|
+
from docx.enum.text import WD_LINE_SPACING
|
|
4
|
+
from docx.shared import ElementProxy, Emu, Length, Pt, Twips, lazyproperty
|
|
5
|
+
from docx.text.tabstops import TabStops
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ParagraphFormat(ElementProxy):
|
|
9
|
+
"""Provides access to paragraph formatting such as justification, indentation, line
|
|
10
|
+
spacing, space before and after, and widow/orphan control."""
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def alignment(self):
|
|
14
|
+
"""A member of the :ref:`WdParagraphAlignment` enumeration specifying the
|
|
15
|
+
justification setting for this paragraph.
|
|
16
|
+
|
|
17
|
+
A value of |None| indicates paragraph alignment is inherited from the style
|
|
18
|
+
hierarchy.
|
|
19
|
+
"""
|
|
20
|
+
pPr = self._element.pPr
|
|
21
|
+
if pPr is None:
|
|
22
|
+
return None
|
|
23
|
+
return pPr.jc_val
|
|
24
|
+
|
|
25
|
+
@alignment.setter
|
|
26
|
+
def alignment(self, value):
|
|
27
|
+
pPr = self._element.get_or_add_pPr()
|
|
28
|
+
pPr.jc_val = value
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def first_line_indent(self):
|
|
32
|
+
"""|Length| value specifying the relative difference in indentation for the
|
|
33
|
+
first line of the paragraph.
|
|
34
|
+
|
|
35
|
+
A positive value causes the first line to be indented. A negative value produces
|
|
36
|
+
a hanging indent. |None| indicates first line indentation is inherited from the
|
|
37
|
+
style hierarchy.
|
|
38
|
+
"""
|
|
39
|
+
pPr = self._element.pPr
|
|
40
|
+
if pPr is None:
|
|
41
|
+
return None
|
|
42
|
+
return pPr.first_line_indent
|
|
43
|
+
|
|
44
|
+
@first_line_indent.setter
|
|
45
|
+
def first_line_indent(self, value):
|
|
46
|
+
pPr = self._element.get_or_add_pPr()
|
|
47
|
+
pPr.first_line_indent = value
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def keep_together(self):
|
|
51
|
+
"""|True| if the paragraph should be kept "in one piece" and not broken across a
|
|
52
|
+
page boundary when the document is rendered.
|
|
53
|
+
|
|
54
|
+
|None| indicates its effective value is inherited from the style hierarchy.
|
|
55
|
+
"""
|
|
56
|
+
pPr = self._element.pPr
|
|
57
|
+
if pPr is None:
|
|
58
|
+
return None
|
|
59
|
+
return pPr.keepLines_val
|
|
60
|
+
|
|
61
|
+
@keep_together.setter
|
|
62
|
+
def keep_together(self, value):
|
|
63
|
+
self._element.get_or_add_pPr().keepLines_val = value
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def keep_with_next(self):
|
|
67
|
+
"""|True| if the paragraph should be kept on the same page as the subsequent
|
|
68
|
+
paragraph when the document is rendered.
|
|
69
|
+
|
|
70
|
+
For example, this property could be used to keep a section heading on the same
|
|
71
|
+
page as its first paragraph. |None| indicates its effective value is inherited
|
|
72
|
+
from the style hierarchy.
|
|
73
|
+
"""
|
|
74
|
+
pPr = self._element.pPr
|
|
75
|
+
if pPr is None:
|
|
76
|
+
return None
|
|
77
|
+
return pPr.keepNext_val
|
|
78
|
+
|
|
79
|
+
@keep_with_next.setter
|
|
80
|
+
def keep_with_next(self, value):
|
|
81
|
+
self._element.get_or_add_pPr().keepNext_val = value
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def left_indent(self):
|
|
85
|
+
"""|Length| value specifying the space between the left margin and the left side
|
|
86
|
+
of the paragraph.
|
|
87
|
+
|
|
88
|
+
|None| indicates the left indent value is inherited from the style hierarchy.
|
|
89
|
+
Use an |Inches| value object as a convenient way to apply indentation in units
|
|
90
|
+
of inches.
|
|
91
|
+
"""
|
|
92
|
+
pPr = self._element.pPr
|
|
93
|
+
if pPr is None:
|
|
94
|
+
return None
|
|
95
|
+
return pPr.ind_left
|
|
96
|
+
|
|
97
|
+
@left_indent.setter
|
|
98
|
+
def left_indent(self, value):
|
|
99
|
+
pPr = self._element.get_or_add_pPr()
|
|
100
|
+
pPr.ind_left = value
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def line_spacing(self):
|
|
104
|
+
"""|float| or |Length| value specifying the space between baselines in
|
|
105
|
+
successive lines of the paragraph.
|
|
106
|
+
|
|
107
|
+
A value of |None| indicates line spacing is inherited from the style hierarchy.
|
|
108
|
+
A float value, e.g. ``2.0`` or ``1.75``, indicates spacing is applied in
|
|
109
|
+
multiples of line heights. A |Length| value such as ``Pt(12)`` indicates spacing
|
|
110
|
+
is a fixed height. The |Pt| value class is a convenient way to apply line
|
|
111
|
+
spacing in units of points. Assigning |None| resets line spacing to inherit from
|
|
112
|
+
the style hierarchy.
|
|
113
|
+
"""
|
|
114
|
+
pPr = self._element.pPr
|
|
115
|
+
if pPr is None:
|
|
116
|
+
return None
|
|
117
|
+
return self._line_spacing(pPr.spacing_line, pPr.spacing_lineRule)
|
|
118
|
+
|
|
119
|
+
@line_spacing.setter
|
|
120
|
+
def line_spacing(self, value):
|
|
121
|
+
pPr = self._element.get_or_add_pPr()
|
|
122
|
+
if value is None:
|
|
123
|
+
pPr.spacing_line = None
|
|
124
|
+
pPr.spacing_lineRule = None
|
|
125
|
+
elif isinstance(value, Length):
|
|
126
|
+
pPr.spacing_line = value
|
|
127
|
+
if pPr.spacing_lineRule != WD_LINE_SPACING.AT_LEAST:
|
|
128
|
+
pPr.spacing_lineRule = WD_LINE_SPACING.EXACTLY
|
|
129
|
+
else:
|
|
130
|
+
pPr.spacing_line = Emu(value * Twips(240))
|
|
131
|
+
pPr.spacing_lineRule = WD_LINE_SPACING.MULTIPLE
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def line_spacing_rule(self):
|
|
135
|
+
"""A member of the :ref:`WdLineSpacing` enumeration indicating how the value of
|
|
136
|
+
:attr:`line_spacing` should be interpreted.
|
|
137
|
+
|
|
138
|
+
Assigning any of the :ref:`WdLineSpacing` members :attr:`SINGLE`,
|
|
139
|
+
:attr:`DOUBLE`, or :attr:`ONE_POINT_FIVE` will cause the value of
|
|
140
|
+
:attr:`line_spacing` to be updated to produce the corresponding line spacing.
|
|
141
|
+
"""
|
|
142
|
+
pPr = self._element.pPr
|
|
143
|
+
if pPr is None:
|
|
144
|
+
return None
|
|
145
|
+
return self._line_spacing_rule(pPr.spacing_line, pPr.spacing_lineRule)
|
|
146
|
+
|
|
147
|
+
@line_spacing_rule.setter
|
|
148
|
+
def line_spacing_rule(self, value):
|
|
149
|
+
pPr = self._element.get_or_add_pPr()
|
|
150
|
+
if value == WD_LINE_SPACING.SINGLE:
|
|
151
|
+
pPr.spacing_line = Twips(240)
|
|
152
|
+
pPr.spacing_lineRule = WD_LINE_SPACING.MULTIPLE
|
|
153
|
+
elif value == WD_LINE_SPACING.ONE_POINT_FIVE:
|
|
154
|
+
pPr.spacing_line = Twips(360)
|
|
155
|
+
pPr.spacing_lineRule = WD_LINE_SPACING.MULTIPLE
|
|
156
|
+
elif value == WD_LINE_SPACING.DOUBLE:
|
|
157
|
+
pPr.spacing_line = Twips(480)
|
|
158
|
+
pPr.spacing_lineRule = WD_LINE_SPACING.MULTIPLE
|
|
159
|
+
else:
|
|
160
|
+
pPr.spacing_lineRule = value
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
def page_break_before(self):
|
|
164
|
+
"""|True| if the paragraph should appear at the top of the page following the
|
|
165
|
+
prior paragraph.
|
|
166
|
+
|
|
167
|
+
|None| indicates its effective value is inherited from the style hierarchy.
|
|
168
|
+
"""
|
|
169
|
+
pPr = self._element.pPr
|
|
170
|
+
if pPr is None:
|
|
171
|
+
return None
|
|
172
|
+
return pPr.pageBreakBefore_val
|
|
173
|
+
|
|
174
|
+
@page_break_before.setter
|
|
175
|
+
def page_break_before(self, value):
|
|
176
|
+
self._element.get_or_add_pPr().pageBreakBefore_val = value
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def right_indent(self):
|
|
180
|
+
"""|Length| value specifying the space between the right margin and the right
|
|
181
|
+
side of the paragraph.
|
|
182
|
+
|
|
183
|
+
|None| indicates the right indent value is inherited from the style hierarchy.
|
|
184
|
+
Use a |Cm| value object as a convenient way to apply indentation in units of
|
|
185
|
+
centimeters.
|
|
186
|
+
"""
|
|
187
|
+
pPr = self._element.pPr
|
|
188
|
+
if pPr is None:
|
|
189
|
+
return None
|
|
190
|
+
return pPr.ind_right
|
|
191
|
+
|
|
192
|
+
@right_indent.setter
|
|
193
|
+
def right_indent(self, value):
|
|
194
|
+
pPr = self._element.get_or_add_pPr()
|
|
195
|
+
pPr.ind_right = value
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def space_after(self):
|
|
199
|
+
"""|Length| value specifying the spacing to appear between this paragraph and
|
|
200
|
+
the subsequent paragraph.
|
|
201
|
+
|
|
202
|
+
|None| indicates this value is inherited from the style hierarchy. |Length|
|
|
203
|
+
objects provide convenience properties, such as :attr:`~.Length.pt` and
|
|
204
|
+
:attr:`~.Length.inches`, that allow easy conversion to various length units.
|
|
205
|
+
"""
|
|
206
|
+
pPr = self._element.pPr
|
|
207
|
+
if pPr is None:
|
|
208
|
+
return None
|
|
209
|
+
return pPr.spacing_after
|
|
210
|
+
|
|
211
|
+
@space_after.setter
|
|
212
|
+
def space_after(self, value):
|
|
213
|
+
self._element.get_or_add_pPr().spacing_after = value
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def space_before(self):
|
|
217
|
+
"""|Length| value specifying the spacing to appear between this paragraph and
|
|
218
|
+
the prior paragraph.
|
|
219
|
+
|
|
220
|
+
|None| indicates this value is inherited from the style hierarchy. |Length|
|
|
221
|
+
objects provide convenience properties, such as :attr:`~.Length.pt` and
|
|
222
|
+
:attr:`~.Length.cm`, that allow easy conversion to various length units.
|
|
223
|
+
"""
|
|
224
|
+
pPr = self._element.pPr
|
|
225
|
+
if pPr is None:
|
|
226
|
+
return None
|
|
227
|
+
return pPr.spacing_before
|
|
228
|
+
|
|
229
|
+
@space_before.setter
|
|
230
|
+
def space_before(self, value):
|
|
231
|
+
self._element.get_or_add_pPr().spacing_before = value
|
|
232
|
+
|
|
233
|
+
@lazyproperty
|
|
234
|
+
def tab_stops(self):
|
|
235
|
+
"""|TabStops| object providing access to the tab stops defined for this
|
|
236
|
+
paragraph format."""
|
|
237
|
+
pPr = self._element.get_or_add_pPr()
|
|
238
|
+
return TabStops(pPr)
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def widow_control(self):
|
|
242
|
+
"""|True| if the first and last lines in the paragraph remain on the same page
|
|
243
|
+
as the rest of the paragraph when Word repaginates the document.
|
|
244
|
+
|
|
245
|
+
|None| indicates its effective value is inherited from the style hierarchy.
|
|
246
|
+
"""
|
|
247
|
+
pPr = self._element.pPr
|
|
248
|
+
if pPr is None:
|
|
249
|
+
return None
|
|
250
|
+
return pPr.widowControl_val
|
|
251
|
+
|
|
252
|
+
@widow_control.setter
|
|
253
|
+
def widow_control(self, value):
|
|
254
|
+
self._element.get_or_add_pPr().widowControl_val = value
|
|
255
|
+
|
|
256
|
+
@staticmethod
|
|
257
|
+
def _line_spacing(spacing_line, spacing_lineRule):
|
|
258
|
+
"""Return the line spacing value calculated from the combination of
|
|
259
|
+
`spacing_line` and `spacing_lineRule`.
|
|
260
|
+
|
|
261
|
+
Returns a |float| number of lines when `spacing_lineRule` is
|
|
262
|
+
``WD_LINE_SPACING.MULTIPLE``, otherwise a |Length| object of absolute line
|
|
263
|
+
height is returned. Returns |None| when `spacing_line` is |None|.
|
|
264
|
+
"""
|
|
265
|
+
if spacing_line is None:
|
|
266
|
+
return None
|
|
267
|
+
if spacing_lineRule == WD_LINE_SPACING.MULTIPLE:
|
|
268
|
+
return spacing_line / Pt(12)
|
|
269
|
+
return spacing_line
|
|
270
|
+
|
|
271
|
+
@staticmethod
|
|
272
|
+
def _line_spacing_rule(line, lineRule):
|
|
273
|
+
"""Return the line spacing rule value calculated from the combination of `line`
|
|
274
|
+
and `lineRule`.
|
|
275
|
+
|
|
276
|
+
Returns special members of the :ref:`WdLineSpacing` enumeration when line
|
|
277
|
+
spacing is single, double, or 1.5 lines.
|
|
278
|
+
"""
|
|
279
|
+
if lineRule == WD_LINE_SPACING.MULTIPLE:
|
|
280
|
+
if line == Twips(240):
|
|
281
|
+
return WD_LINE_SPACING.SINGLE
|
|
282
|
+
if line == Twips(360):
|
|
283
|
+
return WD_LINE_SPACING.ONE_POINT_FIVE
|
|
284
|
+
if line == Twips(480):
|
|
285
|
+
return WD_LINE_SPACING.DOUBLE
|
|
286
|
+
return lineRule
|