Untitled
unknown
plain_text
a year ago
11 kB
15
Indexable
class BinCustomizationScreen(ctk.CTkToplevel):
def __init__(self, parent, dark_mode: bool, language='EN'):
super().__init__(parent)
self.dark_mode = dark_mode
self.language = language
self.keyboard_visible = False
self.current_entry = None
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.bg_color = '#1c1c1e' if dark_mode else '#f5f5f7'
self.text_color = 'white' if dark_mode else 'black'
self.button_color = '#2c2c2e' if dark_mode else '#e5e5e7'
self.button_hover = '#3a3a3c' if dark_mode else '#d1d1d6'
self.configure(fg_color=self.bg_color)
# Create main container
self.container = ctk.CTkFrame(self, fg_color=self.bg_color, corner_radius=0)
self.container.pack(fill='both', expand=True, padx=40, pady=20)
# Add 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")
# Create title
self.title = ctk.CTkLabel(
self.container,
text=TRANSLATIONS[language].get('bin_customization', 'Bin Customization'),
font=("Dongle", 42, "bold"),
text_color=self.text_color
)
self.title.pack(pady=(0, 20))
# Create bins container for top half
self.bins_container = ctk.CTkFrame(
self.container,
fg_color="transparent",
height=300
)
self.bins_container.pack(fill='x', pady=(0, 20))
# Create entry fields and color pickers for each bin
self.bin_frames = {}
self.name_entries = {}
self.color_buttons = {}
self.color_dark_buttons = {}
self.default_vars = {}
# Create a frame for each bin
for bin_config in self.bin_config.bins:
bin_frame = ctk.CTkFrame(
self.bins_container,
fg_color=self.button_color,
corner_radius=10
)
bin_frame.pack(side='left', expand=True, padx=10, fill='both')
# Bin title (e.g., "Bin 1", "Bin 2", etc.)
bin_title = ctk.CTkLabel(
bin_frame,
text=f"Bin {bin_config['id'][-1]}",
font=("Dongle", 24, "bold"),
text_color=self.text_color
)
bin_title.pack(pady=(10, 5))
# Name entry
name_entry = ctk.CTkEntry(
bin_frame,
placeholder_text="Bin Name",
font=("Dongle", 20),
fg_color=self.bg_color,
text_color=self.text_color,
height=35
)
name_entry.insert(0, bin_config['name'])
name_entry.pack(pady=5, padx=10, fill='x')
name_entry.bind('<Button-1>', lambda e, entry=name_entry: self.show_keyboard(entry))
self.name_entries[bin_config['id']] = name_entry
# Color buttons container
colors_frame = ctk.CTkFrame(bin_frame, fg_color="transparent")
colors_frame.pack(fill='x', padx=10, pady=5)
# Light color button
color_btn = ctk.CTkButton(
colors_frame,
text="Light Color",
command=lambda bid=bin_config['id'], mode='light': self.pick_color(bid, mode),
fg_color=bin_config['color'],
hover_color=bin_config['color'],
text_color='black',
font=("Dongle", 16),
height=30
)
color_btn.pack(side='left', expand=True, padx=(0, 5))
self.color_buttons[bin_config['id']] = color_btn
# Dark color button
color_dark_btn = ctk.CTkButton(
colors_frame,
text="Dark Color",
command=lambda bid=bin_config['id'], mode='dark': self.pick_color(bid, mode),
fg_color=bin_config['color_dark'],
hover_color=bin_config['color_dark'],
text_color='white',
font=("Dongle", 16),
height=30
)
color_dark_btn.pack(side='left', expand=True, padx=(5, 0))
self.color_dark_buttons[bin_config['id']] = color_dark_btn
# Default checkbox
default_var = ctk.BooleanVar(value=bin_config['is_default'])
default_check = ctk.CTkCheckBox(
bin_frame,
text="Use Default",
command=lambda bid=bin_config['id']: self.toggle_default(bid),
variable=default_var,
font=("Dongle", 16),
text_color=self.text_color
)
default_check.pack(pady=10)
self.default_vars[bin_config['id']] = default_var
self.bin_frames[bin_config['id']] = bin_frame
# Create keyboard container at the bottom
self.keyboard_frame = ctk.CTkFrame(
self.container,
fg_color="transparent",
height=250
)
# Create keyboard
self.keyboard = TouchKeyboard(
self.keyboard_frame,
None, # Entry widget will be set dynamically
self.hide_keyboard,
dark_mode=self.dark_mode
)
self.keyboard.pack(fill='both', expand=True)
# Save button at the bottom
self.save_button = ctk.CTkButton(
self.container,
text="Save Changes",
command=self.save_changes,
font=("Dongle", 20),
fg_color='#34c759',
hover_color='#30d158',
height=40
)
self.save_button.pack(pady=20)
# Restore defaults button
self.restore_button = ctk.CTkButton(
self.container,
text="Restore All Defaults",
command=self.restore_defaults,
font=("Dongle", 20),
fg_color='#ff3b30',
hover_color='#ff453a',
height=40
)
self.restore_button.pack(pady=(0, 20))
# Bind click outside entry to hide keyboard
self.bind('<Button-1>', self.check_hide_keyboard)
def show_keyboard(self, entry):
self.current_entry = entry
self.keyboard.entry = entry
if not self.keyboard_visible:
self.keyboard_frame.pack(side="bottom", pady=(0, 0))
self.keyboard_frame.pack_configure(expand=False, anchor="s", padx=(self.winfo_width() // 2 - 500, 0))
self.keyboard_visible = True
entry.focus_set()
def hide_keyboard(self, event=None):
if self.keyboard_visible:
self.keyboard_frame.pack_forget()
self.keyboard_visible = False
def check_hide_keyboard(self, event):
widget = event.widget
if self.keyboard_visible:
if (widget not in self.name_entries.values() and
not self.keyboard_frame.winfo_containing(event.x_root, event.y_root)):
self.hide_keyboard()
def pick_color(self, bin_id, mode):
# Here you would typically open a color picker
# For this example, we'll just cycle through some preset colors
preset_colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff']
current_color = self.color_buttons[bin_id].cget('fg_color') if mode == 'light' else self.color_dark_buttons[bin_id].cget('fg_color')
try:
next_index = (preset_colors.index(current_color) + 1) % len(preset_colors)
except ValueError:
next_index = 0
if mode == 'light':
self.color_buttons[bin_id].configure(
fg_color=preset_colors[next_index],
hover_color=preset_colors[next_index]
)
else:
self.color_dark_buttons[bin_id].configure(
fg_color=preset_colors[next_index],
hover_color=preset_colors[next_index]
)
def toggle_default(self, bin_id):
is_default = self.default_vars[bin_id].get()
if is_default:
# If setting to default, load default values
default_bin = next((b for b in self.bin_config.DEFAULT_BINS if b['id'] == bin_id), None)
if default_bin:
self.name_entries[bin_id].delete(0, 'end')
self.name_entries[bin_id].insert(0, default_bin['name'])
self.color_buttons[bin_id].configure(
fg_color=default_bin['color'],
hover_color=default_bin['color']
)
self.color_dark_buttons[bin_id].configure(
fg_color=default_bin['color_dark'],
hover_color=default_bin['color_dark']
)
def save_changes(self):
new_config = []
for bin_id in self.bin_frames.keys():
is_default = self.default_vars[bin_id].get()
if is_default:
# Use default values
default_bin = next(b for b in self.bin_config.DEFAULT_BINS if b['id'] == bin_id)
new_config.append(default_bin.copy())
else:
# Use custom values
new_config.append({
'id': bin_id,
'name': self.name_entries[bin_id].get(),
'color': self.color_buttons[bin_id].cget('fg_color'),
'color_dark': self.color_dark_buttons[bin_id].cget('fg_color'),
'is_default': False
})
# Save to configuration file
self.bin_config.save_configuration(new_config)
# Reload main UI
self.winfo_toplevel().reload_ui()
self.destroy()
def restore_defaults(self):
# Reset all bins to default configuration
self.bin_config.restore_defaults()
# Reload main UI
self.winfo_toplevel().reload_ui()
self.destroy()Editor is loading...
Leave a Comment