Untitled

 avatar
unknown
plain_text
5 months ago
6.8 kB
4
Indexable
def create_waste_circles(parent, dark_mode, language='EN'):
    bins = load_bin_config()
    circles = []
    
    for bin_id, bin_data in bins.items():
        container = ctk.CTkFrame(parent, fg_color='transparent')
        container.pack(side='left', padx=15)
        
        # Get translated name if available
        display_name = bin_data['name']
        if 'default_translation' in bin_data:
            display_name = bin_data['default_translation'].get(language, bin_data['name'])
        
        progress = CircularProgress(
            container,
            size=220,
            label=display_name,
            circle_color=bin_data['circle_color'],
            circle_color_dark=bin_data['circle_color_dark']
        )
        progress.pack()
        progress.set_dark_mode(dark_mode)
        progress.waste_id = bin_id
        circles.append(progress)
    
    return circles

# Update ResetFillLevelsScreen
def modify_reset_screen():
    def create_reset_circles(self):
        bins = load_bin_config()
        self.circle_widgets = []
        
        for bin_id, bin_data in bins.items():
            container = ctk.CTkFrame(self.padding_frame, fg_color=self.bg_color)
            container.pack(side='left', padx=15)
            
            # Get translated name if available
            display_name = bin_data['name']
            if 'default_translation' in bin_data:
                display_name = bin_data['default_translation'].get(self.language, bin_data['name'])
            
            progress = ResetCircleButton(
                container,
                size=220,
                label=display_name,
                circle_color=bin_data['circle_color'],
                circle_color_dark=bin_data['circle_color_dark'],
                command=lambda bid=bin_id: self._reset_fill_level(bid)
            )
            progress.pack()
            progress.set_dark_mode(self.dark_mode)
            progress.waste_id = bin_id
            
            self.circle_widgets.append(progress)
            
            # Set current fill level
            levels = load_fill_levels()
            if bin_id in levels:
                progress.set_fill_level(levels[bin_id])
    
    ResetFillLevelsScreen.create_reset_circles = create_reset_circles

# Update SettingsMenu to include bin configuration
def add_bin_configuration_to_settings():
    def create_bin_config_section(self):
        # Add bin configuration section to settings menu
        self.create_separator(self.scrollable_frame)
        self.create_section_title(
            self.scrollable_frame,
            "Bin Configuration"
        )
        
        # Add button to open bin configuration
        config_button = ctk.CTkButton(
            self.scrollable_frame,
            text="Configure Bins",
            command=self.open_bin_config,
            font=("Dongle", 16),
            fg_color='#2c2c2e' if self.dark_mode else '#e5e5e7',
            hover_color='#3a3a3c' if self.dark_mode else '#d1d1d6',
            text_color='white' if self.dark_mode else 'black'
        )
        config_button.pack(pady=(10, 0), padx=20, anchor='w')
    
    def open_bin_config(self):
        BinConfigurationScreen(
            self.winfo_toplevel(),
            self.dark_mode,
            self.winfo_toplevel().LANGUAGE
        )
    
    SettingsMenu.create_bin_config_section = create_bin_config_section
    SettingsMenu.open_bin_config = open_bin_config

# Add new BinConfigurationScreen class
class BinConfigurationScreen(ctk.CTkToplevel):
    def __init__(self, parent, dark_mode: bool, language='EN'):
        super().__init__(parent)
        
        self.dark_mode = dark_mode
        self.language = language
        
        # Make it fullscreen
        self.overrideredirect(True)
        self.geometry(f"{self.winfo_screenwidth()}x{self.winfo_screenheight()}+0+0")
        self.protocol("WM_DELETE_WINDOW", lambda: None)
        self.attributes('-topmost', True)
        
        # Set colors
        self.bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
        self.configure(fg_color=self.bg_color)
        
        self.create_widgets()
    
    def create_widgets(self):
        # Create scrollable frame for bin configurations
        self.scroll_frame = ctk.CTkScrollableFrame(
            self,
            fg_color=self.bg_color
        )
        self.scroll_frame.pack(fill='both', expand=True, padx=40, pady=40)
        
        # Load current configuration
        self.bins = load_bin_config()
        
        # Create entry fields for each bin
        for bin_id, bin_data in self.bins.items():
            frame = ctk.CTkFrame(self.scroll_frame, fg_color=self.bg_color)
            frame.pack(fill='x', pady=10)
            
            # Bin name entry
            ctk.CTkLabel(
                frame,
                text=f"Bin {bin_id[-1]} Name:",
                font=("Dongle", 16)
            ).pack(side='left', padx=5)
            
            name_var = ctk.StringVar(value=bin_data['name'])
            ctk.CTkEntry(
                frame,
                textvariable=name_var,
                width=200
            ).pack(side='left', padx=5)
            
            # Color picker buttons
            ctk.CTkButton(
                frame,
                text="Light Color",
                command=lambda bid=bin_id: self.pick_color(bid, 'circle_color')
            ).pack(side='left', padx=5)
            
            ctk.CTkButton(
                frame,
                text="Dark Color",
                command=lambda bid=bin_id: self.pick_color(bid, 'circle_color_dark')
            ).pack(side='left', padx=5)
        
        # Save and cancel buttons
        button_frame = ctk.CTkFrame(self.scroll_frame, fg_color=self.bg_color)
        button_frame.pack(fill='x', pady=20)
        
        ctk.CTkButton(
            button_frame,
            text="Save",
            command=self.save_configuration
        ).pack(side='left', padx=5)
        
        ctk.CTkButton(
            button_frame,
            text="Cancel",
            command=self.destroy
        ).pack(side='left', padx=5)
    
    def pick_color(self, bin_id, color_key):
        # Implement color picker dialog
        # For now, just use a predefined color
        self.bins[bin_id][color_key] = "#ff0000"
    
    def save_configuration(self):
        # Update bin configuration
        save_bin_config(self.bins)
        # Migrate fill levels if needed
        migrate_fill_levels()
        # Refresh main UI
        self.master.reload_ui()
        self.destroy()
Editor is loading...
Leave a Comment