From 04045b0e9e4b42277bb052835bc3f938b1ce9659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= Date: Sun, 8 Feb 2026 13:44:27 +0100 Subject: [PATCH] Change cutleft to support selecting a single column --- cutleft.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/cutleft.py b/cutleft.py index a78cbed..9283e1e 100644 --- a/cutleft.py +++ b/cutleft.py @@ -82,7 +82,7 @@ def stitch_images(image_list): return combined -def process_single_pdf(filename, shift_offset=0): +def process_single_pdf(filename, shift_offset=0, max_per_file=5): """ Converts PDF to stitched images. Returns a tuple: (preview_image_resized, list_of_split_images, schema_dict) @@ -94,8 +94,15 @@ def process_single_pdf(filename, shift_offset=0): for img in pages: width, height = img.size - left = 100 + shift_offset - right = (width // 3) + 100 + shift_offset + + if max_per_file == 1: + # If Single Page mode, take the full width (ignore shift/crop) + left = 0 + right = width + else: + # Original "Cutleft" logic (approx 1/3 width) + left = 100 + shift_offset + right = (width // 3) + 100 + shift_offset # Ensure crop box is valid left = max(0, left) @@ -110,7 +117,7 @@ def process_single_pdf(filename, shift_offset=0): return None # 1. Generate Schema / Distribution - col_distribution = distribute_pages(len(cropped_images), max_per_file=5) + col_distribution = distribute_pages(len(cropped_images), max_per_file=max_per_file) # 2. Generate Split Images (Full Resolution) split_images = [] @@ -168,6 +175,7 @@ class ImageReviewer: self.files = file_list self.index = 0 self.current_shift = 0 + self.current_max_per_file = 5 self.current_preview = None # Only stores the resized preview for GUI self.is_processing = False @@ -192,6 +200,8 @@ class ImageReviewer: self.root.bind('n', lambda e: self.on_shift(50)) self.root.bind('N', lambda e: self.on_shift(100)) self.root.bind('t', lambda e: self.on_shift(-50)) + self.root.bind('1', lambda e: self.on_set_max_pages(1)) # New Binding + # Start background pre-fetcher self.bg_thread = Thread(target=self.prefetch_worker, daemon=True) @@ -204,6 +214,14 @@ class ImageReviewer: self.root.focus_force() self.root.mainloop() + def on_set_max_pages(self, count): + if self.is_processing: + return + self.current_max_per_file = count + print(f"Setting max pages per file: {count}") + # Trigger reprocessing with current settings + self.trigger_processing(self.files[self.index], self.current_shift) + def prefetch_worker(self): """Background thread to process the NEXT image constantly.""" idx_to_process = 0 @@ -249,7 +267,7 @@ class ImageReviewer: self.label_info.configure(text=f"Processing {filename} (Shift {shift})... Please wait.", fg="red") def worker(): - res = process_single_pdf(filename, shift) + res = process_single_pdf(filename, shift, self.current_max_per_file) self.manual_queue.put(res) Thread(target=worker, daemon=True).start() @@ -309,6 +327,7 @@ class ImageReviewer: return self.index += 1 self.current_shift = 0 + self.current_max_per_file = 5 # Reset to default self.load_current_image(use_prefetch=True) # --- Entry Point --- @@ -317,4 +336,3 @@ if __name__ == "__main__": print("No PDF files found.") else: app = ImageReviewer(files) -