Untitled

 avatar
unknown
plain_text
5 months ago
3.6 kB
4
Indexable
class ResetFillLevelsScreen(ctk.CTkToplevel):
    def __init__(self, parent, dark_mode: bool, language='EN'):
        super().__init__(parent)
        
        self.bin_config = BinConfiguration()
        
        # 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 colors to match main screen exactly
        self.dark_mode = dark_mode
        self.bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'  # Same as main screen
        self.configure(fg_color=self.bg_color)
        
        # Create title label to indicate reset mode
        self.title_label = ctk.CTkLabel(
            self,
            text="? Tap circles to reset fill levels",
            font=("Dongle", 32),
            text_color='white' if dark_mode else 'black'
        )
        self.title_label.place(relx=0.5, rely=0.2, anchor='center')
        
        # Create circles frame with transparent background
        self.circles_frame = ctk.CTkFrame(self, fg_color="transparent")
        self.circles_frame.place(relx=0.5, rely=0.5, anchor='center')
        
        # Add padding frame with transparent background
        self.padding_frame = ctk.CTkFrame(self.circles_frame, fg_color="transparent")
        self.padding_frame.pack(padx=50)
        
        # Create list to track circle widgets
        self.circle_widgets = []

        # Create Reset Circles for each bin
        for bin_config in self.bin_config.bins:
            container = ctk.CTkFrame(self.padding_frame, fg_color="transparent")
            container.pack(side='left', padx=15)
            
            progress = ResetCircleButton(
                container,
                bin_id=bin_config['id'],
                size=220,
                language=language,
                dark_mode=dark_mode,
                command=lambda bid=bin_config['id']: self._reset_fill_level(bid)
            )
            
            progress.pack()
            progress.set_dark_mode(dark_mode)
            
            # Store circle widgets
            self.circle_widgets.append(progress)
            
            # Load and set current fill level
            levels = load_fill_levels()
            if bin_config['id'] in levels:
                progress.set_fill_level(levels[bin_config['id']])

        # Bind click event to the main window
        self.bind('<Button-1>', self.check_click_location)

    def check_click_location(self, event):
        """Check if click is outside the circles"""
        clicked_widget = event.widget.winfo_containing(event.x_root, event.y_root)
        
        # Check if clicked widget is one of our circles or their containers
        for circle in self.circle_widgets:
            if clicked_widget is circle or clicked_widget in circle.winfo_children():
                return
                
        # If we get here, the click was outside the circles
        self.destroy()

    def _reset_fill_level(self, bin_id):
        """Reset fill level for the specified bin"""
        print(f"{bin_id} emptied")
        
        # Update JSON file
        levels = load_fill_levels()
        levels[bin_id] = 0
        save_fill_levels(levels)
        
        # Update main window circles
        CircularProgress.update_all_instances()
        
        # Close the reset screen after a short delay
        self.after(200, self.destroy)
Editor is loading...
Leave a Comment