better cutleft : wider and cleans up
parent
6ace0c3b03
commit
11b63ec402
20
cutleft.py
20
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 <directory_path_or_file_path>")
|
||||
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue