Untitled
unknown
plain_text
a year ago
5.0 kB
6
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 based on dark mode
self.dark_mode = dark_mode
self.bg_color = '#0c0c0e' if dark_mode else '#e5e5e7' # Darker background
self.configure(fg_color=self.bg_color)
# Create semi-transparent overlay
self.overlay = ctk.CTkFrame(
self,
fg_color=('black', 'white'),
corner_radius=0
)
self.overlay.place(relx=0, rely=0, relwidth=1, relheight=1)
self.overlay.configure(fg_color=self.apply_alpha('#000000', 0.3))
# Create circles frame
self.circles_frame = ctk.CTkFrame(self, fg_color='transparent')
self.circles_frame.place(relx=0.5, rely=0.5, anchor='center')
# Add padding frame
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)
# Create a darkened version of the circle
darkened_config = self.create_darkened_config(bin_config)
progress = ResetCircleButton(
container,
bin_id=bin_config['id'],
size=220,
language=language,
command=lambda bid=bin_config['id']: self._reset_fill_level(bid)
)
# Override the bin_config with our darkened version
progress.bin_config = darkened_config
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 hex_to_rgb(self, hex_color):
"""Convert hex color to RGB tuple"""
hex_color = hex_color.lstrip('#')
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
def rgb_to_hex(self, rgb):
"""Convert RGB tuple to hex color"""
return '#{:02x}{:02x}{:02x}'.format(*rgb)
def darken_color(self, hex_color, factor=0.7):
"""Darken a hex color by multiplying RGB values by factor"""
rgb = self.hex_to_rgb(hex_color)
darkened = tuple(int(c * factor) for c in rgb)
return self.rgb_to_hex(darkened)
def apply_alpha(self, hex_color, alpha):
"""Apply alpha transparency to a hex color"""
rgb = self.hex_to_rgb(hex_color)
return f'#{rgb[0]:02x}{rgb[1]:02x}{rgb[2]:02x}{int(alpha * 255):02x}'
def create_darkened_config(self, original_config):
"""Create a new config with darkened colors"""
darkened_config = original_config.copy()
darkened_config['color'] = self.darken_color(original_config['color'], 0.7)
darkened_config['color_dark'] = self.darken_color(original_config['color_dark'], 0.7)
return darkened_config
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