mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-06 04:44:18 +01:00
Starter language switch: key status lines by Tcl name
tkinter.StringVar is unhashable, so the Windows self-test failed building the starter. The GUI self-test now also switches the language twice. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ybp8UvaVnj6zwuseaMHD73
This commit is contained in:
3 files changed
+21
-8
No files matched your search
+3
-2
@@ -213,13 +213,14 @@ class Starter:
|
||||
pass
|
||||
self.tr = Translator(language)
|
||||
self.language.set(LANGUAGE_NAMES[language])
|
||||
for variable, (key, values) in self.texts.items():
|
||||
for variable, key, values in self.texts.values():
|
||||
variable.set(self.t(key, **values))
|
||||
self._build()
|
||||
|
||||
def _say(self, variable, key: str, **values):
|
||||
"""Set a status line by key so a language switch can re-translate it."""
|
||||
self.texts[variable] = (key, values)
|
||||
# Tk variables are unhashable: keyed by their Tcl name.
|
||||
self.texts[str(variable)] = (variable, key, values)
|
||||
variable.set(self.t(key, **values))
|
||||
|
||||
def report_bug(self):
|
||||
|
||||
+15
-6
@@ -85,6 +85,7 @@ def self_test(report: str) -> int:
|
||||
def _gui_self_test() -> str:
|
||||
"""Build the starter window once (Tk bundled, QR drawn), then close it."""
|
||||
try:
|
||||
import tempfile
|
||||
import tkinter as tk
|
||||
|
||||
from src.launcher.app import Starter
|
||||
@@ -92,12 +93,20 @@ def _gui_self_test() -> str:
|
||||
root = tk.Tk()
|
||||
try:
|
||||
root.withdraw()
|
||||
starter = Starter(root, check_updates=False)
|
||||
starter._show_status({"state": "running", "url": "http://192.168.1.2:8765/",
|
||||
"code": "123ABC", "solo": False})
|
||||
root.update()
|
||||
if not starter.qr.find_all():
|
||||
return "qr missing"
|
||||
with tempfile.TemporaryDirectory(prefix="u-jagd-gui-") as folder:
|
||||
settings = os.path.join(folder, "settings.json")
|
||||
starter = Starter(root, check_updates=False, preferences_path=settings)
|
||||
starter._show_status({"state": "running", "url": "http://192.168.1.2:8765/",
|
||||
"code": "123ABC", "solo": False})
|
||||
root.update()
|
||||
if not starter.qr.find_all():
|
||||
return "qr missing"
|
||||
# The language switch rebuilds the window and saves the choice.
|
||||
for language in ("de", "en"):
|
||||
starter.choose_language(language)
|
||||
root.update()
|
||||
if starter.tr.language != "en" or not os.path.exists(settings):
|
||||
return "language switch"
|
||||
finally:
|
||||
root.destroy()
|
||||
except Exception as exc: # noqa: BLE001 - reported, fatal only on Windows
|
||||
|
||||
@@ -68,6 +68,9 @@ def test_the_game_tells_its_listener_the_saved_language(tmp_path, monkeypatch):
|
||||
|
||||
|
||||
class _Var:
|
||||
# Like tkinter.StringVar: unhashable.
|
||||
__hash__ = None
|
||||
|
||||
def __init__(self, value=""):
|
||||
self.value = value
|
||||
|
||||
|
||||
Reference in new issue
Block a user