ShortGenerator/Main.py
klop51 ae5a287aeb Add processing preview with progress tracking to the main application
- Implemented a new feature to show a processing preview for clips.
- Added a progress bar, elapsed time, and remaining time indicators.
- Utilized threading to keep the main application responsive during processing.
- Included buttons for previewing clips, opening videos, and exiting the application.
2025-08-09 21:45:39 +02:00

53 lines
2.1 KiB
Python

import tkinter as tk
from tkinter import ttk, filedialog
import threading
import time
# Example function that simulates clip processing with time tracking
def process_clips(progress_var, progress_bar, status_label, time_label, total_steps=10):
start_time = time.time()
for i in range(total_steps):
time.sleep(0.5) # Simulate processing time
elapsed = time.time() - start_time
remaining = (elapsed / (i+1)) * (total_steps - (i+1))
progress_var.set((i+1) * 100 / total_steps)
status_label.config(text=f"Processing... {i+1}/{total_steps}")
time_label.config(text=f"Elapsed: {elapsed:.1f}s | Remaining: {remaining:.1f}s")
status_label.config(text="Done!")
time_label.config(text=f"Total Time: {time.time() - start_time:.1f}s")
def start_preview_with_progress():
progress_window = tk.Toplevel(root)
progress_window.title("Processing Preview")
progress_window.geometry("320x130")
progress_window.resizable(False, False)
status_label = tk.Label(progress_window, text="Initializing...", anchor="w")
status_label.pack(fill="x", padx=10, pady=(10,0))
time_label = tk.Label(progress_window, text="Elapsed: 0.0s | Remaining: --s", anchor="w")
time_label.pack(fill="x", padx=10)
progress_var = tk.DoubleVar()
progress_bar = ttk.Progressbar(progress_window, variable=progress_var, maximum=100)
progress_bar.pack(fill="x", padx=10, pady=10)
threading.Thread(target=process_clips, args=(progress_var, progress_bar, status_label, time_label), daemon=True).start()
# Main Tkinter app remains responsive with all buttons available
root = tk.Tk()
root.title("Shorts Generator 2")
root.geometry("400x200")
preview_button = tk.Button(root, text="Preview Clips", command=start_preview_with_progress)
preview_button.pack(pady=10)
# Example of other functional buttons remaining available
open_button = tk.Button(root, text="Open Video", command=lambda: filedialog.askopenfilename())
open_button.pack(pady=10)
exit_button = tk.Button(root, text="Exit", command=root.quit)
exit_button.pack(pady=10)
root.mainloop()