Skip to content

Commit 8ea3891

Browse files
author
Steve Canny
committed
style: add BaseStyle.unhide_when_used getter
1 parent 78008c6 commit 8ea3891

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

docx/oxml/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
120120
register_element_cls('w:style', CT_Style)
121121
register_element_cls('w:styles', CT_Styles)
122122
register_element_cls('w:uiPriority', CT_DecimalNumber)
123+
register_element_cls('w:unhideWhenUsed', CT_OnOff)
123124

124125
from .table import (
125126
CT_Row, CT_Tbl, CT_TblGrid, CT_TblGridCol, CT_TblLayoutType, CT_TblPr,

docx/oxml/styles.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class CT_Style(BaseOxmlElement):
4545
basedOn = ZeroOrOne('w:basedOn', successors=_tag_seq[3:])
4646
uiPriority = ZeroOrOne('w:uiPriority', successors=_tag_seq[8:])
4747
semiHidden = ZeroOrOne('w:semiHidden', successors=_tag_seq[9:])
48+
unhideWhenUsed = ZeroOrOne('w:unhideWhenUsed', successors=_tag_seq[10:])
4849
pPr = ZeroOrOne('w:pPr', successors=_tag_seq[17:])
4950
rPr = ZeroOrOne('w:rPr', successors=_tag_seq[18:])
5051
del _tag_seq
@@ -143,6 +144,16 @@ def uiPriority_val(self, value):
143144
uiPriority = self._add_uiPriority()
144145
uiPriority.val = value
145146

147+
@property
148+
def unhideWhenUsed_val(self):
149+
"""
150+
Value of `w:unhideWhenUsed/@w:val` or |False| if not present.
151+
"""
152+
unhideWhenUsed = self.unhideWhenUsed
153+
if unhideWhenUsed is None:
154+
return False
155+
return unhideWhenUsed.val
156+
146157

147158
class CT_Styles(BaseOxmlElement):
148159
"""

docx/styles/style.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ def type(self):
125125
return WD_STYLE_TYPE.PARAGRAPH
126126
return type
127127

128+
@property
129+
def unhide_when_used(self):
130+
"""
131+
|True| if an application should make this style visible the next time
132+
it is applied to content. False otherwise. Note that |docx| does not
133+
automatically unhide a style having |True| for this attribute when it
134+
is applied to content.
135+
"""
136+
return self._element.unhideWhenUsed_val
137+
128138
@staticmethod
129139
def _translate_special_case_names(name):
130140
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ Feature: Get and set style properties
9797
Then style.type is the known type
9898

9999

100-
@wip
101100
Scenario Outline: Get unhide-when-used value
102101
Given a style having unhide-when-used set <setting>
103102
Then style.unhide_when_used is <value>

tests/styles/test_style.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def it_can_change_its_sort_order(self, priority_set_fixture):
141141
style.priority = value
142142
assert style._element.xml == expected_xml
143143

144+
def it_knows_whether_its_unhide_when_used(self, unhide_get_fixture):
145+
style, expected_value = unhide_get_fixture
146+
assert style.unhide_when_used == expected_value
147+
144148
def it_can_delete_itself_from_the_document(self, delete_fixture):
145149
style, styles, expected_xml = delete_fixture
146150
style.delete()
@@ -267,6 +271,17 @@ def type_get_fixture(self, request):
267271
style = BaseStyle(element(style_cxml))
268272
return style, expected_value
269273

274+
@pytest.fixture(params=[
275+
('w:style', False),
276+
('w:style/w:unhideWhenUsed', True),
277+
('w:style/w:unhideWhenUsed{w:val=0}', False),
278+
('w:style/w:unhideWhenUsed{w:val=1}', True),
279+
])
280+
def unhide_get_fixture(self, request):
281+
style_cxml, expected_value = request.param
282+
style = BaseStyle(element(style_cxml))
283+
return style, expected_value
284+
270285

271286
class Describe_CharacterStyle(object):
272287

0 commit comments

Comments
 (0)