Untitled

 avatar
unknown
plain_text
5 months ago
3.8 kB
3
Indexable
class WasteAlertScreen(ctk.CTkToplevel):
    def __init__(self, parent, waste_type: str, color: str, dark_mode: bool, progress_circle=None, language='EN'):
        super().__init__(parent)
        
        self.waste_type = waste_type
        self.language = language
        self.progress_circle = progress_circle
        
        # Make it fullscreen and disable all close operations
        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 background color based on dark mode
        bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
        self.configure(fg_color=bg_color)
        
        # Create main container with padding
        self.container = ctk.CTkFrame(
            self,
            fg_color=bg_color,
            corner_radius=0
        )
        self.container.pack(fill='both', expand=True, padx=40, pady=40)
        
        # Create colored alert box
        self.alert_box = ctk.CTkFrame(
            self.container,
            fg_color=color,
            corner_radius=20
        )
        self.alert_box.pack(fill='both', expand=True)
        
        # Determine text color based on waste type and dark mode
        text_color = '#000000' if waste_type in ["Gelber Sack", "Recycling"] and dark_mode else ('#ffffff' if dark_mode else '#000000')
        
        # Get the translated waste type name
        translated_waste_type = waste_type
        # Reverse lookup the original German key for the waste type
        for de_key, en_value in TRANSLATIONS['EN'].items():
            if en_value == waste_type and de_key in TRANSLATIONS['DE']:
                translated_waste_type = TRANSLATIONS[language][de_key]
                break
        
        # Add the message label with correct translation
        message_text = TRANSLATIONS[language]['bin_full_message'].format(waste_type=translated_waste_type)
        self.message_label = ctk.CTkLabel(
            self.alert_box,
            text=message_text,
            font=('Dongle', 32),
            text_color=text_color
        )
        self.message_label.place(relx=0.5, rely=0.35, anchor='center')
        
        try:
            # Determine which icon to use based on background color brightness
            # For yellow/light backgrounds use black icon, for dark backgrounds use white icon
            is_light_bg = waste_type in ["Gelber Sack", "Recycling"] or not dark_mode
            icon_suffix = "-b" if is_light_bg else "-w"
            
            icon_image = ctk.CTkImage(
                light_image=Image.open(f"icons/circle-alert{icon_suffix}.png"),
                dark_image=Image.open(f"icons/circle-alert{icon_suffix}.png"),
                size=(72, 72)
            )
            
            self.icon_button = ctk.CTkButton(
                self.alert_box,
                image=icon_image,
                text="",
                width=60,
                height=60,
                fg_color="transparent",
                hover_color=color,
                command=self.handle_empty_bin
            )
            self.icon_button.place(relx=0.5, rely=0.65, anchor='center')
            
        except Exception as e:
            print(f"Error loading icon: {e}")
            self.icon_button = ctk.CTkButton(
                self.alert_box,
                text="?",
                width=60,
                height=60,
                fg_color="transparent",
                hover_color=color,
                command=self.handle_empty_bin
            )
            self.icon_button.place(relx=0.5, rely=0.65, anchor='center')
Editor is loading...
Leave a Comment