diff --git a/.gitignore b/.gitignore index 903ecf7..2b49492 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ venv/ # Python-Cache __pycache__/ *.py[cod] + +*.un~ diff --git a/games/blackjack/views/__pycache__/blackjack_table_view.cpython-311.pyc b/games/blackjack/views/__pycache__/blackjack_table_view.cpython-311.pyc index 58f0378..73aa48b 100644 Binary files a/games/blackjack/views/__pycache__/blackjack_table_view.cpython-311.pyc and b/games/blackjack/views/__pycache__/blackjack_table_view.cpython-311.pyc differ diff --git a/games/blackjack/views/blackjack_table_view.py b/games/blackjack/views/blackjack_table_view.py index 06f48c9..2361d17 100644 --- a/games/blackjack/views/blackjack_table_view.py +++ b/games/blackjack/views/blackjack_table_view.py @@ -19,7 +19,7 @@ from models.progression import Progression from resources.code_res.game_constants import ( ACCENT_GOLD, ACCENT_GOTH, BJ_BOT_CARD_SIZE, BJ_BOT_TURN_DELAY_MS, BJ_DEALER_DELAY_MS, BJ_INITIAL_ANTE, BJ_SPLIT_CARD_SIZE, - BJ_STARTING_GOLD, BJ_VARIANTS, BORDER_COLOR, ERROR_FG, + BJ_STARTING_GOLD, BJ_VARIANTS, BORDER_COLOR, CELL_BG, ERROR_FG, FG_COLOR, GOLD_MIN_TABLE_ENTRY, MUTED_FG, PANEL_BG, PK_TABLE_IMAGE, PLAYING_CARD_SIZE, SUBTLE_BORDER, TABLE_BG, XP_TO_GOLD_AMOUNT ) @@ -29,11 +29,13 @@ from view.widgets.image_button import ImageButton GAME_FOLDER_ID = "blackjack" IMAGES_DIR = Path(__file__).resolve().parents[3] / "resources" / "images" +BJ_DEALER_CARD_SIZE = (86, 125) + BJ_OVAL_BOT_COORDS = ( - (0.160, 0.76), # Platz 1: Unten links (Spieler 1) - (0.160, 0.24), # Platz 2: Oben links (Spieler 2) - (0.840, 0.24), # Platz 3: Oben rechts (Spieler 3) - (0.840, 0.76), # Platz 4: Unten rechts (Spieler 4) + (0.155, 0.76), # Platz 1: Unten links (Spieler 1) + (0.155, 0.25), # Platz 2: Oben links (Spieler 2) + (0.845, 0.25), # Platz 3: Oben rechts (Spieler 3) + (0.845, 0.76), # Platz 4: Unten rechts (Spieler 4) ) BJ_SEAT_LAYOUT_BY_COUNT = { @@ -106,6 +108,31 @@ class BlackjackTableView: return None return None + def _create_fanned_cards_canvas( + self, + parent: tk.Widget, + photos: list, + card_size: tuple[int, int], + visible_step: int, + bg_color: str, + max_width: int = 360, + ) -> tk.Canvas: + """Zeichnet Karten überlappend auf ein Canvas (ohne negative Tkinter-pack-Paddings).""" + cw, ch = card_size + n = len(photos) + if n <= 0: + return tk.Canvas(parent, width=cw, height=ch, bg=bg_color, highlightthickness=0, bd=0) + + step = visible_step + if n > 1 and (cw + (n - 1) * step) > max_width: + step = max(18, (max_width - cw) // (n - 1)) + + total_w = cw + (n - 1) * step if n > 1 else cw + cv = tk.Canvas(parent, width=total_w, height=ch, bg=bg_color, highlightthickness=0, bd=0) + for i, ph in enumerate(photos): + cv.create_image(i * step, 0, image=ph, anchor="nw") + return cv + # --------------------------------------------------------- # AUTO-SAVE & RESUME (nur aktiv während The Devil's Deal!) # --------------------------------------------------------- @@ -233,14 +260,8 @@ class BlackjackTableView: ) self.table_frame.place(relx=0.5, rely=0.535, anchor="center", relwidth=0.96, relheight=0.88) - self.pot_lbl = tk.Label( - self.table_frame, text="", font=("Georgia", 11, "bold"), - fg=ACCENT_GOLD, bg=PANEL_BG, pady=4, highlightthickness=1, highlightbackground=SUBTLE_BORDER - ) - self.pot_lbl.pack(fill="x", side="top", pady=(0, 4)) - - # Kompakte 3-Spalten-Leiste unten (identisch zu Poker) - bottom_area = tk.Frame(self.table_frame, bg=TABLE_BG, height=224) + # Kompakte 3-Spalten-Leiste unten (Links: Tisch- & Regelinfos | Mitte: Eigene Hand | Rechts: Aktionen) + bottom_area = tk.Frame(self.table_frame, bg=TABLE_BG, height=218) bottom_area.pack(fill="x", side="bottom", pady=(6, 0)) bottom_area.pack_propagate(False) @@ -249,34 +270,65 @@ class BlackjackTableView: bottom_area.columnconfigure(2, weight=26, uniform="bjcols") bottom_area.rowconfigure(0, weight=1) + # Linkes Zusatz-/Status-Panel (verhindert Clipping in der Mitte) self.left_info_panel = tk.Frame( - bottom_area, bg=PANEL_BG, padx=8, pady=5, + bottom_area, bg=PANEL_BG, padx=10, pady=8, highlightthickness=1, highlightbackground=BORDER_COLOR ) self.left_info_panel.grid(row=0, column=0, sticky="nsew", padx=(0, 6)) + tk.Label( + self.left_info_panel, + text=t(f"variant_{self.variant_key}"), + font=("Helvetica", 10, "bold"), + fg=ACCENT_GOTH, + bg=PANEL_BG, + anchor="w", + ).pack(fill="x") + + tk.Frame(self.left_info_panel, bg=SUBTLE_BORDER, height=1).pack(fill="x", pady=(4, 6)) + + tk.Label( + self.left_info_panel, + text=t("bj_variant_desc", self.cfg["decks"], BJ_INITIAL_ANTE), + font=("Helvetica", 8), + fg=MUTED_FG, + bg=PANEL_BG, + wraplength=280, + justify="left", + anchor="w", + ).pack(fill="x", pady=(0, 8)) + + self.status_lbl = tk.Label( + self.left_info_panel, + text="", + font=("Helvetica", 9, "bold"), + fg=ACCENT_GOLD, + bg=PANEL_BG, + wraplength=280, + justify="left", + anchor="nw", + ) + self.status_lbl.pack(fill="both", expand=True) + + # Mittleres Panel: Nutzer-Hand center_player_wrap = tk.Frame( bottom_area, bg=PANEL_BG, padx=10, pady=6, highlightthickness=1, highlightbackground=SUBTLE_BORDER ) center_player_wrap.grid(row=0, column=1, sticky="nsew", padx=4) - self.status_lbl = tk.Label( - center_player_wrap, text="", font=("Georgia", 10, "bold"), - fg=ACCENT_GOLD, bg=PANEL_BG, wraplength=410, justify="center" - ) - self.status_lbl.pack(side="top", pady=(0, 3)) - self.player_sec = tk.Frame(center_player_wrap, bg=PANEL_BG) self.player_sec.pack(fill="both", expand=True) + # Rechtes Panel: Vertikale Aktions-Buttons direkt neben dem Spieler self.controls_frame = tk.Frame( bottom_area, bg=PANEL_BG, padx=8, pady=5, highlightthickness=1, highlightbackground=BORDER_COLOR ) self.controls_frame.grid(row=0, column=2, sticky="nsew", padx=(6, 0)) - # Canvas für den ovalen Tisch (`poker_table.jpg`[cite: 9]) + # Canvas für den ovalen Tisch (`poker_table.jpg`) self.arena_canvas = tk.Canvas( self.table_frame, bg="#120f18", highlightthickness=1, highlightbackground=SUBTLE_BORDER ) @@ -286,20 +338,33 @@ class BlackjackTableView: # Bank-Box (oben mittig auf dem Canvas) felt_bg = "#1b1626" self.board_box = tk.Frame( - self.arena_canvas, bg=felt_bg, padx=10, pady=6, + self.arena_canvas, bg=felt_bg, padx=10, pady=5, highlightthickness=1, highlightbackground=SUBTLE_BORDER ) - self.board_box.place(relx=0.50, rely=0.28, anchor="center") + self.board_box.place(relx=0.50, rely=0.25, anchor="center") self.dealer_lbl = tk.Label( self.board_box, text=t("bj_dealer_title"), - font=("Georgia", 9, "bold"), fg=MUTED_FG, bg=felt_bg + font=("Helvetica", 9, "bold"), fg=MUTED_FG, bg=felt_bg ) self.dealer_lbl.pack(pady=(0, 3)) - self.dealer_cards_frame = tk.Frame(self.board_box, bg=felt_bg, height=PLAYING_CARD_SIZE[1] + 2) + self.dealer_cards_frame = tk.Frame(self.board_box, bg=felt_bg) self.dealer_cards_frame.pack() + # Pot-Ansicht zentral in der Tischmitte (wie auf der Skizze) + self.pot_box = tk.Frame( + self.arena_canvas, bg=PANEL_BG, padx=14, pady=6, + highlightthickness=1, highlightbackground=ACCENT_GOLD + ) + self.pot_box.place(relx=0.50, rely=0.67, anchor="center") + + self.pot_lbl = tk.Label( + self.pot_box, text="", font=("Helvetica", 10, "bold"), + fg=ACCENT_GOLD, bg=PANEL_BG + ) + self.pot_lbl.pack() + self._bot_seat_frames: list[tk.Frame] = [] self._refresh_header() @@ -386,7 +451,7 @@ class BlackjackTableView: self._begin_new_table_cycle() # --------------------------------------------------------- - # RENDERING TISCH & SPIELER HÄNDE (Karten mit Überlappung) + # RENDERING TISCH & SPIELER HÄNDE (Kartenfächer via Canvas) # --------------------------------------------------------- @staticmethod def _hand_state_suffix(hand: PlayerHand) -> str: @@ -419,21 +484,19 @@ class BlackjackTableView: b_col, thick = BORDER_COLOR, 1 box = tk.Frame( - self.arena_canvas, bg="#191521", padx=8, pady=4, width=175, + self.arena_canvas, bg="#191521", padx=8, pady=4, width=182, highlightthickness=thick, highlightbackground=b_col ) box.place(relx=rx, rely=ry, anchor="center") self._bot_seat_frames.append(box) disp_name = t("bj_bot_rebuy", bot.name) if bot.rebought else bot.name - tk.Label(box, text=disp_name, font=("Georgia", 9, "bold"), fg=ACCENT_GOTH, bg="#191521").pack() + tk.Label(box, text=disp_name, font=("Helvetica", 9, "bold"), fg=ACCENT_GOTH, bg="#191521").pack() tk.Label(box, text=t("bj_bot_gold_lbl", bot.gold), font=("Helvetica", 8, "bold"), fg=ACCENT_GOLD, bg="#191521").pack(pady=(1, 2)) - cards_f = tk.Frame(box, bg="#191521", height=82) - cards_f.pack(pady=2) - show_faces = reveal_opponents or bot.busted - for c_idx, card in enumerate(bot.hand): + bot_photos = [] + for card in bot.hand: photo = ( self.ctx.assets.get_card_photo(card.image_filename, size=BJ_BOT_CARD_SIZE) if show_faces @@ -441,11 +504,13 @@ class BlackjackTableView: ) if photo: self._photo_refs.append(photo) - lbl = tk.Label(cards_f, image=photo, bg="#191521", bd=0) - lbl.pack(side="left") - if c_idx > 0: - # Karten leicht überlappen lassen (~35px sichtbar) - lbl.pack_configure(padx=(-38, 0)) + bot_photos.append(photo) + + if bot_photos: + cv = self._create_fanned_cards_canvas( + box, bot_photos, BJ_BOT_CARD_SIZE, visible_step=28, bg_color="#191521", max_width=164 + ) + cv.pack(pady=2) if reveal_opponents and bot.hand: b_val, _ = HandEvaluator.evaluate(bot.hand) @@ -477,17 +542,18 @@ class BlackjackTableView: if len(hands) == 1: h = hands[0] - cards_f = tk.Frame(self.player_sec, bg=PANEL_BG, height=132) - cards_f.pack(pady=2) - for c_idx, card in enumerate(h.cards): + p_photos = [] + for card in h.cards: photo = self.ctx.assets.get_card_photo(card.image_filename, size=PLAYING_CARD_SIZE) if photo: self._photo_refs.append(photo) - lbl = tk.Label(cards_f, image=photo, bg=PANEL_BG, bd=0) - lbl.pack(side="left") - if c_idx > 0: - # Überlappung bei eigener Hand - lbl.pack_configure(padx=(-42, 0)) + p_photos.append(photo) + + if p_photos: + cv = self._create_fanned_cards_canvas( + self.player_sec, p_photos, PLAYING_CARD_SIZE, visible_step=38, bg_color=PANEL_BG, max_width=400 + ) + cv.pack(expand=True, pady=(2, 2)) p_val, p_soft = HandEvaluator.evaluate(h.cards) soft_hint = t("bj_soft_hint", p_val) if p_soft and p_val < 21 else "" @@ -496,7 +562,7 @@ class BlackjackTableView: tk.Label( self.player_sec, text=t("bj_player_total", p_val, soft_hint, h.bet_in_pot, suffix), - font=("Georgia", 11, "bold"), fg=lbl_col, bg=PANEL_BG + font=("Helvetica", 10, "bold"), fg=lbl_col, bg=PANEL_BG, pady=2 ).pack(side="bottom", pady=(2, 2)) return @@ -512,16 +578,18 @@ class BlackjackTableView: ) hbox.pack(side="left", padx=5) - cards_f = tk.Frame(hbox, bg=CELL_BG, height=108) - cards_f.pack(pady=2) - for c_idx, card in enumerate(h.cards): + sp_photos = [] + for card in h.cards: photo = self.ctx.assets.get_card_photo(card.image_filename, size=BJ_SPLIT_CARD_SIZE) if photo: self._photo_refs.append(photo) - lbl = tk.Label(cards_f, image=photo, bg=CELL_BG, bd=0) - lbl.pack(side="left") - if c_idx > 0: - lbl.pack_configure(padx=(-36, 0)) + sp_photos.append(photo) + + if sp_photos: + cv = self._create_fanned_cards_canvas( + hbox, sp_photos, BJ_SPLIT_CARD_SIZE, visible_step=32, bg_color=CELL_BG, max_width=195 + ) + cv.pack(pady=2) p_val, p_soft = HandEvaluator.evaluate(h.cards) soft_hint = t("bj_soft_hint", p_val) if p_soft and p_val < 21 else "" @@ -530,7 +598,7 @@ class BlackjackTableView: tk.Label( hbox, text=t("bj_hand_box_title", idx + 1, p_val, soft_hint, h.bet_in_pot, suffix), - font=("Georgia", 9, "bold"), fg=lbl_col, bg=CELL_BG + font=("Helvetica", 9, "bold"), fg=lbl_col, bg=CELL_BG, pady=1 ).pack(pady=(1, 0)) def _render_table(self, reveal_opponents: bool, reveal_dealer: bool): @@ -538,20 +606,24 @@ class BlackjackTableView: for w in self.dealer_cards_frame.winfo_children(): w.destroy() + felt_bg = "#1b1626" + d_photos = [] for c_idx, card in enumerate(self.engine.dealer_hand): photo = ( - self.ctx.assets.get_card_back_photo(color=self.cfg["back_color"], size=PLAYING_CARD_SIZE) + self.ctx.assets.get_card_back_photo(color=self.cfg["back_color"], size=BJ_DEALER_CARD_SIZE) if c_idx == 1 and not reveal_dealer - else self.ctx.assets.get_card_photo(card.image_filename, size=PLAYING_CARD_SIZE) + else self.ctx.assets.get_card_photo(card.image_filename, size=BJ_DEALER_CARD_SIZE) ) if photo: self._photo_refs.append(photo) - lbl = tk.Label(self.dealer_cards_frame, image=photo, bg="#1b1626", bd=0) - lbl.pack(side="left") - if c_idx > 0: - lbl.pack_configure(padx=(-42, 0)) + d_photos.append(photo) + + if d_photos: + d_cv = self._create_fanned_cards_canvas( + self.dealer_cards_frame, d_photos, BJ_DEALER_CARD_SIZE, visible_step=36, bg_color=felt_bg, max_width=320 + ) + d_cv.pack() - felt_bg = "#1b1626" if not reveal_dealer and self.engine.dealer_hand: up_val, _ = HandEvaluator.evaluate([self.engine.dealer_hand[0]]) self.dealer_lbl.configure(text=t("bj_dealer_shows", up_val), bg=felt_bg) @@ -680,15 +752,15 @@ class BlackjackTableView: col, t("bj_tree_btn_call_yes", to_call), self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active, lambda: self._on_step1_call_yes(to_call), - sound_mgr=self.ctx.sounds, width=170, height=30, font=("Helvetica", 9, "bold") - ).pack(pady=2) + sound_mgr=self.ctx.sounds, width=175, height=30, font=("Helvetica", 9, "bold") + ).pack(pady=3) ImageButton( col, t("bj_tree_btn_call_no_lose"), self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active, self._on_fold_hand, - sound_mgr=self.ctx.sounds, width=170, height=30, font=("Helvetica", 9, "bold") - ).pack(pady=2) + sound_mgr=self.ctx.sounds, width=175, height=30, font=("Helvetica", 9, "bold") + ).pack(pady=3) return if self.turn_step == STEP_ZIEHEN: @@ -698,7 +770,7 @@ class BlackjackTableView: col, t("bj_tree_btn_draw_yes"), self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active, self._on_step2_draw_yes, - sound_mgr=self.ctx.sounds, width=170, height=28, font=("Helvetica", 9, "bold") + sound_mgr=self.ctx.sounds, width=175, height=28, font=("Helvetica", 9, "bold") ).pack(pady=2) if self.engine.can_double_down(self.active_hand_idx, wallet): @@ -707,7 +779,7 @@ class BlackjackTableView: col, t("bj_double_btn", dd_cost), self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active, self._on_step2_double_down, - sound_mgr=self.ctx.sounds, width=170, height=28, font=("Helvetica", 9, "bold") + sound_mgr=self.ctx.sounds, width=175, height=28, font=("Helvetica", 9, "bold") ).pack(pady=2) if self.engine.can_split_hand(self.active_hand_idx, wallet): @@ -716,42 +788,45 @@ class BlackjackTableView: col, t("bj_split_btn", sp_cost), self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active, self._on_step2_split, - sound_mgr=self.ctx.sounds, width=170, height=28, font=("Helvetica", 9, "bold") + sound_mgr=self.ctx.sounds, width=175, height=28, font=("Helvetica", 9, "bold") ).pack(pady=2) ImageButton( col, t("bj_tree_btn_draw_no"), self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active, self._on_step2_draw_no, - sound_mgr=None, width=170, height=28, font=("Helvetica", 9, "bold") + sound_mgr=None, width=175, height=28, font=("Helvetica", 9, "bold") ).pack(pady=2) ImageButton( col, t("bj_fold_btn"), self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active, self._on_fold_hand, - sound_mgr=self.ctx.sounds, width=170, height=28, font=("Helvetica", 9, "bold") + sound_mgr=self.ctx.sounds, width=175, height=28, font=("Helvetica", 9, "bold") ).pack(pady=2) return if self.turn_step == STEP_ERHOEHEN: self.status_lbl.configure(text=t("bj_tree_step3_raise", hand_tag)) dyn_chips = self._get_current_level_chips() + avail_chips = [c for c in dyn_chips if wallet >= c] - for chip in dyn_chips: - if wallet >= chip: + if avail_chips: + grid_f = tk.Frame(col, bg=PANEL_BG) + grid_f.pack(pady=(2, 4)) + for idx, chip in enumerate(avail_chips): ImageButton( - col, f"+{chip} Gold", + grid_f, f"+{chip}g", self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active, lambda c=chip: self._on_step3_raise_yes(c), - sound_mgr=self.ctx.sounds, width=170, height=26, font=("Helvetica", 9, "bold") - ).pack(pady=1) + sound_mgr=self.ctx.sounds, width=85, height=28, font=("Helvetica", 9, "bold") + ).grid(row=idx // 2, column=idx % 2, padx=2, pady=2) ImageButton( col, t("bj_tree_btn_raise_no"), self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active, self._on_step3_raise_no, - sound_mgr=self.ctx.sounds, width=170, height=28, font=("Helvetica", 9, "bold") + sound_mgr=self.ctx.sounds, width=175, height=30, font=("Helvetica", 9, "bold") ).pack(pady=2) # --------------------------------------------------------- diff --git a/main.py b/main.py index ab8bad3..bc79f64 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- import os import signal +import subprocess import sys import tempfile +import warnings from pathlib import Path from PIL import Image, ImageTk @@ -31,6 +33,8 @@ def _prepare_os_app_identity(): except Exception: pass elif sys.platform.startswith("linux"): + # Hilft X11/Tkinter bereits vor Fenstererstellung bei der Ressourcen-Zuordnung + os.environ.setdefault("RESOURCE_NAME", APP_WM_CLASS) try: import ctypes libc = ctypes.CDLL("libc.so.6") @@ -42,47 +46,104 @@ def _prepare_os_app_identity(): def _extract_ico_frames(icon_path: Path) -> tuple[Image.Image | None, list[Image.Image]]: """Liest das größte Bild aus game_icon.ico (auch wenn es intern PNG/JPEG/BMP-codiert ist).""" try: - with Image.open(icon_path) as ico: - best_img = None - best_area = -1 + with warnings.catch_warnings(): + warnings.simplefilter("ignore", UserWarning) + with Image.open(icon_path) as ico: + best_img = None + best_area = -1 - ico_helper = getattr(ico, "ico", None) - if ico_helper is not None and hasattr(ico_helper, "sizes"): - for sz in ico_helper.sizes(): - try: - frame = ico_helper.getimage(sz).convert("RGBA") - area = frame.width * frame.height - if area > best_area: - best_area = area - best_img = frame - except Exception: - continue + ico_helper = getattr(ico, "ico", None) + if ico_helper is not None and hasattr(ico_helper, "sizes"): + for sz in ico_helper.sizes(): + try: + frame = ico_helper.getimage(sz).convert("RGBA") + area = frame.width * frame.height + if area > best_area: + best_area = area + best_img = frame + except Exception: + continue - if best_img is None: - n_frames = getattr(ico, "n_frames", 1) - for idx in range(n_frames): - try: - ico.seek(idx) - frame = ico.copy().convert("RGBA") - area = frame.width * frame.height - if area > best_area: - best_area = area - best_img = frame - except Exception: - continue + if best_img is None: + n_frames = getattr(ico, "n_frames", 1) + for idx in range(n_frames): + try: + ico.seek(idx) + frame = ico.copy().convert("RGBA") + area = frame.width * frame.height + if area > best_area: + best_area = area + best_img = frame + except Exception: + continue - if best_img is None: - best_img = ico.convert("RGBA") + if best_img is None: + best_img = ico.convert("RGBA") - cascade = [ - best_img.resize((px, px), Image.Resampling.LANCZOS) - for px in (256, 128, 64, 48, 32, 16) - ] - return best_img, cascade + cascade = [ + best_img.resize((px, px), Image.Resampling.LANCZOS) + for px in (256, 128, 64, 48, 32, 16) + ] + return best_img, cascade except Exception: return None, [] +def ensure_crostini_shelf_icon(icon_ico_path: Path, wm_class: str = APP_WM_CLASS) -> None: + """ + Erzeugt unter ChromeOS (Crostini) vollautomatisch im User-Verzeichnis (~/.local) + ein PNG-Icon + .desktop-Zuordnung für den garcon-Daemon, damit das Shelf-Icon + ohne manuelle System-Installation statt eines grauen Kastens erscheint. + """ + if not sys.platform.startswith("linux"): + return + + is_crostini = ( + Path("/dev/.cros_milestone").exists() + or "sommelier" in os.environ.get("XDG_RUNTIME_DIR", "").lower() + or Path("/opt/google/cros-containers").exists() + ) + if not is_crostini or not icon_ico_path.is_file(): + return + + try: + data_home = Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share")) + apps_dir = data_home / "applications" + desktop_file = apps_dir / f"{wm_class}.desktop" + + best_pil, _ = _extract_ico_frames(icon_ico_path) + if best_pil is not None: + for px in (128, 64, 48): + icon_dir = data_home / "icons" / "hicolor" / f"{px}x{px}" / "apps" + icon_png = icon_dir / f"{wm_class}.png" + if not icon_png.is_file(): + icon_dir.mkdir(parents=True, exist_ok=True) + best_pil.resize((px, px), Image.Resampling.LANCZOS).save(icon_png, format="PNG") + + if getattr(sys, "frozen", False): + exec_cmd = f'"{Path(sys.executable).resolve()}"' + else: + exec_cmd = f'"{sys.executable}" "{Path(sys.argv[0]).resolve()}"' + + desktop_content = ( + "[Desktop Entry]\n" + "Version=1.0\n" + "Type=Application\n" + "Name=The Goth Cardgame Collection\n" + f"Exec={exec_cmd}\n" + f"Icon={wm_class}\n" + f"StartupWMClass={wm_class}\n" + "Categories=Game;CardGame;\n" + "Terminal=false\n" + ) + + if not desktop_file.is_file() or desktop_file.read_text(encoding="utf-8") != desktop_content: + apps_dir.mkdir(parents=True, exist_ok=True) + desktop_file.write_text(desktop_content, encoding="utf-8") + except Exception: + pass + + def _apply_windows_icon(app, icon_path: Path, best_pil: Image.Image | None): """ Setzt das Icon unter Windows nativ via Tk iconbitmap + Win32 WM_SETICON, @@ -160,6 +221,28 @@ def _apply_cross_platform_icon(app, root_path: Path): app.tk.call("tk", "appname", APP_WM_CLASS) except Exception: pass + # Erzwingt die exakte X11 WM_CLASS am Top-Level-Fenster für Sommelier/Wayland + try: + app.update_idletasks() + subprocess.run( + [ + "xprop", + "-id", + hex(app.winfo_id()), + "-f", + "WM_CLASS", + "8s", + "-set", + "WM_CLASS", + APP_WM_CLASS, + ], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + timeout=1.5, + check=False, + ) + except Exception: + pass icon_path = (root_path / APP_ICON_REL_PATH).resolve() if not icon_path.is_file(): @@ -173,7 +256,13 @@ def _apply_cross_platform_icon(app, root_path: Path): if cascade_pils: try: - tk_photos = [ImageTk.PhotoImage(im) for im in cascade_pils] + # Unter Linux/XWayland max. 128x128 übergeben, da 256x256 in _NET_WM_ICON oft grau wird + usable_pils = ( + [im for im in cascade_pils if im.width <= 128] + if sys.platform.startswith("linux") + else cascade_pils + ) + tk_photos = [ImageTk.PhotoImage(im) for im in usable_pils] app._app_icon_refs = tk_photos app.iconphoto(True, *tk_photos) except Exception: @@ -195,13 +284,6 @@ def _apply_cross_platform_icon(app, root_path: Path): def _install_clean_shutdown(app: GothCardCollectionView): - """ - Sorgt für komplett lautloses Beenden beim Klick auf X und bei Strg+C: - 1. Führt evtl. bestehenden WindowStatePersistence-Close-Hook aus (solange DB offen ist) - 2. Zerstört Kind-Widgets kontrolliert (feuert -Save-Hooks aktiver Spieltische) - 3. Bricht restlos alle noch geplanten Tcl-after()-Timer ab - 4. Beendet pygame und schließt SQLite sauber ohne Traceback - """ shutting_down = False prev_wm_delete_cmd = None try: @@ -209,7 +291,6 @@ def _install_clean_shutdown(app: GothCardCollectionView): except Exception: prev_wm_delete_cmd = None - # Unterdrückt verwaiste Tcl-Callback-Fehlermeldungen während des Shutdowns orig_report = getattr(app, "report_callback_exception", None) def _filtered_callback_exc(exc, val, tb): @@ -226,7 +307,6 @@ def _install_clean_shutdown(app: GothCardCollectionView): return shutting_down = True - # 1. Kind-Widgets zuerst abräumen, damit aktive Spieltische ihren Stand noch speichern können try: for child in list(app.winfo_children()): try: @@ -236,15 +316,12 @@ def _install_clean_shutdown(app: GothCardCollectionView): except Exception: pass - # 2. Falls WindowStatePersistence vorher einen WM_DELETE_WINDOW-Tcl-Befehl gesetzt hat, - # Geometrie noch sichern, bevor wir Timer & DB schließen if prev_wm_delete_cmd: try: app.tk.call(prev_wm_delete_cmd) except Exception: pass - # 3. Alle noch ausstehenden Tcl-after()-Jobs abbrechen try: for after_id in app.tk.call("after", "info"): try: @@ -254,7 +331,6 @@ def _install_clean_shutdown(app: GothCardCollectionView): except Exception: pass - # 4. Audio & SQLite kontrolliert herunterfahren try: if pygame.mixer.get_init(): pygame.mixer.music.stop() @@ -267,7 +343,6 @@ def _install_clean_shutdown(app: GothCardCollectionView): except Exception: pass - # 5. Tk-Hauptschleife und Fenster sauber schließen try: app.quit() except Exception: @@ -280,7 +355,6 @@ def _install_clean_shutdown(app: GothCardCollectionView): app.protocol("WM_DELETE_WINDOW", graceful_exit) - # Strg+C (SIGINT) abfangen + kurzer Python-Heartbeat, damit Windows SIGINT sofort zustellt try: signal.signal(signal.SIGINT, lambda _sig, _frm: graceful_exit()) except Exception: @@ -300,7 +374,10 @@ def _install_clean_shutdown(app: GothCardCollectionView): def main(): _prepare_os_app_identity() - root_path = Path(__file__).resolve().parent + root_path = Path(getattr(sys, "_MEIPASS", Path(__file__).resolve().parent)) + + # Vor dem Erstellen des Tk-Fensters aufrufen, damit garcon das Icon bereits kennt! + ensure_crostini_shelf_icon((root_path / APP_ICON_REL_PATH).resolve(), APP_WM_CLASS) FontLoader.register_fonts(root_path) diff --git a/models/__pycache__/database.cpython-311.pyc b/models/__pycache__/database.cpython-311.pyc index 8151db5..67a635c 100644 Binary files a/models/__pycache__/database.cpython-311.pyc and b/models/__pycache__/database.cpython-311.pyc differ diff --git a/resources/code_res/__pycache__/game_constants.cpython-311.pyc b/resources/code_res/__pycache__/game_constants.cpython-311.pyc index e775226..d2ec927 100644 Binary files a/resources/code_res/__pycache__/game_constants.cpython-311.pyc and b/resources/code_res/__pycache__/game_constants.cpython-311.pyc differ diff --git a/resources/code_res/internal_base.db b/resources/code_res/internal_base.db index 0264e22..fde2fcb 100644 Binary files a/resources/code_res/internal_base.db and b/resources/code_res/internal_base.db differ diff --git a/resources/code_res/sql/02_blackjack.sql b/resources/code_res/sql/02_blackjack.sql index 4f7d43d..9f9834c 100644 --- a/resources/code_res/sql/02_blackjack.sql +++ b/resources/code_res/sql/02_blackjack.sql @@ -276,4 +276,6 @@ INSERT OR REPLACE INTO base_i18n (key, lang, val) VALUES ('variant_bj_classic', 'DE', 'Blackjack – Klassisch'), ('variant_bj_classic', 'EN', 'Blackjack – Classic'), ('variant_bj_highstakes', 'DE', 'Blackjack – Hoher Einsatz'), -('variant_bj_highstakes', 'EN', 'Blackjack – High Stakes'); +('variant_bj_highstakes', 'EN', 'Blackjack – High Stakes'), +('bj_gold_display_lbl', 'DE', 'Guthaben: {0} Gold'), +('bj_gold_display_lbl', 'EN', 'Balance: {0} Gold'); \ No newline at end of file diff --git a/view/main_window.py b/view/main_window.py index 298af45..5aa47f3 100644 --- a/view/main_window.py +++ b/view/main_window.py @@ -17,10 +17,12 @@ from view.menus.main_menu_view import MainMenuView from view.menus.statistics_view import StatisticsView from view.widgets.resizing_bg import ResizingBG +APP_WM_CLASS = "goth-cardgame-collection" + class GothCardCollectionView(tk.Tk): def __init__(self, ctrl, root_dir: Path): - super().__init__() + super().__init__(baseName=APP_WM_CLASS, className=APP_WM_CLASS) self.ctrl = ctrl self.title(t("app_title")) self.configure(bg=BG_COLOR) @@ -85,11 +87,17 @@ class GothCardCollectionView(tk.Tk): def _on_window_configure(self, event): if event.widget == self: if self._geom_save_job: - self.after_cancel(self._geom_save_job) + try: + self.after_cancel(self._geom_save_job) + except Exception: + pass self._geom_save_job = self.after(400, self._save_window_state) def _save_window_state(self): + self._geom_save_job = None try: + if not self.winfo_exists(): + return is_zoomed = False if sys.platform == "darwin": is_zoomed = ( @@ -113,11 +121,18 @@ class GothCardCollectionView(tk.Tk): pass def close_app(self): + if self._geom_save_job: + try: + self.after_cancel(self._geom_save_job) + except Exception: + pass + self._geom_save_job = None self._save_window_state() Database.close() self.destroy() def clear_window(self, apply_global_bg=True): + self.bg_widget = None for widget in self.winfo_children(): widget.destroy() if apply_global_bg and self.assets.raw_bg: