Closed obdura closed 2 years ago
Hi there,
I love your suggestion.
I'm going to include the following improvement to Table
def even_odd_row_colors(
self,
even_row_color: Color,
odd_row_color: Color,
header_row_color: typing.Optional[Color] = None
) -> "Table":
"""
This function colors the Table with the classic "zebra stripes"
e.a. one color for all even rows, and a contrasting color for the odd rows.
:param even_row_color: the Color to be used for even rows
:param odd_row_color: the Color to be used for odd rows
:param header_row_color: the Color to be used for the header row, if None is specified the even_row_color will be used
This function returns self.
"""
if header_row_color is None:
header_row_color = even_row_color
assert header_row_color is not None
for r in range(0, self._number_of_rows):
for tc in self._get_cells_at_row(r):
if r == 0:
tc._background_color = header_row_color
else:
if r % 2 == 0:
tc._background_color = even_row_color
else:
tc._background_color = odd_row_color
return self
This ensures that:
header_row_color
, it defaults to even_row_color
)header_row_color
You can expect this fix in the upcoming release (normally this weekend)
Kind regards, Joris Schellekens
Hi, recently I were doing a document with tables. I were confronted with the problem that I could not put a header with different color on an
even_odd_row_colors()
colored table.I created a custom class that inherits from
FixedColumnWidthTable
(I may have do it generally inheriting fromTable
) to solve this purpose. This now allows to create a different colored header on these kind of colored tables:It helped me to create a table like this one:
Maybe this kind of improvement could be added to a new version of
borb
.Also, it is a good library that you have made.