Untitled
unknown
plain_text
a year ago
5.0 kB
5
Indexable
class SettingsButton(ctk.CTkButton):
def __init__(self, parent, dark_mode=False, command=None):
super().__init__(
parent,
text="",
width=40,
height=40,
fg_color="transparent",
hover_color="#2c2c2e" if dark_mode else "#e5e5e7",
command=command
)
self.dark_mode = dark_mode
self.load_icon()
def load_icon(self):
try:
icon_suffix = "-w" if self.dark_mode else "-b"
icon_image = ctk.CTkImage(
light_image=Image.open(f"icons/settings{icon_suffix}.png"),
dark_image=Image.open(f"icons/settings{icon_suffix}.png"),
size=(24, 24)
)
self.configure(image=icon_image)
except Exception as e:
print(f"Error loading settings icon: {e}")
self.configure(text="⚙️")
def set_dark_mode(self, is_dark):
self.dark_mode = is_dark
self.load_icon()
self.configure(hover_color="#2c2c2e" if is_dark else "#e5e5e7")
class SettingsOverlay(ctk.CTkFrame):
def __init__(self, parent, dark_mode=False, language='EN'):
super().__init__(parent)
self.parent = parent
self.dark_mode = dark_mode
self.language = language
# Configure the frame
self.configure(
fg_color='#1c1c1e' if dark_mode else '#f5f5f7',
corner_radius=0
)
# Initialize with position outside the screen
self.place(relx=1.0, rely=0, relwidth=0.8, relheight=1.0)
self.setup_ui()
self.animate_in()
def setup_ui(self):
# Title
self.title = ctk.CTkLabel(
self,
text=TRANSLATIONS[self.language]['settings'],
font=('Dongle', 32, 'bold'),
text_color='white' if self.dark_mode else 'black'
)
self.title.place(relx=0.05, rely=0.05)
# Settings sections
self.create_settings_section()
def create_settings_section(self):
# Appearance section
y_pos = 0.15
spacing = 0.08
# Language switcher
self.create_setting_label(TRANSLATIONS[self.language]['language'], y_pos)
self.language_switch = ctk.CTkSegmentedButton(
self,
values=['EN', 'DE'],
command=self.on_language_change,
selected_color='#007AFF',
unselected_color='#3a3a3c' if self.dark_mode else '#e5e5e7',
selected_hover_color='#0051FF'
)
self.language_switch.place(relx=0.05, rely=y_pos + 0.04, relwidth=0.3)
self.language_switch.set(self.language)
# Dark mode toggle
y_pos += spacing
self.create_setting_label(TRANSLATIONS[self.language]['dark_mode'], y_pos)
self.dark_mode_switch = ctk.CTkSwitch(
self,
text="",
command=self.on_dark_mode_change,
button_color='#007AFF',
button_hover_color='#0051FF',
progress_color='#34c759' if not self.dark_mode else '#30d158'
)
self.dark_mode_switch.place(relx=0.05, rely=y_pos + 0.04)
self.dark_mode_switch.select() if self.dark_mode else self.dark_mode_switch.deselect()
def create_setting_label(self, text, y_pos):
label = ctk.CTkLabel(
self,
text=text,
font=('Dongle', 20),
text_color='white' if self.dark_mode else 'black'
)
label.place(relx=0.05, rely=y_pos)
def on_language_change(self, value):
self.language = value
self.parent.LANGUAGE = value
# Trigger UI update
self.parent.update_language(value)
def on_dark_mode_change(self):
is_dark = self.dark_mode_switch.get()
self.parent.update_dark_mode(is_dark)
def animate_in(self):
self.animate(1.0, 0.2)
def animate_out(self):
self.animate(1.0, 1.0, True)
def animate(self, start_x, end_x, closing=False):
duration = 300 # Animation duration in milliseconds
steps = 30 # Number of animation steps
step_time = duration / steps
distance = end_x - start_x
step_distance = distance / steps
def animation_step(step):
if step < steps:
current_x = start_x + (step_distance * step)
self.place(relx=current_x, rely=0, relwidth=0.8, relheight=1.0)
self.after(int(step_time), lambda: animation_step(step + 1))
elif closing:
self.destroy()
animation_step(0)
def close(self):
self.animate_out()Editor is loading...
Leave a Comment