Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48a7e31

Browse files
DKWoodsSteve Canny
authored andcommitted
tabs: add TabStop.alignment
1 parent 5b7edf9 commit 48a7e31

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

docx/oxml/text/parfmt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
Custom element classes related to paragraph properties (CT_PPr).
55
"""
66

7-
from ...enum.text import WD_ALIGN_PARAGRAPH, WD_LINE_SPACING
7+
from ...enum.text import (
8+
WD_ALIGN_PARAGRAPH, WD_LINE_SPACING, WD_TAB_ALIGNMENT
9+
)
810
from ...shared import Length
911
from ..simpletypes import ST_SignedTwipsMeasure, ST_TwipsMeasure
1012
from ..xmlchemy import (
@@ -319,6 +321,7 @@ class CT_TabStop(BaseOxmlElement):
319321
"""
320322
``<w:tab>`` element, representing an individual tab stop.
321323
"""
324+
val = RequiredAttribute('w:val', WD_TAB_ALIGNMENT)
322325
pos = RequiredAttribute('w:pos', ST_SignedTwipsMeasure)
323326

324327

docx/text/tabstops.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ def __init__(self, element):
6464
super(TabStop, self).__init__(element, None)
6565
self._tab = element
6666

67+
@property
68+
def alignment(self):
69+
"""
70+
A member of :ref:`WdTabAlignment` specifying the alignment setting
71+
for this tab stop.
72+
"""
73+
return self._tab.val
74+
6775
@property
6876
def position(self):
6977
"""

features/tab-tabstop-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Feature: Tab stop properties
1414
| out | -457200 |
1515

1616

17-
@wip
1817
Scenario Outline: Get TabStop.alignment
1918
Given a tab stop having <alignment> alignment
2019
Then tab_stop.alignment is <alignment>

tests/text/test_tabstops.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
absolute_import, division, print_function, unicode_literals
1010
)
1111

12+
from docx.enum.text import WD_TAB_ALIGNMENT
1213
from docx.shared import Twips
1314
from docx.text.tabstops import TabStop, TabStops
1415

@@ -24,8 +25,22 @@ def it_knows_its_position(self, position_get_fixture):
2425
tab_stop, expected_value = position_get_fixture
2526
assert tab_stop.position == expected_value
2627

28+
def it_knows_its_alignment(self, alignment_get_fixture):
29+
tab_stop, expected_value = alignment_get_fixture
30+
assert tab_stop.alignment == expected_value
31+
2732
# fixture --------------------------------------------------------
2833

34+
@pytest.fixture(params=[
35+
('w:tab{w:val=left}', 'LEFT'),
36+
('w:tab{w:val=right}', 'RIGHT'),
37+
])
38+
def alignment_get_fixture(self, request):
39+
tab_stop_cxml, member = request.param
40+
tab_stop = TabStop(element(tab_stop_cxml))
41+
expected_value = getattr(WD_TAB_ALIGNMENT, member)
42+
return tab_stop, expected_value
43+
2944
@pytest.fixture
3045
def position_get_fixture(self, request):
3146
tab_stop = TabStop(element('w:tab{w:pos=720}'))

0 commit comments

Comments
 (0)