#!/usr/bin/env python3 """Interactive demonstration of menu theming functionality.""" import logging import os import sys import tkinter as tk # Add the src directory to the path so we can import the modules sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../src")) from theme_manager import ThemeManager def demo_menu_theming(): """Interactive demonstration of menu theming with different themes.""" # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) print("Menu Theming Interactive Demo") print("=============================") # Create root window root = tk.Tk() root.title("Menu Theming Demo - TheChart") root.geometry("500x400") # Initialize theme manager theme_manager = ThemeManager(root, logger) # Create demo menubar using the new convenience method menubar = theme_manager.create_themed_menu(root) root.config(menu=menubar) # Create submenus file_menu = theme_manager.create_themed_menu(menubar, tearoff=0) theme_menu = theme_manager.create_themed_menu(menubar, tearoff=0) help_menu = theme_manager.create_themed_menu(menubar, tearoff=0) menubar.add_cascade(label="File", menu=file_menu) menubar.add_cascade(label="Theme", menu=theme_menu) menubar.add_cascade(label="Help", menu=help_menu) # Populate file menu file_menu.add_command(label="Demo Item 1") file_menu.add_command(label="Demo Item 2") file_menu.add_separator() file_menu.add_command(label="Exit Demo", command=root.quit) # Populate help menu help_menu.add_command( label="About Demo", command=lambda: tk.messagebox.showinfo( "About", "Interactive menu theming demonstration for TheChart" ), ) # Theme information display theme_info_frame = tk.Frame(root, relief="ridge", bd=2) theme_info_frame.pack(fill="x", padx=20, pady=10) current_theme_label = tk.Label( theme_info_frame, text=f"Current Theme: {theme_manager.get_current_theme().title()}", font=("Arial", 12, "bold"), ) current_theme_label.pack(pady=5) colors_display = tk.Text(theme_info_frame, height=6, wrap="word") colors_display.pack(fill="x", padx=10, pady=5) def update_theme_display(): """Update the theme information display.""" current_theme_label.config( text=f"Current Theme: {theme_manager.get_current_theme().title()}" ) menu_colors = theme_manager.get_menu_colors() colors_text = "Current Menu Colors:\n" for key, value in menu_colors.items(): colors_text += f" {key}: {value}\n" colors_display.delete(1.0, tk.END) colors_display.insert(1.0, colors_text) # Function to apply theme and update displays def apply_theme_and_update(theme_name): """Apply theme and update all displays.""" print(f"Switching to theme: {theme_name}") if theme_manager.apply_theme(theme_name): # Re-theme all menus theme_manager.configure_menu(menubar) theme_manager.configure_menu(file_menu) theme_manager.configure_menu(theme_menu) theme_manager.configure_menu(help_menu) # Update display update_theme_display() print(f" ✓ Successfully applied {theme_name} theme") else: print(f" ✗ Failed to apply {theme_name} theme") # Create theme selection menu available_themes = theme_manager.get_available_themes() current_theme = theme_manager.get_current_theme() for theme in available_themes: theme_menu.add_radiobutton( label=theme.title(), command=lambda t=theme: apply_theme_and_update(t), value=theme == current_theme, ) # Instructions instructions_frame = tk.Frame(root) instructions_frame.pack(fill="both", expand=True, padx=20, pady=10) tk.Label( instructions_frame, text="Menu Theming Demonstration", font=("Arial", 16, "bold"), ).pack(pady=10) instructions_text = """ Instructions: 1. Use the Theme menu to switch between different themes 2. Observe how menu colors change to match each theme 3. Try the File and Help menus to see the color effects 4. Menu backgrounds, text, and hover effects all update automatically Available themes: """ + ", ".join([t.title() for t in available_themes]) tk.Label( instructions_frame, text=instructions_text, justify="left", wraplength=450, ).pack(pady=10) # Initialize display update_theme_display() print(f"Demo window opened with {len(available_themes)} available themes.") print("Try the Theme menu to see different color schemes!") # Show the window root.mainloop() if __name__ == "__main__": demo_menu_theming()