From 11b63ec402fe272bd062bcb74bedc595c842e76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= Date: Sun, 8 Feb 2026 15:50:19 +0100 Subject: [PATCH] better cutleft : wider and cleans up --- cutleft.py | 20 +++++++++++++++++--- page_splitter.py | 3 +-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cutleft.py b/cutleft.py index 9283e1e..83f7f43 100644 --- a/cutleft.py +++ b/cutleft.py @@ -11,7 +11,7 @@ from PIL import Image, ImageTk # --- Configuration --- DELIMITER_WIDTH = 5 DELIMITER_COLOR = (0, 0, 0) -OUTPUT_SIZE = (1000, 1000) +OUTPUT_SIZE = (1800, 1000) if len(sys.argv) < 2: sys.exit("Usage: python script.py ") @@ -152,6 +152,21 @@ def save_results(result_tuple, filename): _, splits, schema = result_tuple base_name = os.path.splitext(filename)[0] + # --- Cleanup: Delete existing files for this PDF --- + for f in os.listdir(OUTPUT_DIR): + file_path = os.path.join(OUTPUT_DIR, f) + # 1. Delete schema file + if f == f"{base_name}_schema.json": + os.remove(file_path) + # 2. Delete image files (pattern: basename_01.jpg, etc.) + elif f.startswith(f"{base_name}_") and f.endswith(".jpg"): + # Check if the suffix is strictly numeric (e.g. "01") to avoid + # deleting unrelated files like "file_v2_01.jpg" when processing "file.pdf" + suffix = f[len(base_name)+1:-4] + if suffix.isdigit(): + os.remove(file_path) + # --------------------------------------------------- + # Save Images for i, img in enumerate(splits): # Suffix _01, _02, etc. @@ -167,7 +182,6 @@ def save_results(result_tuple, filename): with open(json_path, 'w') as f: json.dump(schema, f, indent=4) print(f"Saved schema: {json_filename}") - # --- GUI Application --- class ImageReviewer: @@ -311,7 +325,7 @@ class ImageReviewer: self.label_info.configure( text=f"[{self.index+1}/{len(self.files)}] {filename} | Shift: {self.current_shift}px" f"{schema_info}\n" - f"Enter: Next | n: +50 | N: +100 | t: -50", + f"Enter: Next | n: +50 | N: +100 | t: -50 | 1: use single column", fg="black" ) diff --git a/page_splitter.py b/page_splitter.py index 71a162f..9dbd1aa 100644 --- a/page_splitter.py +++ b/page_splitter.py @@ -312,7 +312,7 @@ class PDFPreviewer: # Move the temp output file to replace the original shutil.move(self.final_file, self.pdf_path) - print(f"Original moved to {backup_path}, new file saved at {self.pdf_path}") + # print(f"Original moved to {backup_path}, new file saved at {self.pdf_path}") except Exception as e: messagebox.showerror("Error", f"Failed to move/replace files: {e}") @@ -445,4 +445,3 @@ if __name__ == "__main__": root = tk.Tk() app = PDFPreviewer(root, pdf_file_path) root.mainloop() -