Untitled

 avatar
unknown
plain_text
5 months ago
6.0 kB
3
Indexable
class SettingsMenu(ctk.CTkFrame):
    def __init__(self, parent, dark_mode):
        # Customizable dimensions - adjust these values as needed
        self.menu_width = 300  # Adjust this to your preferred width
        self.menu_height = 600  # Matches your screen height
        
        # Pass height and width to constructor
        super().__init__(
            parent,
            fg_color='#1c1c1e' if dark_mode else '#f5f5f7',
            width=self.menu_width,
            height=self.menu_height
        )
        
        self.parent = parent
        self.dark_mode = dark_mode
        self.is_open = False
        self.animation_running = False
        self.current_width = 0
        self.target_width = self.menu_width

        # Add border color based on dark mode
        self.border_color = '#2c2c2e' if dark_mode else '#e5e5e7'
        self.configure(border_width=2, border_color=self.border_color)
        
        # Place the frame initially off-screen (removed height parameter)
        self.place(relx=1, rely=0, x=self.menu_width, y=0, anchor='ne')
        
        # Create main container for content with scrolling if needed
        self.main_container = ctk.CTkFrame(
            self,
            fg_color='transparent',
            width=self.menu_width,
            height=self.menu_height
        )
        self.main_container.pack(fill='both', expand=True)
        
        # Create settings content
        self.create_menu_content()
        
        # Create settings button
        try:
            is_light_bg = not dark_mode
            icon_suffix = "-b" if is_light_bg else "-w"
            
            icon_image = ctk.CTkImage(
                light_image=Image.open(f"icons/settings{icon_suffix}.png"),
                dark_image=Image.open(f"icons/settings{icon_suffix}.png"),
                size=(30, 30)
            )
            self.settings_button = ctk.CTkButton(
                self.parent,
                image=icon_image,
                text="",
                width=30,
                height=30,
                fg_color="transparent",
                hover_color='#2c2c2e' if dark_mode else '#e5e5e7',
                command=self.toggle_menu
            )
            self.settings_button.place(relx=0.97, rely=0.05, anchor='center')
            
        except Exception as e:
            print(f"Error loading settings icon: {e}")
            self.settings_button = ctk.CTkButton(
                self.parent,
                text="⚙",
                width=30,
                height=30,
                fg_color="transparent",
                hover_color='#2c2c2e' if dark_mode else '#e5e5e7',
                command=self.toggle_menu
            )
            self.settings_button.place(relx=0.97, rely=0.04, anchor='center')
            
        # Bind click event to parent window
        self.parent.bind("<Button-1>", self.check_click_location)

    def create_separator(self, parent):
        """Create a visual separator line"""
        separator = ctk.CTkFrame(
            parent,
            height=2,
            fg_color=self.border_color
        )
        separator.pack(fill='x', padx=20, pady=20)

    def create_section_title(self, parent, text):
        """Create a section title with consistent styling"""
        title = ctk.CTkLabel(
            parent,
            text=text,
            font=("Dongle", 20),
            text_color='white' if self.dark_mode else 'black'
        )
        title.pack(padx=20, anchor='w')

    def create_menu_content(self):
        root = self.winfo_toplevel()
        current_language = root.LANGUAGE
        
        # Title
        title = ctk.CTkLabel(
            self.main_container,
            text=TRANSLATIONS[current_language]['settings'],
            font=("Dongle", 24, "bold"),
            text_color='white' if self.dark_mode else 'black'
        )
        title.pack(pady=(20, 20), padx=20, anchor='w')
        
        self.create_separator(self.main_container)
        
        # Appearance section
        self.create_section_title(
            self.main_container,
            TRANSLATIONS[current_language]['appearance']
        )
        
        # Dark mode switch
        self.dark_mode_switch = ctk.CTkSwitch(
            self.main_container,
            text=TRANSLATIONS[current_language]['dark_mode'],
            command=self.toggle_dark_mode,
            font=("Dongle", 16),
            fg_color='#34c759',
            progress_color='#34c759'
        )
        self.dark_mode_switch.pack(pady=(10, 0), padx=20, anchor='w')
        self.dark_mode_switch.select() if self.dark_mode else self.dark_mode_switch.deselect()
        
        self.create_separator(self.main_container)
        
        # Language section
        self.create_section_title(
            self.main_container,
            TRANSLATIONS[current_language]['language']
        )
        
        # Language selection
        self.language_var = ctk.StringVar(value=current_language)
        
        self.language_menu = ctk.CTkOptionMenu(
            self.main_container,
            values=['EN', 'DE'],
            command=self.change_language,
            variable=self.language_var,
            font=("Dongle", 16),
            fg_color='#2c2c2e' if self.dark_mode else '#e5e5e7',
            button_color='#3a3a3c' if self.dark_mode else '#d1d1d6',
            button_hover_color='#3a3a3c' if self.dark_mode else '#d1d1d6',
        )
        self.language_menu.pack(pady=(10, 0), padx=20, anchor='w')
        
        # Add a final separator for visual balance
        self.create_separator(self.main_container)
        
        # Add an empty frame at the bottom to push everything up
        spacer = ctk.CTkFrame(self.main_container, fg_color="transparent")
        spacer.pack(fill='both', expand=True)
Editor is loading...
Leave a Comment