blackjack-theory-game/gui/components/notifications.py
2026-06-09 20:07:08 +02:00

64 lines
2.2 KiB
Python
Executable File

import customtkinter as ctk
class NotificationSystem:
def __init__(self, parent):
self.parent = parent
self.streak_label = None
self.streak_notification = None
self.attached_windows = []
self._create_streak_label() # Create label immediately
def _update_streak_display(self, current_streak):
"""Original streak display logic"""
if current_streak >= 3:
if not self.streak_label:
self._create_streak_label()
self.streak_label.configure(text=f"🔥 {current_streak}")
self.streak_label.lift()
elif self.streak_label:
self.streak_label.configure(text="")
def _create_streak_label(self):
"""Original streak label creation"""
self.streak_label = ctk.CTkLabel(
self.parent,
text="",
font=("Arial", 16, "bold"),
text_color="#FFD700", # Gold
bg_color="transparent"
)
self.streak_label.place(relx=0.95, rely=0.02, anchor="ne")
def _show_streak_notification(self, message):
"""Original notification popup"""
notif = ctk.CTkToplevel(self.parent)
notif.overrideredirect(True)
# Keep original styling
label = ctk.CTkLabel(
notif,
text=message,
font=("Arial", 14, "bold"),
fg_color="#3a7ebf",
text_color="white",
corner_radius=8,
padx=20,
pady=10
)
label.pack()
# Original positioning logic
main_width = self.parent.winfo_width()
main_height = self.parent.winfo_height()
notif.update_idletasks()
notif_width = notif.winfo_width()
notif_height = notif.winfo_height()
x_offset = main_width - notif_width - 20
y_offset = 40
x_offset = max(10, min(x_offset, main_width - notif_width - 10))
y_offset = max(10, min(y_offset, main_height - notif_height - 10))
notif.geometry(f"+{self.parent.winfo_x() + x_offset}+{self.parent.winfo_y() + y_offset}")
self.parent.after(1500, notif.destroy)