diff --git a/gui.py b/gui.py index 85ea833..4cc9adb 100644 --- a/gui.py +++ b/gui.py @@ -58,6 +58,10 @@ class FMFaceGeneratorGUI: self.image_queue = queue.Queue() self.current_profile = None + # Preview tracking variables + self.generated_images = [] # List of generated image UIDs + self.current_image_index = -1 # Current image being displayed + # Set up the GUI self.setup_gui() @@ -617,6 +621,9 @@ class FMFaceGeneratorGUI: ttk.Button(nav_frame, text="Next", command=self.show_next_image).pack(side=tk.LEFT, padx=5) ttk.Button(nav_frame, text="Refresh", command=self.refresh_preview).pack(side=tk.RIGHT, padx=5) + # Scan for existing images on startup + self.root.after(1000, self.scan_existing_images) # Delay to allow config to load + def browse_model_dir(self): """Browse for model directory""" directory = filedialog.askdirectory(title="Select Model Directory") @@ -713,6 +720,9 @@ class FMFaceGeneratorGUI: self.rtf_file_var.set('') self.output_dir_var.set('./NewGens/') self.log_message("No profile selected, using defaults") + + # Scan for existing images after loading config + self.root.after(500, self.scan_existing_images) else: self.log_message("No configuration file found, using defaults") @@ -919,6 +929,15 @@ class FMFaceGeneratorGUI: try: image_path = f"{self.output_dir_var.get()}/{uid}.png" if os.path.exists(image_path): + # Add to generated images list if not already present + if uid not in self.generated_images: + self.generated_images.append(uid) + self.update_total_count() + + # Find the index of current image + if uid in self.generated_images: + self.current_image_index = self.generated_images.index(uid) + # Load and resize image image = Image.open(image_path) image.thumbnail((300, 300), Image.Resampling.LANCZOS) @@ -937,16 +956,73 @@ class FMFaceGeneratorGUI: def show_previous_image(self): """Show previous image""" - self.log_message("Previous image functionality not implemented yet") + if not self.generated_images: + self.log_message("No images available to navigate") + return + + if self.current_image_index <= 0: + self.log_message("Already at first image") + return + + self.current_image_index -= 1 + uid = self.generated_images[self.current_image_index] + self.show_image(uid) def show_next_image(self): """Show next image""" - self.log_message("Next image functionality not implemented yet") + if not self.generated_images: + self.log_message("No images available to navigate") + return + + if self.current_image_index >= len(self.generated_images) - 1: + self.log_message("Already at last image") + return + + self.current_image_index += 1 + uid = self.generated_images[self.current_image_index] + self.show_image(uid) + + def update_total_count(self): + """Update the total generated count display""" + count = len(self.generated_images) + self.total_generated_var.set(str(count)) + self.log_message(f"Total generated images: {count}") + + def scan_existing_images(self): + """Scan the output directory for existing images""" + try: + output_dir = self.output_dir_var.get() + if not output_dir or not os.path.exists(output_dir): + return + + # Find all PNG files in the output directory + existing_images = [] + for file in os.listdir(output_dir): + if file.endswith('.png') and file[:-4].isdigit(): + uid = file[:-4] # Remove .png extension + existing_images.append(uid) + + # Sort by UID (numerically) + existing_images.sort(key=int) + + # Update our tracking list + self.generated_images = existing_images + self.update_total_count() + + if existing_images: + self.log_message(f"Found {len(existing_images)} existing images") + else: + self.log_message("No existing images found") + + except Exception as e: + self.log_message(f"Error scanning existing images: {str(e)}") def refresh_preview(self): """Refresh the preview""" self.log_message("Refreshing preview...") - # This would scan the output directory and show available images + self.scan_existing_images() + if self.generated_images: + self.show_image(self.generated_images[0]) # Show first image def main(): """Main function"""