# --- FILE: gitsync_tool/gui/tabs/automation_tab.py --- import tkinter as tk from tkinter import ttk from typing import Callable from gitutility.gui.tooltip import Tooltip class AutomationTab(ttk.Frame): """ The 'Automation' tab in the main application notebook. This tab provides buttons for automated, multi-step tasks like updating a Gitea Wiki or analyzing and cleaning repository history. """ def __init__(self, master: tk.Misc, **kwargs): """ Initializes the Automation tab. Args: master: The parent widget (the ttk.Notebook). **kwargs: Dictionary of callbacks from the main controller. """ super().__init__(master, padding=(10, 10)) # Store callbacks self.update_gitea_wiki_callback = kwargs.get('update_gitea_wiki_cb') self.analyze_and_clean_history_callback = kwargs.get('analyze_and_clean_history_cb') # Get a reference to the main frame to access shared variables (like remote_url_var) self.main_frame = self.master.master # Configure layout self.columnconfigure(0, weight=1) # Create widgets self._create_widgets() def _create_widgets(self) -> None: """Creates and arranges all widgets for this tab.""" # --- Wiki Synchronization Section --- wiki_frame = ttk.LabelFrame( self, text="Gitea Wiki Synchronization", padding=(10, 5) ) wiki_frame.grid(row=0, column=0, sticky="ew", pady=(0, 10)) ttk.Label( wiki_frame, text="Update Gitea Wiki pages using local files from the 'doc/' directory.", wraplength=450, justify=tk.LEFT ).pack(pady=(0, 10), fill="x", expand=True) self.update_wiki_button = ttk.Button( wiki_frame, text="Update Gitea Wiki Now", command=self.update_gitea_wiki_callback, state=tk.DISABLED ) self.update_wiki_button.pack(pady=5) Tooltip( self.update_wiki_button, "Clones the associated Gitea Wiki repo, copies 'doc/Manual*.md' files,\n" "commits the changes, and pushes them to the remote wiki." ) # --- History Cleaning Section --- history_frame = ttk.LabelFrame( self, text="Repository History Maintenance", padding=(10, 5) ) history_frame.grid(row=1, column=0, sticky="ew") ttk.Label( history_frame, text="Analyze repository for committed files that should be ignored and offer to purge them from history.", wraplength=450, justify=tk.LEFT ).pack(pady=(0, 10), fill="x", expand=True) self.analyze_history_button = ttk.Button( history_frame, text="Analyze & Clean History...", command=self.analyze_and_clean_history_callback, state=tk.DISABLED ) self.analyze_history_button.pack(pady=5) Tooltip( self.analyze_history_button, "DESTRUCTIVE: Analyze history for files to remove.\n" "This action can rewrite the entire repository history." ) def set_action_widgets_state(self, state: str) -> None: """ Sets the state of all action widgets in this tab. This tab has special logic: buttons are only enabled if a remote URL is present. """ # Determine the base state (NORMAL or DISABLED) base_state = state # Check for remote URL presence by accessing the remote_tab's variable remote_url_present = False if hasattr(self.main_frame, 'remote_tab'): remote_url_present = bool(self.main_frame.remote_tab.remote_url_var.get().strip()) # The final state is NORMAL only if the base state is NORMAL AND a remote URL is configured final_state = tk.NORMAL if base_state == tk.NORMAL and remote_url_present else tk.DISABLED widgets = [ self.update_wiki_button, self.analyze_history_button, ] for widget in widgets: if widget and widget.winfo_exists(): widget.config(state=final_state)