Untitled
unknown
plain_text
a year ago
4.8 kB
10
Indexable
class ResetFillLevelsScreen(ctk.CTkToplevel):
def __init__(self, parent, dark_mode: bool, language='EN'):
super().__init__(parent)
# 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.language = language
self.bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
self.configure(fg_color=self.bg_color)
# Create title
title_label = ctk.CTkLabel(
self,
text=TRANSLATIONS[language].get('reset_bins', 'Reset Bins'),
font=("Dongle", 42, "bold"),
text_color='white' if dark_mode else 'black'
)
title_label.pack(pady=(20, 40))
# Create circles frame
self.circles_frame = ctk.CTkFrame(self, fg_color=self.bg_color)
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=self.bg_color)
self.padding_frame.pack(padx=50)
# Load bin configuration and fill levels
self.bin_config = load_bin_config()
self.levels = load_fill_levels()
# Create list to track circle widgets
self.circle_widgets = []
for bin_data in self.bin_config:
container = ctk.CTkFrame(self.padding_frame, fg_color=self.bg_color)
container.pack(side='left', padx=15)
# Create a darkened version of the bin config for reset screen
reset_config = {
"id": bin_data["id"],
"name": bin_data["name"],
"colors": {
"light": self._darken_color(bin_data["colors"]["light"]),
"dark": self._darken_color(bin_data["colors"]["dark"])
}
}
circle = CircularProgress(
container,
size=220,
bin_config=reset_config,
dark_mode=dark_mode
)
circle.pack()
# Set current fill level
if bin_data["id"] in self.levels:
circle.set_fill_level(self.levels[bin_data["id"]])
# Bind click event
circle.bind('<Button-1>', lambda e, bin_id=bin_data["id"]: self._reset_fill_level(bin_id))
# Store widget reference
self.circle_widgets.append(circle)
# Bind click event to the main window for closing
self.bind('<Button-1>', self.check_click_location)
# Create close button
self.close_button = ctk.CTkButton(
self,
text="×",
width=40,
height=40,
command=self.destroy,
fg_color='#ff3b30',
hover_color='#ff453a',
text_color='white',
font=("Arial", 24, "bold"),
corner_radius=20
)
self.close_button.place(relx=0.98, rely=0.02, anchor="ne")
def _darken_color(self, hex_color):
"""Darken a hex color by 20%"""
hex_color = hex_color.lstrip('#')
rgb = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
darkened = tuple(int(c * 0.8) for c in rgb)
return '#{:02x}{:02x}{:02x}'.format(*darkened)
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 click is on close button, let it handle the event
if clicked_widget == self.close_button:
return
# If we get here, the click was outside the circles and not on close button
self.destroy()
def _reset_fill_level(self, bin_id):
"""Reset fill level for the specified bin"""
print(f"Bin {bin_id} emptied")
# Update JSON file
self.levels[bin_id] = 0
save_fill_levels(self.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