Skip to content

Commit

Permalink
tbl: add Table.table_direction setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Canny committed Feb 21, 2015
1 parent d4ca18d commit 9605cc0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NEXT

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


0.8.4 (2015-02-20)
Expand Down
8 changes: 8 additions & 0 deletions docx/oxml/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def bidiVisual_val(self):
return None
return bidiVisual.val

@bidiVisual_val.setter
def bidiVisual_val(self, value):
tblPr = self.tblPr
if value is None:
tblPr._remove_bidiVisual()
else:
tblPr.get_or_add_bidiVisual().val = value

@property
def col_count(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions docx/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def table_direction(self):
"""
return self._element.bidiVisual_val

@table_direction.setter
def table_direction(self, value):
self._element.bidiVisual_val = value

@property
def _cells(self):
"""
Expand Down
1 change: 0 additions & 1 deletion features/tbl-props.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Feature: Get and set table properties
| left-to-right | LTR |


@wip
Scenario Outline: Set table direction
Given a table having table direction set <setting>
When I assign <new-value> to table.table_direction
Expand Down
21 changes: 21 additions & 0 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def it_knows_its_direction(self, direction_get_fixture):
table, expected_value = direction_get_fixture
assert table.table_direction == expected_value

def it_can_change_its_direction(self, direction_set_fixture):
table, new_value, expected_xml = direction_set_fixture
table.table_direction = new_value
assert table._element.xml == expected_xml

def it_knows_its_table_style(self, style_get_fixture):
table, style_id_, style_ = style_get_fixture
style = table.style
Expand Down Expand Up @@ -239,6 +244,22 @@ def direction_get_fixture(self, request):
table = Table(element(tbl_cxml), None)
return table, expected_value

@pytest.fixture(params=[
('w:tbl/w:tblPr', WD_TABLE_DIRECTION.RTL,
'w:tbl/w:tblPr/w:bidiVisual'),
('w:tbl/w:tblPr/w:bidiVisual', WD_TABLE_DIRECTION.LTR,
'w:tbl/w:tblPr/w:bidiVisual{w:val=0}'),
('w:tbl/w:tblPr/w:bidiVisual{w:val=0}', WD_TABLE_DIRECTION.RTL,
'w:tbl/w:tblPr/w:bidiVisual'),
('w:tbl/w:tblPr/w:bidiVisual{w:val=1}', None,
'w:tbl/w:tblPr'),
])
def direction_set_fixture(self, request):
tbl_cxml, new_value, expected_cxml = request.param
table = Table(element(tbl_cxml), None)
expected_xml = xml(expected_cxml)
return table, new_value, expected_xml

@pytest.fixture
def row_cells_fixture(self, _cells_, _column_count_):
table = Table(None, None)
Expand Down

0 comments on commit 9605cc0

Please sign in to comment.