Skip to content

Commit 4863ac9

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.right_indent setter
1 parent 5a92413 commit 4863ac9

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

docx/oxml/text/paragraph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ def ind_right(self):
182182
return None
183183
return ind.right
184184

185+
@ind_right.setter
186+
def ind_right(self, value):
187+
if value is None and self.ind is None:
188+
return
189+
ind = self.get_or_add_ind()
190+
ind.right = value
191+
185192
@property
186193
def jc_val(self):
187194
"""

docx/text/paragraph.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ def right_indent(self):
270270
return None
271271
return pPr.ind_right
272272

273+
@right_indent.setter
274+
def right_indent(self, value):
275+
pPr = self._element.get_or_add_pPr()
276+
pPr.ind_right = value
277+
273278
@property
274279
def space_after(self):
275280
"""

features/txt-parfmt-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ Feature: Get or set paragraph formatting properties
110110
| right | 17.3 pt | 219710 |
111111

112112

113-
@wip
114113
Scenario Outline: Set paragraph indents
115114
Given a paragraph format having <type> indent of <setting>
116115
When I assign <new-value> to paragraph_format.<type>_indent

tests/text/test_paragraph.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ def it_knows_its_right_indent(self, right_indent_get_fixture):
356356
paragraph_format, expected_value = right_indent_get_fixture
357357
assert paragraph_format.right_indent == expected_value
358358

359+
def it_can_change_its_right_indent(self, right_indent_set_fixture):
360+
paragraph_format, value, expected_xml = right_indent_set_fixture
361+
paragraph_format.right_indent = value
362+
assert paragraph_format._element.xml == expected_xml
363+
359364
# fixtures -------------------------------------------------------
360365

361366
@pytest.fixture(params=[
@@ -530,6 +535,19 @@ def right_indent_get_fixture(self, request):
530535
paragraph_format = ParagraphFormat(element(p_cxml))
531536
return paragraph_format, expected_value
532537

538+
@pytest.fixture(params=[
539+
('w:p', Pt(36), 'w:p/w:pPr/w:ind{w:right=720}'),
540+
('w:p', Pt(-3), 'w:p/w:pPr/w:ind{w:right=-60}'),
541+
('w:p', 0, 'w:p/w:pPr/w:ind{w:right=0}'),
542+
('w:p', None, 'w:p/w:pPr'),
543+
('w:p/w:pPr/w:ind{w:right=240}', None, 'w:p/w:pPr/w:ind'),
544+
])
545+
def right_indent_set_fixture(self, request):
546+
p_cxml, value, expected_p_cxml = request.param
547+
paragraph_format = ParagraphFormat(element(p_cxml))
548+
expected_xml = xml(expected_p_cxml)
549+
return paragraph_format, value, expected_xml
550+
533551
@pytest.fixture(params=[
534552
('w:p', None),
535553
('w:p/w:pPr', None),

0 commit comments

Comments
 (0)