Skip to content

Commit c6ee527

Browse files
author
Steve Canny
committed
style: add LatentStyles.default_priority getter
1 parent faa7ab1 commit c6ee527

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docx/oxml/styles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from ..enum.style import WD_STYLE_TYPE
8-
from .simpletypes import ST_OnOff, ST_String
8+
from .simpletypes import ST_DecimalNumber, ST_OnOff, ST_String
99
from .xmlchemy import (
1010
BaseOxmlElement, OptionalAttribute, ZeroOrMore, ZeroOrOne
1111
)
@@ -38,6 +38,8 @@ class CT_LatentStyles(BaseOxmlElement):
3838
"""
3939
lsdException = ZeroOrMore('w:lsdException', successors=())
4040

41+
defUIPriority = OptionalAttribute('w:defUIPriority', ST_DecimalNumber)
42+
4143
def get_by_name(self, name):
4244
"""
4345
Return the `w:lsdException` child having *name*, or |None| if not

docx/styles/latent.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def __iter__(self):
3535
def __len__(self):
3636
return len(self._element.lsdException_lst)
3737

38+
@property
39+
def default_priority(self):
40+
"""
41+
Integer between 0 and 99 inclusive specifying the default sort order
42+
for latent styles in style lists and the style gallery. |None| if no
43+
value is assigned, which causes Word to use the default value 99.
44+
"""
45+
return self._element.defUIPriority
46+
3847

3948
class _LatentStyle(ElementProxy):
4049
"""

tests/styles/test_latent.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def it_raises_on_latent_style_not_found(self, getitem_raises_fixture):
3939
with pytest.raises(KeyError):
4040
latent_styles[name]
4141

42+
def it_knows_its_default_priority(self, priority_get_fixture):
43+
latent_styles, expected_value = priority_get_fixture
44+
assert latent_styles.default_priority == expected_value
45+
4246
# fixture --------------------------------------------------------
4347

4448
@pytest.fixture(params=[
@@ -78,3 +82,12 @@ def len_fixture(self, request):
7882
latentStyles_cxml, count = request.param
7983
latent_styles = LatentStyles(element(latentStyles_cxml))
8084
return latent_styles, count
85+
86+
@pytest.fixture(params=[
87+
('w:latentStyles', None),
88+
('w:latentStyles{w:defUIPriority=42}', 42),
89+
])
90+
def priority_get_fixture(self, request):
91+
latentStyles_cxml, expected_value = request.param
92+
latent_styles = LatentStyles(element(latentStyles_cxml))
93+
return latent_styles, expected_value

0 commit comments

Comments
 (0)