clickable error msg

This commit is contained in:
Mylloon 2023-06-01 12:49:10 +02:00
parent 0c2abd9b32
commit 44bfb5b45e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 37 additions and 8 deletions

23
gui.py
View file

@ -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"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

View file

@ -25,8 +25,9 @@ def clang_format(file_path) -> str:
def parse_clang_format_output(output) -> list[ClangError]:
error_pattern = (
r"(?P<filename>.+):(?P<line_number>\d+):(?P<column_number>\d+):"
r" warning: code should be clang-formatted \[(?P<warning_message>.+)\]"
r"(?P<filename>.+):(?P<line_number>\d+):(?P<column_number>\d+)"
r": warning: code should be clang-formatted \[(?P<warning_message>.+)\]"
r"\n(?P<warning_content>(.)*\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,
)
)

View file

@ -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