Changes to page_splitter : get rid of output directory
parent
690936a3f9
commit
6ace0c3b03
|
|
@ -26,10 +26,10 @@ class PDFPreviewer:
|
||||||
self.base_name = os.path.splitext(os.path.basename(self.pdf_path))[0]
|
self.base_name = os.path.splitext(os.path.basename(self.pdf_path))[0]
|
||||||
self.split_dir = f"{self.base_name}_split"
|
self.split_dir = f"{self.base_name}_split"
|
||||||
self.reorder_dir = f"{self.base_name}_reorder"
|
self.reorder_dir = f"{self.base_name}_reorder"
|
||||||
if self.output_dir is None:
|
|
||||||
self.final_file = f"{self.base_name}_final"
|
# Create a temporary output file
|
||||||
else:
|
self.final_file = f"{self.base_name}_temp.pdf"
|
||||||
self.final_file = f"{self.output_dir}/Copie{self.num:02}.pdf"
|
|
||||||
self.current_page_index = 0
|
self.current_page_index = 0
|
||||||
self.page_settings = []
|
self.page_settings = []
|
||||||
self.processing = False # Flag to prevent multiple finish calls
|
self.processing = False # Flag to prevent multiple finish calls
|
||||||
|
|
@ -57,11 +57,24 @@ class PDFPreviewer:
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
self.inputs = list_pdf_files(path)
|
self.inputs = list_pdf_files(path)
|
||||||
self.output_dir = f"{path}_out"
|
|
||||||
else:
|
else:
|
||||||
self.inputs = [path]
|
# Check for existing original in backup and restore if found
|
||||||
self.output_dir = None
|
dir_name = os.path.dirname(os.path.abspath(path))
|
||||||
|
file_name = os.path.basename(path)
|
||||||
|
backup_path = os.path.join(dir_name, "Copies Originales", file_name)
|
||||||
|
|
||||||
|
if os.path.exists(backup_path):
|
||||||
|
try:
|
||||||
|
shutil.move(backup_path, path)
|
||||||
|
print(f"Restored original file from: {backup_path}")
|
||||||
|
except Exception as e:
|
||||||
|
messagebox.showerror("Error", f"Failed to restore original file: {e}")
|
||||||
|
master.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.inputs = [path]
|
||||||
|
|
||||||
|
self.output_dir = None
|
||||||
self.master = master
|
self.master = master
|
||||||
self.num = 0
|
self.num = 0
|
||||||
self.global_rotation = 0 # Rotation appliquée à tous les fichiers
|
self.global_rotation = 0 # Rotation appliquée à tous les fichiers
|
||||||
|
|
@ -273,10 +286,37 @@ class PDFPreviewer:
|
||||||
self.master.destroy()
|
self.master.destroy()
|
||||||
|
|
||||||
def finish_and_process(self):
|
def finish_and_process(self):
|
||||||
"""Starts the PDF splitting process."""
|
"""Starts the PDF splitting process and moves files."""
|
||||||
self.split_pdf()
|
self.split_pdf()
|
||||||
self.reorder_pdfs()
|
self.reorder_pdfs()
|
||||||
self.concate_files()
|
self.concate_files()
|
||||||
|
|
||||||
|
# Logic to move original to backup and replace with new file
|
||||||
|
try:
|
||||||
|
abs_path = os.path.abspath(self.pdf_path)
|
||||||
|
dir_name = os.path.dirname(abs_path)
|
||||||
|
file_name = os.path.basename(abs_path)
|
||||||
|
|
||||||
|
backup_dir = os.path.join(dir_name, "Copies Originales")
|
||||||
|
os.makedirs(backup_dir, exist_ok=True)
|
||||||
|
|
||||||
|
backup_path = os.path.join(backup_dir, file_name)
|
||||||
|
|
||||||
|
# Remove backup if it already exists (overwrite)
|
||||||
|
if os.path.exists(backup_path):
|
||||||
|
os.remove(backup_path)
|
||||||
|
|
||||||
|
# Move the original file to "Copies Originales"
|
||||||
|
shutil.move(self.pdf_path, backup_path)
|
||||||
|
|
||||||
|
# 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}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
messagebox.showerror("Error", f"Failed to move/replace files: {e}")
|
||||||
|
|
||||||
self.remove_dirs()
|
self.remove_dirs()
|
||||||
|
|
||||||
def split_filename_left(self, i):
|
def split_filename_left(self, i):
|
||||||
|
|
@ -405,3 +445,4 @@ if __name__ == "__main__":
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
app = PDFPreviewer(root, pdf_file_path)
|
app = PDFPreviewer(root, pdf_file_path)
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue