Skip to content

Commit 872a0f2

Browse files
author
Steve Canny
committed
style: add BaseStyle.priority setter
1 parent 0b612d3 commit 872a0f2

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

docx/oxml/styles.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ def uiPriority_val(self):
136136
return None
137137
return uiPriority.val
138138

139+
@uiPriority_val.setter
140+
def uiPriority_val(self, value):
141+
self._remove_uiPriority()
142+
if value is not None:
143+
uiPriority = self._add_uiPriority()
144+
uiPriority.val = value
145+
139146

140147
class CT_Styles(BaseOxmlElement):
141148
"""

docx/styles/style.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ def priority(self):
9797
"""
9898
return self._element.uiPriority_val
9999

100+
@priority.setter
101+
def priority(self, value):
102+
self._element.uiPriority_val = value
103+
100104
@property
101105
def style_id(self):
102106
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ Feature: Get and set style properties
6969
| 42 | 42 |
7070

7171

72-
@wip
7372
Scenario Outline: Set style display sort order
7473
Given a style having priority of <setting>
7574
When I assign <new-value> to style.priority

tests/styles/test_style.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ def it_knows_its_sort_order(self, priority_get_fixture):
136136
style, expected_value = priority_get_fixture
137137
assert style.priority == expected_value
138138

139+
def it_can_change_its_sort_order(self, priority_set_fixture):
140+
style, value, expected_xml = priority_set_fixture
141+
style.priority = value
142+
assert style._element.xml == expected_xml
143+
139144
def it_can_delete_itself_from_the_document(self, delete_fixture):
140145
style, styles, expected_xml = delete_fixture
141146
style.delete()
@@ -237,6 +242,20 @@ def priority_get_fixture(self, request):
237242
style = BaseStyle(element(style_cxml))
238243
return style, expected_value
239244

245+
@pytest.fixture(params=[
246+
('w:style', 42,
247+
'w:style/w:uiPriority{w:val=42}'),
248+
('w:style/w:uiPriority{w:val=42}', 24,
249+
'w:style/w:uiPriority{w:val=24}'),
250+
('w:style/w:uiPriority{w:val=24}', None,
251+
'w:style'),
252+
])
253+
def priority_set_fixture(self, request):
254+
style_cxml, value, expected_cxml = request.param
255+
style = BaseStyle(element(style_cxml))
256+
expected_xml = xml(expected_cxml)
257+
return style, value, expected_xml
258+
240259
@pytest.fixture(params=[
241260
('w:style', WD_STYLE_TYPE.PARAGRAPH),
242261
('w:style{w:type=paragraph}', WD_STYLE_TYPE.PARAGRAPH),

0 commit comments

Comments
 (0)