Skip to content

Commit b7ec0f0

Browse files
author
Steve Canny
committed
docs: add API page for docx.styles.style module
1 parent 93b990c commit b7ec0f0

File tree

4 files changed

+96
-13
lines changed

4 files changed

+96
-13
lines changed

docs/api/style.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
.. _style_api:
3+
4+
Style-related objects
5+
=====================
6+
7+
A style is used to collect a set of formatting properties under a single name
8+
and apply those properties to a content object all at once. This promotes
9+
formatting consistency thoroughout a document and across related documents
10+
and allows formatting changes to be made globally by changing the definition
11+
in the appropriate style.
12+
13+
.. currentmodule:: docx.styles.style
14+
15+
16+
|BaseStyle| objects
17+
-------------------
18+
19+
.. autoclass:: BaseStyle()
20+
:members:
21+
:inherited-members:
22+
:exclude-members:
23+
part, style_id
24+
25+
26+
|_CharacterStyle| objects
27+
-------------------------
28+
29+
.. autoclass:: _CharacterStyle()
30+
:show-inheritance:
31+
:members:
32+
:inherited-members:
33+
:exclude-members:
34+
element, part, style_id, type
35+
36+
37+
|_ParagraphStyle| objects
38+
-------------------------
39+
40+
.. autoclass:: _ParagraphStyle()
41+
:show-inheritance:
42+
:members:
43+
:inherited-members:
44+
:exclude-members:
45+
element, part, style_id, type
46+
47+
48+
|_TableStyle| objects
49+
---------------------
50+
51+
.. autoclass:: _TableStyle()
52+
:show-inheritance:
53+
:members:
54+
:inherited-members:
55+
:exclude-members:
56+
element, part, style_id, type
57+
58+
59+
|_NumberingStyle| objects
60+
-------------------------
61+
62+
.. autoclass:: _NumberingStyle()
63+
:members:

docs/conf.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@
6969
rst_epilog = """
7070
.. |api-Document| replace:: :class:`docx.api.Document`
7171
72+
.. |BaseStyle| replace:: :class:`.BaseStyle`
73+
7274
.. |_Body| replace:: :class:`._Body`
7375
7476
.. |_Cell| replace:: :class:`._Cell`
7577
78+
.. |_CharacterStyle| replace:: :class:`._CharacterStyle`
79+
7680
.. |Cm| replace:: :class:`.Cm`
7781
7882
.. |_Column| replace:: :class:`._Column`
@@ -109,16 +113,20 @@
109113
110114
.. |Length| replace:: :class:`.Length`
111115
112-
.. |OpcPackage| replace:: :class:`.OpcPackage`
113-
114116
.. |None| replace:: :class:`.None`
115117
116118
.. |NumberingPart| replace:: :class:`.NumberingPart`
117119
120+
.. |_NumberingStyle| replace:: :class:`._NumberingStyle`
121+
122+
.. |OpcPackage| replace:: :class:`.OpcPackage`
123+
118124
.. |Paragraph| replace:: :class:`.Paragraph`
119125
120126
.. |ParagraphFormat| replace:: :class:`.ParagraphFormat`
121127
128+
.. |_ParagraphStyle| replace:: :class:`._ParagraphStyle`
129+
122130
.. |Part| replace:: :class:`.Part`
123131
124132
.. |Pt| replace:: :class:`.Pt`
@@ -147,6 +155,8 @@
147155
148156
.. |Table| replace:: :class:`.Table`
149157
158+
.. |_TableStyle| replace:: :class:`._TableStyle`
159+
150160
.. |_Text| replace:: :class:`._Text`
151161
152162
.. |True| replace:: :class:`True`

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ API Documentation
8383
:maxdepth: 2
8484

8585
api/document
86-
api/table
86+
api/style
8787
api/text
88+
api/table
8889
api/section
8990
api/shape
9091
api/shared

docx/styles/style.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ def StyleFactory(style_elm):
3232
class BaseStyle(ElementProxy):
3333
"""
3434
Base class for the various types of style object, paragraph, character,
35-
table, and numbering.
35+
table, and numbering. These properties and methods are inherited by all
36+
style objects.
3637
"""
3738

3839
__slots__ = ()
3940

4041
@property
4142
def builtin(self):
4243
"""
43-
Boolean indicating whether this style is a built-in style. False
44-
indicates it is a custom (user-defined) style.
44+
Read-only. |True| if this style is a built-in style. |False|
45+
indicates it is a custom (user-defined) style. Note this value is
46+
based on the presence of a `customStyle` attribute in the XML, not on
47+
specific knowledge of which styles are built into Word.
4548
"""
4649
return not self._element.customStyle
4750

@@ -73,7 +76,9 @@ def name(self, value):
7376
@property
7477
def style_id(self):
7578
"""
76-
The unique key name (string) for this style.
79+
The unique key name (string) for this style. This value is subject to
80+
rewriting by Word and should generally not be changed unless you are
81+
familiar with the internals involved.
7782
"""
7883
return self._element.styleId
7984

@@ -85,7 +90,7 @@ def style_id(self, value):
8590
def type(self):
8691
"""
8792
Member of :ref:`WdStyleType` corresponding to the type of this style,
88-
e.g. ``WD_STYLE_TYPE.PARAGRAPH`.
93+
e.g. ``WD_STYLE_TYPE.PARAGRAPH``.
8994
"""
9095
type = self._element.type
9196
if type is None:
@@ -115,7 +120,9 @@ def _translate_special_case_names(name):
115120

116121
class _CharacterStyle(BaseStyle):
117122
"""
118-
A character style.
123+
A character style. A character style is applied to a |Run| object and
124+
primarily provides character-level formatting via the |Font| object in
125+
its :attr:`.font` property.
119126
"""
120127

121128
__slots__ = ()
@@ -147,7 +154,8 @@ def font(self):
147154

148155
class _ParagraphStyle(_CharacterStyle):
149156
"""
150-
A paragraph style.
157+
A paragraph style. A paragraph style provides both character formatting
158+
and paragraph formatting such as indentation and line-spacing.
151159
"""
152160

153161
__slots__ = ()
@@ -156,22 +164,23 @@ class _ParagraphStyle(_CharacterStyle):
156164
def paragraph_format(self):
157165
"""
158166
The |ParagraphFormat| object providing access to the paragraph
159-
properties for this style.
167+
formatting properties for this style such as indentation.
160168
"""
161169
return ParagraphFormat(self._element)
162170

163171

164172
class _TableStyle(_ParagraphStyle):
165173
"""
166-
A table style.
174+
A table style. A table style provides character and paragraph formatting
175+
for its contents as well as special table formatting properties.
167176
"""
168177

169178
__slots__ = ()
170179

171180

172181
class _NumberingStyle(BaseStyle):
173182
"""
174-
A numbering style.
183+
A numbering style. Not yet implemented.
175184
"""
176185

177186
__slots__ = ()

0 commit comments

Comments
 (0)