From 44bfb5b45ea99f2235b1dfc81488caa77f22cd41 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 1 Jun 2023 12:49:10 +0200 Subject: [PATCH] clickable error msg --- gui.py | 25 ++++++++++++++++++++----- src/clangformat.py | 7 +++++-- src/errors.py | 13 ++++++++++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gui.py b/gui.py index e8818d9..ab96b39 100644 --- a/gui.py +++ b/gui.py @@ -1,5 +1,5 @@ import sys -from tkinter import Button, Frame, Label, Tk +from tkinter import Button, Frame, Label, Tk, Toplevel from tkinter.filedialog import askdirectory, askopenfile from src.clangformat import clang_format, parse_clang_format_output @@ -73,6 +73,17 @@ class GUI: self.parent, text="Ouvrir un dossier", command=self._open_directory ).grid(column=1, row=1) + def _show_info(self, msg: str) -> None: + title = f"Contenu de l'avertissement - {self.name}" + info = Toplevel() + info.resizable(False, False) + info.title(title) + Label(info, text=msg).pack() + + width = max([len(line) for line in [title] + msg.splitlines()]) * 12 + height = (3 + msg.count("\n")) * 10 + info.geometry(f"{width}x{height}") + def _analyse(self, start_row: int, path: str) -> None: """Analyse les données""" @@ -88,16 +99,20 @@ class GUI: if parsed_output: for error in parsed_output: - Label( + Button( self.parent, text=f"Avertissement dans {error.filename} " - f"à la ligne {error.line_number}," + f"à la ligne {error.line_number}, " f"caractère {error.column_number}.", - ).grid(column=0, row=idx, columnspan=1) + borderwidth=0, + justify="left", + anchor="w", + command=lambda: self._show_info(error.warning_content), + ).grid(column=0, row=idx) idx += 1 else: Label( self.parent, text=f"Aucun avertissement trouvé dans {file}.", - ).grid(column=0, row=idx, columnspan=1) + ).grid(column=0, row=idx) idx += 1 diff --git a/src/clangformat.py b/src/clangformat.py index 3ae79af..4706664 100644 --- a/src/clangformat.py +++ b/src/clangformat.py @@ -25,8 +25,9 @@ def clang_format(file_path) -> str: def parse_clang_format_output(output) -> list[ClangError]: error_pattern = ( - r"(?P.+):(?P\d+):(?P\d+):" - r" warning: code should be clang-formatted \[(?P.+)\]" + r"(?P.+):(?P\d+):(?P\d+)" + r": warning: code should be clang-formatted \[(?P.+)\]" + r"\n(?P(.)*\n?(.)*)" ) error_matches = re.finditer(error_pattern, output) @@ -36,6 +37,7 @@ def parse_clang_format_output(output) -> list[ClangError]: line_number = int(error_match.group("line_number")) column_number = int(error_match.group("column_number")) warning_message = str(error_match.group("warning_message")) + warning_content = str(error_match.group("warning_content")) errors.append( ClangError( @@ -43,6 +45,7 @@ def parse_clang_format_output(output) -> list[ClangError]: line_number, column_number, warning_message[1:], + warning_content, ) ) diff --git a/src/errors.py b/src/errors.py index f480d46..2e49042 100644 --- a/src/errors.py +++ b/src/errors.py @@ -1,11 +1,17 @@ class ClangError: def __init__( - self, filename: str, line_number: int, column_number: int, warning_message: str + self, + filename: str, + line_number: int, + column_number: int, + warning_message: str, + warning_content: str, ) -> None: self._filename = filename self._line_number = line_number self._column_number = column_number self._warning_message = warning_message + self._warning_content = warning_content @property def filename(self) -> str: @@ -26,3 +32,8 @@ class ClangError: def warning_message(self) -> str: """Quelle est le nom de l'erreur""" return self._warning_message + + @property + def warning_content(self) -> str: + """Quelle est le contenu de l'erreur""" + return self._warning_content