X Tutup
Skip to content

Commit 676612d

Browse files
author
Steve Canny
committed
parfmt: add ParagraphFormat.widow_control setter
1 parent 3832dc1 commit 676612d

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

docx/oxml/text/paragraph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ def widowControl_val(self):
366366
return None
367367
return widowControl.val
368368

369+
@widowControl_val.setter
370+
def widowControl_val(self, value):
371+
if value is None:
372+
self._remove_widowControl()
373+
else:
374+
self.get_or_add_widowControl().val = value
375+
369376

370377
class CT_Spacing(BaseOxmlElement):
371378
"""

docx/text/paragraph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ def widow_control(self):
376376
return None
377377
return pPr.widowControl_val
378378

379+
@widow_control.setter
380+
def widow_control(self, value):
381+
self._element.get_or_add_pPr().widowControl_val = value
382+
379383
@staticmethod
380384
def _line_spacing(spacing_line, spacing_lineRule):
381385
"""

features/txt-parfmt-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ Feature: Get or set paragraph formatting properties
148148
| widow_control | Off | False |
149149

150150

151-
@wip
152151
Scenario Outline: Set On/Off paragraph property
153152
Given a paragraph format having <prop-name> set <state>
154153
When I assign <new-value> to paragraph_format.<prop-name>

tests/text/test_paragraph.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,23 @@ def on_off_get_fixture(self, request):
555555
('w:p', 'keep_together', True, 'w:p/w:pPr/w:keepLines'),
556556
('w:p', 'keep_with_next', True, 'w:p/w:pPr/w:keepNext'),
557557
('w:p', 'page_break_before', True, 'w:p/w:pPr/w:pageBreakBefore'),
558+
('w:p', 'widow_control', True, 'w:p/w:pPr/w:widowControl'),
558559
('w:p/w:pPr/w:keepLines', 'keep_together', False,
559560
'w:p/w:pPr/w:keepLines{w:val=0}'),
560561
('w:p/w:pPr/w:keepNext', 'keep_with_next', False,
561562
'w:p/w:pPr/w:keepNext{w:val=0}'),
562563
('w:p/w:pPr/w:pageBreakBefore', 'page_break_before', False,
563564
'w:p/w:pPr/w:pageBreakBefore{w:val=0}'),
565+
('w:p/w:pPr/w:widowControl', 'widow_control', False,
566+
'w:p/w:pPr/w:widowControl{w:val=0}'),
564567
('w:p/w:pPr/w:keepLines{w:val=0}', 'keep_together', None,
565568
'w:p/w:pPr'),
566569
('w:p/w:pPr/w:keepNext{w:val=0}', 'keep_with_next', None,
567570
'w:p/w:pPr'),
568571
('w:p/w:pPr/w:pageBreakBefore{w:val=0}', 'page_break_before', None,
569572
'w:p/w:pPr'),
573+
('w:p/w:pPr/w:widowControl{w:val=0}', 'widow_control', None,
574+
'w:p/w:pPr'),
570575
])
571576
def on_off_set_fixture(self, request):
572577
p_cxml, prop_name, value, expected_cxml = request.param

0 commit comments

Comments
 (0)
X Tutup