Change cutleft to support selecting a single column
parent
8059544e26
commit
04045b0e9e
26
cutleft.py
26
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,6 +94,13 @@ def process_single_pdf(filename, shift_offset=0):
|
|||
|
||||
for img in pages:
|
||||
width, height = img.size
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue