Skip to content

Commit 5a92413

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.left_indent setter
1 parent 4321d9e commit 5a92413

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

docx/oxml/text/paragraph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ def ind_left(self):
165165
return None
166166
return ind.left
167167

168+
@ind_left.setter
169+
def ind_left(self, value):
170+
if value is None and self.ind is None:
171+
return
172+
ind = self.get_or_add_ind()
173+
ind.left = value
174+
168175
@property
169176
def ind_right(self):
170177
"""

docx/text/paragraph.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ def left_indent(self):
190190
return None
191191
return pPr.ind_left
192192

193+
@left_indent.setter
194+
def left_indent(self, value):
195+
pPr = self._element.get_or_add_pPr()
196+
pPr.ind_left = value
197+
193198
@property
194199
def line_spacing(self):
195200
"""

tests/text/test_paragraph.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ def it_knows_its_left_indent(self, left_indent_get_fixture):
347347
paragraph_format, expected_value = left_indent_get_fixture
348348
assert paragraph_format.left_indent == expected_value
349349

350+
def it_can_change_its_left_indent(self, left_indent_set_fixture):
351+
paragraph_format, value, expected_xml = left_indent_set_fixture
352+
paragraph_format.left_indent = value
353+
assert paragraph_format._element.xml == expected_xml
354+
350355
def it_knows_its_right_indent(self, right_indent_get_fixture):
351356
paragraph_format, expected_value = right_indent_get_fixture
352357
assert paragraph_format.right_indent == expected_value
@@ -423,6 +428,19 @@ def left_indent_get_fixture(self, request):
423428
paragraph_format = ParagraphFormat(element(p_cxml))
424429
return paragraph_format, expected_value
425430

431+
@pytest.fixture(params=[
432+
('w:p', Pt(36), 'w:p/w:pPr/w:ind{w:left=720}'),
433+
('w:p', Pt(-3), 'w:p/w:pPr/w:ind{w:left=-60}'),
434+
('w:p', 0, 'w:p/w:pPr/w:ind{w:left=0}'),
435+
('w:p', None, 'w:p/w:pPr'),
436+
('w:p/w:pPr/w:ind{w:left=240}', None, 'w:p/w:pPr/w:ind'),
437+
])
438+
def left_indent_set_fixture(self, request):
439+
p_cxml, value, expected_p_cxml = request.param
440+
paragraph_format = ParagraphFormat(element(p_cxml))
441+
expected_xml = xml(expected_p_cxml)
442+
return paragraph_format, value, expected_xml
443+
426444
@pytest.fixture(params=[
427445
('w:p', None),
428446
('w:p/w:pPr', None),

0 commit comments

Comments
 (0)