58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
import sys
|
|
from tkinter import Frame, Label, Tk
|
|
|
|
from src.clangformat import clang_format, parse_clang_format_output
|
|
from src.utils import analyze_args
|
|
|
|
|
|
class GUI:
|
|
def __init__(self) -> None:
|
|
self.name = "Errsy"
|
|
self.parent = Tk()
|
|
self.parent.resizable(False, False)
|
|
self.f = Frame(self.parent)
|
|
|
|
def start(self) -> None:
|
|
"""Affiche la fenêtre"""
|
|
self._main_screen()
|
|
self.f.grid()
|
|
# self.change_pos(1280, 720)
|
|
self.parent.title(self.name)
|
|
self.parent.mainloop()
|
|
|
|
def change_pos(self, x: int, y: int) -> None:
|
|
"""Change les dimensions de la fenêtre"""
|
|
width = self.parent.winfo_screenwidth()
|
|
height = self.parent.winfo_screenheight()
|
|
|
|
# Centre
|
|
x_i = (width // 2) - (x // 2)
|
|
y_i = (height // 2) - (y // 2)
|
|
|
|
self.parent.geometry(f"{x}x{y}+{x_i}+{y_i}")
|
|
|
|
def _main_screen(self):
|
|
"""Écran principal"""
|
|
Label(
|
|
self.parent,
|
|
text=f"{self.name} est une application qui permet d'utiliser "
|
|
"plus facilement clang-format",
|
|
).grid(column=0, row=0, columnspan=1)
|
|
self._analyse()
|
|
|
|
def _analyse(self) -> None:
|
|
"""Analyse les données"""
|
|
files = analyze_args(sys.argv[1:])
|
|
for file in files:
|
|
clang_format_output = clang_format(file)
|
|
parsed_output = parse_clang_format_output(clang_format_output)
|
|
|
|
if parsed_output:
|
|
for idx, error in enumerate(parsed_output):
|
|
Label(
|
|
self.parent,
|
|
text=f"Avertissement dans {error.filename} "
|
|
f"à la ligne {error.line_number}, caractère {error.column_number}.",
|
|
).grid(column=0, row=idx + 1, columnspan=1)
|
|
else:
|
|
print(f"Aucun avertissement trouvé dans {file}.")
|