Skip to content

Commit 9605cc0

Browse files
author
Steve Canny
committed
tbl: add Table.table_direction setter
1 parent d4ca18d commit 9605cc0

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ NEXT
88

99
- Fix #149: KeyError on Document.add_table()
1010
- Fix #78: feature: add_table() sets cell widths
11+
- Add #106: feature: Table.direction (i.e. right-to-left)
1112

1213

1314
0.8.4 (2015-02-20)

docx/oxml/table.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ def bidiVisual_val(self):
7373
return None
7474
return bidiVisual.val
7575

76+
@bidiVisual_val.setter
77+
def bidiVisual_val(self, value):
78+
tblPr = self.tblPr
79+
if value is None:
80+
tblPr._remove_bidiVisual()
81+
else:
82+
tblPr.get_or_add_bidiVisual().val = value
83+
7684
@property
7785
def col_count(self):
7886
"""

docx/table.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def table_direction(self):
154154
"""
155155
return self._element.bidiVisual_val
156156

157+
@table_direction.setter
158+
def table_direction(self, value):
159+
self._element.bidiVisual_val = value
160+
157161
@property
158162
def _cells(self):
159163
"""

features/tbl-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ Feature: Get and set table properties
6666
| left-to-right | LTR |
6767

6868

69-
@wip
7069
Scenario Outline: Set table direction
7170
Given a table having table direction set <setting>
7271
When I assign <new-value> to table.table_direction

tests/test_table.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def it_knows_its_direction(self, direction_get_fixture):
9595
table, expected_value = direction_get_fixture
9696
assert table.table_direction == expected_value
9797

98+
def it_can_change_its_direction(self, direction_set_fixture):
99+
table, new_value, expected_xml = direction_set_fixture
100+
table.table_direction = new_value
101+
assert table._element.xml == expected_xml
102+
98103
def it_knows_its_table_style(self, style_get_fixture):
99104
table, style_id_, style_ = style_get_fixture
100105
style = table.style
@@ -239,6 +244,22 @@ def direction_get_fixture(self, request):
239244
table = Table(element(tbl_cxml), None)
240245
return table, expected_value
241246

247+
@pytest.fixture(params=[
248+
('w:tbl/w:tblPr', WD_TABLE_DIRECTION.RTL,
249+
'w:tbl/w:tblPr/w:bidiVisual'),
250+
('w:tbl/w:tblPr/w:bidiVisual', WD_TABLE_DIRECTION.LTR,
251+
'w:tbl/w:tblPr/w:bidiVisual{w:val=0}'),
252+
('w:tbl/w:tblPr/w:bidiVisual{w:val=0}', WD_TABLE_DIRECTION.RTL,
253+
'w:tbl/w:tblPr/w:bidiVisual'),
254+
('w:tbl/w:tblPr/w:bidiVisual{w:val=1}', None,
255+
'w:tbl/w:tblPr'),
256+
])
257+
def direction_set_fixture(self, request):
258+
tbl_cxml, new_value, expected_cxml = request.param
259+
table = Table(element(tbl_cxml), None)
260+
expected_xml = xml(expected_cxml)
261+
return table, new_value, expected_xml
262+
242263
@pytest.fixture
243264
def row_cells_fixture(self, _cells_, _column_count_):
244265
table = Table(None, None)

0 commit comments

Comments
 (0)