Skip to content
Snippets Groups Projects
Commit 181991e2 authored by Mateusz Kudela's avatar Mateusz Kudela
Browse files

WIP

parent 5d0cfa2c
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !388. Comments created here will be created in the context of that merge request.
......@@ -196,10 +196,34 @@ class CliveCheckerboardTable(CliveWidget):
self.update_previous_state(content)
await self.rebuild(content)
async def _rebuild_header(self) -> None:
await self.query("*")[1].remove()
await self.mount(self._header, after=self._title)
async def _rebuild_rows(
self,
row_type: Any, # noqa: ANN401
start_index: int = 0,
end_index: int | None = None,
) -> None:
rows = self.query(row_type)
assert start_index < len(
rows
), "Starting_from_element parameter has higher value than number of elements in the table"
if end_index:
assert (
start_index < end_index
), "Starting_from_element parameter has higher value than ending_with_element argument"
for index in range(start_index, end_index + 1 if end_index else len(rows)):
await rows[index].remove()
self._mount_static_rows(start_index, end_index)
async def rebuild(
self,
content: Content | None = None,
row_type: Any = None, # noqa: ANN401
rebuild_header: bool = False,
starting_from_element: int = 0,
ending_with_element: int | None = None,
) -> None:
......@@ -213,31 +237,13 @@ class CliveCheckerboardTable(CliveWidget):
if not self.should_be_dynamic and content is not None: # content is given, but table is static
raise RebuildStaticTableWithContentError
with self.app.batch_update():
if starting_from_element == 0 and ending_with_element is None:
await self.query("*").remove()
await self.mount_all(self._create_table_content(content))
if rebuild_header:
await self._rebuild_header()
if self.should_be_dynamic:
self._create_table_content(content)
else:
rows = self.query(row_type)
assert row_type, "You have to set row_type."
assert starting_from_element < len(
rows
), "Starting_from_element parameter has higher value than number of elements in the table"
if ending_with_element:
assert (
starting_from_element < ending_with_element
), "Starting_from_element parameter has higher value than ending_with_element argument"
# remove elements
for index in range(
starting_from_element, ending_with_element + 1 if ending_with_element else len(rows)
):
await rows[index].remove()
# mount again - rebuild only rows after index
(
self._mount_static_rows(starting_from_element, ending_with_element)
if not self.should_be_dynamic
else self._create_table_content(content)
)
await self._rebuild_rows(row_type, starting_from_element, ending_with_element)
def _create_table_content(
self, content: Content | None = None, rows_from_index: int = 0, rows_to_index: int | None = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment