Miscs changes (Interro22)
This commit is contained in:
+16
-7
@@ -5,6 +5,7 @@ import re
|
||||
import queue
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from pathlib import Path
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageTk
|
||||
|
||||
@@ -112,22 +113,27 @@ def worker_thread(base_dir, files_to_process, all_labels):
|
||||
nb_pages = json_schema["columns_per_file"][copie_part-1]
|
||||
|
||||
if json_path.exists():
|
||||
# Read strictly for visualization purposes
|
||||
bb_list = []
|
||||
json_name = ""
|
||||
try:
|
||||
# Read strictly for visualization purposes
|
||||
with open(json_path, 'r') as f:
|
||||
json_result = json.load(f)
|
||||
|
||||
bb_list = json_result.get("list", [])
|
||||
print(f"Buffering {img_path.name}...")
|
||||
json_name = json_result.get("name", "")
|
||||
except Exception as e:
|
||||
print(f"Warning: {json_path.name} is malformed! Loading blank. {e}")
|
||||
# We do NOT skip; we continue so the user can fix it in the GUI
|
||||
|
||||
try:
|
||||
print(f"Buffering {img_path.name}...")
|
||||
pil_image = prepare_image(str(img_path), bb_list, all_labels, nb_pages)
|
||||
|
||||
# Package metadata needed for final calculation later
|
||||
metadata = {
|
||||
"copie": copie,
|
||||
"part": copie_part,
|
||||
"schema": json_schema,
|
||||
"name": json_result.get("name", "")
|
||||
"name": json_name
|
||||
}
|
||||
|
||||
image_queue.put((pil_image, json_path, metadata))
|
||||
@@ -222,7 +228,6 @@ class ImageViewer:
|
||||
if self.is_viewing:
|
||||
print(f"Committing data for {self.current_json_path.name}...")
|
||||
|
||||
# --- CRITICAL CHANGE: Re-read JSON here to capture user edits ---
|
||||
try:
|
||||
with open(self.current_json_path, 'r') as f:
|
||||
current_data = json.load(f)
|
||||
@@ -242,7 +247,11 @@ class ImageViewer:
|
||||
self.accumulated_results["name"] = current_data["name"]
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error re-reading/saving {self.current_json_path}: {e}")
|
||||
# Warn user and STOP (do not advance to next image)
|
||||
msg = f"Error reading {self.current_json_path.name}:\n\n{e}\n\nPlease press 'e' to fix it, then press Enter again."
|
||||
print(msg)
|
||||
messagebox.showerror("JSON Error", msg)
|
||||
return # Abort advancement
|
||||
|
||||
# Advance UI
|
||||
self.is_viewing = False
|
||||
|
||||
Reference in New Issue
Block a user