Change cutleft to support selecting a single column
parent
8059544e26
commit
04045b0e9e
30
cutleft.py
30
cutleft.py
|
|
@ -82,7 +82,7 @@ def stitch_images(image_list):
|
||||||
|
|
||||||
return combined
|
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.
|
Converts PDF to stitched images.
|
||||||
Returns a tuple: (preview_image_resized, list_of_split_images, schema_dict)
|
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:
|
for img in pages:
|
||||||
width, height = img.size
|
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
|
# Ensure crop box is valid
|
||||||
left = max(0, left)
|
left = max(0, left)
|
||||||
|
|
@ -110,7 +117,7 @@ def process_single_pdf(filename, shift_offset=0):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 1. Generate Schema / Distribution
|
# 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)
|
# 2. Generate Split Images (Full Resolution)
|
||||||
split_images = []
|
split_images = []
|
||||||
|
|
@ -168,6 +175,7 @@ class ImageReviewer:
|
||||||
self.files = file_list
|
self.files = file_list
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.current_shift = 0
|
self.current_shift = 0
|
||||||
|
self.current_max_per_file = 5
|
||||||
self.current_preview = None # Only stores the resized preview for GUI
|
self.current_preview = None # Only stores the resized preview for GUI
|
||||||
self.is_processing = False
|
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(50))
|
||||||
self.root.bind('N', lambda e: self.on_shift(100))
|
self.root.bind('N', lambda e: self.on_shift(100))
|
||||||
self.root.bind('t', lambda e: self.on_shift(-50))
|
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
|
# Start background pre-fetcher
|
||||||
self.bg_thread = Thread(target=self.prefetch_worker, daemon=True)
|
self.bg_thread = Thread(target=self.prefetch_worker, daemon=True)
|
||||||
|
|
@ -204,6 +214,14 @@ class ImageReviewer:
|
||||||
self.root.focus_force()
|
self.root.focus_force()
|
||||||
self.root.mainloop()
|
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):
|
def prefetch_worker(self):
|
||||||
"""Background thread to process the NEXT image constantly."""
|
"""Background thread to process the NEXT image constantly."""
|
||||||
idx_to_process = 0
|
idx_to_process = 0
|
||||||
|
|
@ -249,7 +267,7 @@ class ImageReviewer:
|
||||||
self.label_info.configure(text=f"Processing {filename} (Shift {shift})... Please wait.", fg="red")
|
self.label_info.configure(text=f"Processing {filename} (Shift {shift})... Please wait.", fg="red")
|
||||||
|
|
||||||
def worker():
|
def worker():
|
||||||
res = process_single_pdf(filename, shift)
|
res = process_single_pdf(filename, shift, self.current_max_per_file)
|
||||||
self.manual_queue.put(res)
|
self.manual_queue.put(res)
|
||||||
|
|
||||||
Thread(target=worker, daemon=True).start()
|
Thread(target=worker, daemon=True).start()
|
||||||
|
|
@ -309,6 +327,7 @@ class ImageReviewer:
|
||||||
return
|
return
|
||||||
self.index += 1
|
self.index += 1
|
||||||
self.current_shift = 0
|
self.current_shift = 0
|
||||||
|
self.current_max_per_file = 5 # Reset to default
|
||||||
self.load_current_image(use_prefetch=True)
|
self.load_current_image(use_prefetch=True)
|
||||||
|
|
||||||
# --- Entry Point ---
|
# --- Entry Point ---
|
||||||
|
|
@ -317,4 +336,3 @@ if __name__ == "__main__":
|
||||||
print("No PDF files found.")
|
print("No PDF files found.")
|
||||||
else:
|
else:
|
||||||
app = ImageReviewer(files)
|
app = ImageReviewer(files)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue