Manual conflict : utilities

This commit is contained in:
sebastien committed 2026-10-06 11:11:03 +02:00
1 parent f43b713590
commit c155e3eebc
3 files changed
+100 -3

No files matched your search

+38 -2
View File
@@ -5,6 +5,7 @@ from pathlib import Path
from tkinter import messagebox, ttk
from copienator import CliError
from copienator.answer_origins import populated_labels
from copienator.commands.resolve_manual import get_actual_pdf, parse_instruction_text
from copienator.platform import open_path
from .cut_helper import CutHelper
@@ -41,6 +42,7 @@ class ManualResolutionPanel(ttk.Frame):
self.get_evaluation = get_evaluation
self.pdf_buttons = []
self.cut_buttons = []
self.copy_buttons = []
actions = ttk.Frame(self)
actions.pack(fill="x")
self.editor_button = ttk.Button(
@@ -92,11 +94,25 @@ class ManualResolutionPanel(ttk.Frame):
except (OSError, RuntimeError) as exc:
messagebox.showerror("Ouverture du PDF", str(exc))
def open_copy(self, evaluation, copy_id, *, directory=False):
path = evaluation / "Copies" / f"Copie{copy_id}"
if not directory:
path = path.with_suffix(".pdf")
try:
if directory and not path.is_dir():
raise FileNotFoundError(f"Dossier introuvable : {path}")
if not directory and not path.is_file():
raise FileNotFoundError(f"PDF introuvable : {path}")
open_path(path)
except (OSError, RuntimeError) as exc:
messagebox.showerror("Ouverture du dossier" if directory else "Ouverture du PDF", str(exc))
def reload(self):
for button in self.pdf_buttons + self.cut_buttons:
for button in self.pdf_buttons + self.cut_buttons + self.copy_buttons:
button.destroy()
self.pdf_buttons.clear()
self.cut_buttons.clear()
self.copy_buttons.clear()
self.cut_result.set("")
self.text.configure(state="normal")
self.text.delete("1.0", "end")
@@ -111,7 +127,10 @@ class ManualResolutionPanel(ttk.Frame):
else:
self.editor_button.configure(state="normal")
malformed = []
provenance = {}
provenance_error = ""
for number, raw in enumerate(content.splitlines(keepends=True), 1):
populated = []
self.text.insert("end", raw.rstrip("\r\n"))
try:
instructions = parse_instruction_text(raw)
@@ -120,6 +139,21 @@ class ManualResolutionPanel(ttk.Frame):
else:
if instructions:
instruction = instructions[0]
key = (instruction.copy_id, instruction.old_label)
if key not in provenance:
try:
provenance[key] = populated_labels(path.parent, *key)
except (OSError, ValueError) as exc:
provenance[key] = []
provenance_error = f" — Provenance indisponible : {exc}"
populated = provenance[key]
for title, directory in (("pdf", False), ("dir", True)):
button = ttk.Button(
self.text, text=title, width=3,
command=lambda directory=directory, copy_id=instruction.copy_id, root=path.parent: self.open_copy(root, copy_id, directory=directory),
)
self.copy_buttons.append(button)
self.text.window_create("end", window=button, padx=2)
for title, label in (("Source", instruction.old_label),
("Cible", instruction.new_label)):
button = ttk.Button(
@@ -132,12 +166,14 @@ class ManualResolutionPanel(ttk.Frame):
command=lambda item=instruction, root=path.parent: self.open_cut(root, item))
self.cut_buttons.append(button)
self.text.window_create("end", window=button, padx=8)
if populated:
self.text.insert("end", "\n# -> " + ", ".join(populated))
if raw.endswith("\n"):
self.text.insert("end", "\n")
detail = (" — lignes invalides : " + ", ".join(malformed)) if malformed else (
f" — {len(self.pdf_buttons) // 2} instruction(s)"
)
self.status.configure(text=str(path) + detail)
self.status.configure(text=str(path) + detail + provenance_error)
finally:
self.text.configure(state="disabled")