Skip to content

Commit 8562eb7

Browse files
author
Steve Canny
committed
style: add _LatentStyle on/off prop setters
1 parent ec19643 commit 8562eb7

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

docx/oxml/styles.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ def on_off_prop(self, attr_name):
9292
"""
9393
return getattr(self, attr_name)
9494

95+
def set_on_off_prop(self, attr_name, value):
96+
"""
97+
Set the on/off attribute having *attr_name* to *value*.
98+
"""
99+
setattr(self, attr_name, value)
100+
95101

96102
class CT_Style(BaseOxmlElement):
97103
"""

docx/styles/latent.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def hidden(self):
135135
"""
136136
return self._element.on_off_prop('semiHidden')
137137

138+
@hidden.setter
139+
def hidden(self, value):
140+
self._element.set_on_off_prop('semiHidden', value)
141+
138142
@property
139143
def locked(self):
140144
"""
@@ -146,6 +150,10 @@ def locked(self):
146150
"""
147151
return self._element.on_off_prop('locked')
148152

153+
@locked.setter
154+
def locked(self, value):
155+
self._element.set_on_off_prop('locked', value)
156+
149157
@property
150158
def name(self):
151159
"""
@@ -174,6 +182,10 @@ def quick_style(self):
174182
"""
175183
return self._element.on_off_prop('qFormat')
176184

185+
@quick_style.setter
186+
def quick_style(self, value):
187+
self._element.set_on_off_prop('qFormat', value)
188+
177189
@property
178190
def unhide_when_used(self):
179191
"""
@@ -184,3 +196,7 @@ def unhide_when_used(self):
184196
object.
185197
"""
186198
return self._element.on_off_prop('unhideWhenUsed')
199+
200+
@unhide_when_used.setter
201+
def unhide_when_used(self, value):
202+
self._element.set_on_off_prop('unhideWhenUsed', value)

features/sty-latent-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Feature: Get and set latent style properties
8080
| unhide_when_used | no setting | None |
8181

8282

83-
@wip
8483
Scenario Outline: Set on/off latent style properties
8584
Given a latent style having <prop-name> set <setting>
8685
When I assign <new-value> to latent_style.<prop-name>

tests/styles/test_latent.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def it_knows_its_on_off_properties(self, on_off_get_fixture):
3535
actual_value = getattr(latent_style, prop_name)
3636
assert actual_value == expected_value
3737

38+
def it_can_change_its_on_off_properties(self, on_off_set_fixture):
39+
latent_style, prop_name, value, expected_xml = on_off_set_fixture
40+
setattr(latent_style, prop_name, value)
41+
assert latent_style.element.xml == expected_xml
42+
3843
# fixtures -------------------------------------------------------
3944

4045
@pytest.fixture(params=[
@@ -64,6 +69,28 @@ def on_off_get_fixture(self, request):
6469
latent_style = _LatentStyle(element(lsdException_cxml))
6570
return latent_style, prop_name, expected_value
6671

72+
@pytest.fixture(params=[
73+
('w:lsdException', 'hidden', True,
74+
'w:lsdException{w:semiHidden=1}'),
75+
('w:lsdException{w:semiHidden=1}', 'hidden', False,
76+
'w:lsdException{w:semiHidden=0}'),
77+
('w:lsdException{w:semiHidden=0}', 'hidden', None,
78+
'w:lsdException'),
79+
('w:lsdException', 'locked', True,
80+
'w:lsdException{w:locked=1}'),
81+
('w:lsdException', 'quick_style', False,
82+
'w:lsdException{w:qFormat=0}'),
83+
('w:lsdException', 'unhide_when_used', True,
84+
'w:lsdException{w:unhideWhenUsed=1}'),
85+
('w:lsdException{w:locked=1}', 'locked', None,
86+
'w:lsdException'),
87+
])
88+
def on_off_set_fixture(self, request):
89+
lsdException_cxml, prop_name, value, expected_cxml = request.param
90+
latent_styles = _LatentStyle(element(lsdException_cxml))
91+
expected_xml = xml(expected_cxml)
92+
return latent_styles, prop_name, value, expected_xml
93+
6794
@pytest.fixture(params=[
6895
('w:lsdException', None),
6996
('w:lsdException{w:uiPriority=42}', 42),

0 commit comments

Comments
 (0)