Skip to content

Commit 4ef1c51

Browse files
author
Steve Canny
committed
docs: document Style behavior properties
1 parent bddd27a commit 4ef1c51

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

docs/user/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ including its typeface, size, color, bold, italic, etc.
310310

311311
Like paragraph styles, a character style must already be defined in the
312312
document you open with the ``Document()`` call (*see*
313-
:ref:`understandingstyles`).
313+
:ref:`understanding_styles`).
314314

315315
A character style can be specified when adding a new run::
316316

docs/user/styles-understanding.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _understandingstyles:
1+
.. _understanding_styles:
22

33
Understanding Styles
44
====================
@@ -132,6 +132,34 @@ the style id unless they are confident with the internals involved.
132132
A style's :attr:`type` is set at creation time and cannot be changed.
133133

134134

135+
.. _style_behavior:
136+
137+
Style Behavior
138+
--------------
139+
140+
In addition to collecting a set of formatting properties, a style has five
141+
properties that specify its *behavior*. This behavior is relatively simple,
142+
basically amounting to when and where the style appears in the Word or
143+
LibreOffice UI.
144+
145+
The key notion to understanding style behavior is the recommended list. In
146+
the style pane in Word, the user can select which list of styles they want to
147+
see. One of these is named *Recommended* and is known as the *recommended
148+
list*. All five behavior properties affect some aspect of the style’s
149+
appearance in this list and in the style gallery.
150+
151+
In brief, a style appears in the recommended list if its :attr:`hidden`
152+
property is |False| (the default). If a style is not hidden and its
153+
:attr:`quick_style` property is |True|, it also appears in the style gallery.
154+
If a hidden style's :attr:`unhide_when_used` property is |True|, its hidden
155+
property is set |False| the first time it is used. Styles in the style lists
156+
and style gallery are sorted in :attr:`priority` order, then alphabetically
157+
for styles of the same priority. If a style's :attr:`locked` property is
158+
|True| and formatting restrictions are turned on for the document, the style
159+
will not appear in any list or the style gallery and cannot be applied to
160+
content.
161+
162+
135163
Style inheritance
136164
-----------------
137165

docs/user/styles-using.rst

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Working with Styles
33
===================
44

55
This page uses concepts developed in the prior page without introduction. If
6-
a term is unfamiliar, consult the prior page :ref:`understandingstyles` for
6+
a term is unfamiliar, consult the prior page :ref:`understanding_styles` for
77
a definition.
88

99

@@ -242,19 +242,38 @@ There are five behavioral properties of a style:
242242
* :attr:`~.Style.quick_style`
243243
* :attr:`~.Style.locked`
244244

245-
The key notion to understanding the behavioral properties is the *recommended
246-
list*. In the style pane in Word, the user can select which list of styles
247-
they want to see. One of those is named *Recommended*. All five behavior
248-
properties affect some aspect of the style's appearance in this list and in
249-
the style gallery.
250-
251-
In brief, a style appears in the recommended list if its `hidden` property is
252-
|False|. If a style is not hidden and its `quick_style` property is |True|,
253-
it also appears in the style gallery. The style's `priority` value (|int|)
254-
determines its position in the sequence of styles. If a styles's `locked`
255-
property is |True| and formatting restrictions are turned on for the
256-
document, the style will not appear in any list or the style gallery and
257-
cannot be applied to content.
245+
See the :ref:`style_behavior` section in :ref:`understanding_styles` for
246+
a description of how these behavioral properties interact to determine when
247+
and where a style appears in the Word UI.
248+
249+
The :attr:`priority` property takes an integer value. The other four style
250+
behavior properties are *tri-state*, meaning they can take the value |True|
251+
(on), |False| (off), or |None| (inherit).
252+
253+
Display a style in the style gallery
254+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255+
256+
The following code will cause the 'Body Text' paragraph style to appear first
257+
in the style gallery::
258+
259+
>>> from docx import Document
260+
>>> document = Document()
261+
>>> style = document.styles['Body Text']
262+
263+
>>> style.hidden = False
264+
>>> style.quick_style = True
265+
>>> style.priorty = 1
266+
267+
Remove a style from the style gallery
268+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
269+
270+
This code will remove the 'Normal' paragraph style from the style gallery,
271+
but allow it to remain in the recommended list::
272+
273+
>>> style = document.styles['Normal']
274+
275+
>>> style.hidden = False
276+
>>> style.quick_style = False
258277

259278

260279
Working with Latent Styles

0 commit comments

Comments
 (0)