From a6b68e31d835c391d5b4de4011719a04e4ddaa12 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 1 Jun 2023 16:19:48 +0200 Subject: [PATCH] init: pager --- src/gui.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/gui.py b/src/gui.py index 141b40a..b9dc8e3 100644 --- a/src/gui.py +++ b/src/gui.py @@ -91,21 +91,27 @@ class GUI: def _analyse(self, start_row: int, path: str) -> None: """Analyse les données""" - - self.f.destroy() - self.f = Frame(self.parent) - self.f.grid() - files = analyze_args([path]) - idx = start_row + data = [] for file in files: clang_format_output = clang_format(file) - parsed_output = parse_clang_format_output(clang_format_output) + data.append((file, parse_clang_format_output(clang_format_output))) + self._pager(1, data, start_row) - if parsed_output: - for error in parsed_output: + def _pager(self, num_page: int, errors: list, start_row: int) -> None: + self.f.destroy() + self.f = Frame(self.parent) + self.f.grid(columnspan=2) + + idx = start_row + elem_per_page = 5 + for file, error in errors: + if error: + for error in error[ + elem_per_page * (num_page - 1) : elem_per_page * num_page + ]: Button( - self.parent, + self.f, text=f"Avertissement dans {error.filename} " f"à la ligne {error.line_number}, " f"caractère {error.column_number}.", @@ -119,8 +125,19 @@ class GUI: idx += 1 else: Label( - self.parent, + self.f, bg="MediumSpringGreen", text=f"Aucun avertissement trouvé dans {file}.", ).grid(column=0, row=idx, columnspan=2) idx += 1 + + Button( + self.f, + text="Page précédente <", + command=lambda: print("avant"), + ).grid(column=0, row=idx) + Button( + self.f, + text="Page suivante >", + command=lambda: print("apres"), + ).grid(column=1, row=idx)