diff --git a/plotting.py b/plotting.py index b1b326e..aed3045 100644 --- a/plotting.py +++ b/plotting.py @@ -1,6 +1,7 @@ import sys import json import threading +import re import queue import subprocess import tkinter as tk @@ -237,7 +238,8 @@ class ImageViewer: if self.accumulated_results: self.accumulated_results["list"].extend(converted_items) # Update name just in case (though usually consistent per group) - self.accumulated_results["name"] = current_data.get("name", self.accumulated_results["name"]) + if "name" in current_data and current_data["name"] != "Continued": + self.accumulated_results["name"] = current_data["name"] except Exception as e: print(f"Error re-reading/saving {self.current_json_path}: {e}") @@ -281,6 +283,10 @@ class ImageViewer: self.root.clipboard_clear() self.root.clipboard_append(box_str) +def natural_key(text): + return [int(c) if c.isdigit() else c.lower() for c in re.split(r'(\d+)', str(text))] + + if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python plotting.py ") @@ -290,16 +296,20 @@ if __name__ == "__main__": files_to_process = [] if input_path.is_file(): + base_dir = input_path.parent stem = input_path.stem img_path = base_dir / "Cutleft" / f"{stem}.jpg" + files_to_process = [img_path] if not img_path.exists() and input_path.parent.name == "Cutleft": base_dir = input_path.parent.parent img_path = input_path + files_to_process = [img_path] if not img_path.exists(): - print(f"Error: Could not find image at {img_path}") - sys.exit(1) - files_to_process = [img_path] + # We're given Copie01.pdf, look for parts + cutleft_dir = base_dir / "Cutleft" + files_to_process = sorted(list(cutleft_dir.glob(f"{img_path.stem}_*.jpg")), + key=natural_key) else: base_dir = input_path cutleft_dir = base_dir / "Cutleft"