Automatic orientation issues detection and fix, experimental
This commit is contained in:
1 parent
78a7b7679c
commit
46845c4612
12 files changed
+683
-9
No files matched your search
+39
-1
@@ -4,6 +4,7 @@ import os
|
||||
import queue
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tkinter as tk
|
||||
from dataclasses import replace
|
||||
from pathlib import Path
|
||||
@@ -13,6 +14,7 @@ from typing import Any
|
||||
from copienator import CliError, EvaluationWorkspace, ExitCode, atomic_write_json, read_json
|
||||
from copienator.commands.resolve_manual import pending_manual_conflicts
|
||||
from copienator.copy_errors import copy_errors
|
||||
from copienator.orientation import reports as orientation_reports
|
||||
from copienator.filesystem import staged_files
|
||||
from copienator.platform import (
|
||||
WindowsLabelError,
|
||||
@@ -1204,6 +1206,28 @@ class CopienatorApp(tk.Tk):
|
||||
self.marked_copies_button.grid(row=4, column=0, columnspan=2, sticky="w", pady=(7, 0))
|
||||
ttk.Label(copies, text=marked_summary, wraplength=570).grid(
|
||||
row=5, column=0, columnspan=2, sticky="w")
|
||||
if step.id == 'labels' and evaluation:
|
||||
try:
|
||||
orientation = orientation_reports(EvaluationWorkspace(evaluation))
|
||||
except (OSError, ValueError, TypeError) as exc:
|
||||
orientation = {}
|
||||
self._append_console(f'Rapports d’orientation illisibles : {exc}\n')
|
||||
if orientation:
|
||||
lines = []
|
||||
for name, report in orientation.items():
|
||||
pages = sorted({p for values in report.get('images', {}).values() for p in values})
|
||||
lines.append(f'{name} : pages à l’envers {pages}' if pages else f'{name} : orientation à vérifier')
|
||||
if report.get('warning'):
|
||||
lines.append(report['warning'])
|
||||
ttk.Label(copies, text='\n'.join(lines), wraplength=570).grid(
|
||||
row=6, column=0, columnspan=2, sticky='w')
|
||||
orientation_actions = ttk.Frame(copies)
|
||||
orientation_actions.grid(row=7, column=0, columnspan=2, sticky='w', pady=7)
|
||||
state = 'disabled' if self.active_step_id or self.runner.running else 'normal'
|
||||
ttk.Button(orientation_actions, text='Signaler ces copies', state=state,
|
||||
command=self._flag_orientation_copies).pack(side='left')
|
||||
ttk.Button(orientation_actions, text='Corriger automatiquement l’orientation', state=state,
|
||||
command=lambda: self._run_current_step(orientation_repair=True)).pack(side='left', padx=6)
|
||||
row += 1
|
||||
|
||||
if step.id == "plotting":
|
||||
@@ -1324,6 +1348,14 @@ class CopienatorApp(tk.Tk):
|
||||
self.arg_vars["marked"].set(True)
|
||||
self._run_current_step()
|
||||
|
||||
def _flag_orientation_copies(self) -> None:
|
||||
if not self.evaluation or self.active_step_id or self.runner.running:
|
||||
return
|
||||
from copienator.commands.repair_orientation import run
|
||||
run(EvaluationWorkspace(self.evaluation), self.evaluation, flag=True)
|
||||
self.info_var.set('Copies signalées : reprenez les étapes précédentes avec « Traiter les copies signalées ».')
|
||||
self._render_step()
|
||||
|
||||
def _open_desktop_path(self, path: Path | None, label: str) -> None:
|
||||
if path is None or not path.exists():
|
||||
messagebox.showerror("Élément introuvable", f"Le {label} n’existe pas encore.")
|
||||
@@ -1561,9 +1593,11 @@ class CopienatorApp(tk.Tk):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _run_current_step(self, *, syncthing_ready=False, review_command=None) -> None:
|
||||
def _run_current_step(self, *, syncthing_ready=False, review_command=None, orientation_repair=False) -> None:
|
||||
step = self.current_step
|
||||
evaluation = self.evaluation
|
||||
if orientation_repair and (not step or step.id != 'labels'):
|
||||
return
|
||||
if review_command is not None and (
|
||||
not step or step.id != "personal_read" or review_command not in {"re", "wsn", "we"}
|
||||
):
|
||||
@@ -1624,6 +1658,8 @@ class CopienatorApp(tk.Tk):
|
||||
return
|
||||
variant = self._current_variant()
|
||||
command = self._make_command()
|
||||
if orientation_repair:
|
||||
command = [sys.executable, '-m', 'copienator', 'repair-orientation', str(evaluation)]
|
||||
if step.id == "personal_read":
|
||||
command = ["gestion_classe", review_command]
|
||||
if variant.dangerous and not messagebox.askyesno(
|
||||
@@ -2045,6 +2081,8 @@ class CopienatorApp(tk.Tk):
|
||||
self.active_step_id = None
|
||||
self._populate_tree()
|
||||
self._update_controls()
|
||||
if step_id == 'labels' and self.current_step and self.current_step.id == 'labels':
|
||||
self._render_step()
|
||||
if step_id == 'statement_persp':
|
||||
self._refresh_persp_inventory()
|
||||
if step_id == "statement" and self._latex_warning_paths:
|
||||
|
||||
Reference in new issue
Block a user