clickable error msg
This commit is contained in:
parent
0c2abd9b32
commit
44bfb5b45e
3 changed files with 37 additions and 8 deletions
25
gui.py
25
gui.py
|
@ -1,5 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
from tkinter import Button, Frame, Label, Tk
|
from tkinter import Button, Frame, Label, Tk, Toplevel
|
||||||
from tkinter.filedialog import askdirectory, askopenfile
|
from tkinter.filedialog import askdirectory, askopenfile
|
||||||
|
|
||||||
from src.clangformat import clang_format, parse_clang_format_output
|
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
|
self.parent, text="Ouvrir un dossier", command=self._open_directory
|
||||||
).grid(column=1, row=1)
|
).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:
|
def _analyse(self, start_row: int, path: str) -> None:
|
||||||
"""Analyse les données"""
|
"""Analyse les données"""
|
||||||
|
|
||||||
|
@ -88,16 +99,20 @@ class GUI:
|
||||||
|
|
||||||
if parsed_output:
|
if parsed_output:
|
||||||
for error in parsed_output:
|
for error in parsed_output:
|
||||||
Label(
|
Button(
|
||||||
self.parent,
|
self.parent,
|
||||||
text=f"Avertissement dans {error.filename} "
|
text=f"Avertissement dans {error.filename} "
|
||||||
f"à la ligne {error.line_number},"
|
f"à la ligne {error.line_number}, "
|
||||||
f"caractère {error.column_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
|
idx += 1
|
||||||
else:
|
else:
|
||||||
Label(
|
Label(
|
||||||
self.parent,
|
self.parent,
|
||||||
text=f"Aucun avertissement trouvé dans {file}.",
|
text=f"Aucun avertissement trouvé dans {file}.",
|
||||||
).grid(column=0, row=idx, columnspan=1)
|
).grid(column=0, row=idx)
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
|
@ -25,8 +25,9 @@ def clang_format(file_path) -> str:
|
||||||
|
|
||||||
def parse_clang_format_output(output) -> list[ClangError]:
|
def parse_clang_format_output(output) -> list[ClangError]:
|
||||||
error_pattern = (
|
error_pattern = (
|
||||||
r"(?P<filename>.+):(?P<line_number>\d+):(?P<column_number>\d+):"
|
r"(?P<filename>.+):(?P<line_number>\d+):(?P<column_number>\d+)"
|
||||||
r" warning: code should be clang-formatted \[(?P<warning_message>.+)\]"
|
r": warning: code should be clang-formatted \[(?P<warning_message>.+)\]"
|
||||||
|
r"\n(?P<warning_content>(.)*\n?(.)*)"
|
||||||
)
|
)
|
||||||
error_matches = re.finditer(error_pattern, output)
|
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"))
|
line_number = int(error_match.group("line_number"))
|
||||||
column_number = int(error_match.group("column_number"))
|
column_number = int(error_match.group("column_number"))
|
||||||
warning_message = str(error_match.group("warning_message"))
|
warning_message = str(error_match.group("warning_message"))
|
||||||
|
warning_content = str(error_match.group("warning_content"))
|
||||||
|
|
||||||
errors.append(
|
errors.append(
|
||||||
ClangError(
|
ClangError(
|
||||||
|
@ -43,6 +45,7 @@ def parse_clang_format_output(output) -> list[ClangError]:
|
||||||
line_number,
|
line_number,
|
||||||
column_number,
|
column_number,
|
||||||
warning_message[1:],
|
warning_message[1:],
|
||||||
|
warning_content,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
class ClangError:
|
class ClangError:
|
||||||
def __init__(
|
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:
|
) -> None:
|
||||||
self._filename = filename
|
self._filename = filename
|
||||||
self._line_number = line_number
|
self._line_number = line_number
|
||||||
self._column_number = column_number
|
self._column_number = column_number
|
||||||
self._warning_message = warning_message
|
self._warning_message = warning_message
|
||||||
|
self._warning_content = warning_content
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def filename(self) -> str:
|
def filename(self) -> str:
|
||||||
|
@ -26,3 +32,8 @@ class ClangError:
|
||||||
def warning_message(self) -> str:
|
def warning_message(self) -> str:
|
||||||
"""Quelle est le nom de l'erreur"""
|
"""Quelle est le nom de l'erreur"""
|
||||||
return self._warning_message
|
return self._warning_message
|
||||||
|
|
||||||
|
@property
|
||||||
|
def warning_content(self) -> str:
|
||||||
|
"""Quelle est le contenu de l'erreur"""
|
||||||
|
return self._warning_content
|
||||||
|
|
Reference in a new issue