This commit is contained in:
2026-06-13 22:47:31 +02:00
parent add3da5177
commit d1446fc452
8032 changed files with 2650751 additions and 1551 deletions

View File

@@ -617,10 +617,55 @@ def save_main_languages(lang_in: str, lang_out: str):
pass
_MAIN_ROOT = None
def _clear_main_root(widget=None) -> None:
global _MAIN_ROOT
if _MAIN_ROOT is widget or widget is None:
_MAIN_ROOT = None
def focus_existing_translator(parent=None):
"""Vorhandenes Übersetzerfenster nach vorne holen (Singleton)."""
global _MAIN_ROOT
root = _MAIN_ROOT
if root is None:
return None
try:
if not root.winfo_exists():
_MAIN_ROOT = None
return None
except Exception:
_MAIN_ROOT = None
return None
try:
root.deiconify()
root.wm_state("normal")
except Exception:
pass
try:
from aza_ui_helpers import bring_tool_window_to_front, center_tool_window
center_tool_window(root, parent=parent, vertical_center=True)
bring_tool_window_to_front(root, flash_ms=1200)
except Exception:
pass
try:
root.focus_force()
except Exception:
pass
return root
def main(parent=None):
"""Startet das Übersetzer-Modul.
parent: Wenn angegeben (Tk-Window), wird ein Toplevel statt eigenem Tk() erstellt
und kein eigener mainloop() aufgerufen (Embedded-Modus)."""
global _MAIN_ROOT
existing = focus_existing_translator(parent)
if existing is not None:
return existing
load_dotenv()
try:
from aza_ai_client import get_ai_client
@@ -694,6 +739,7 @@ def main(parent=None):
save_main_languages(lin, lou)
except Exception:
pass
_clear_main_root(root)
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_main_close)
@@ -924,8 +970,8 @@ def main(parent=None):
lang_in_var.set(out_val)
lang_out_var.set(in_val)
umkehr_row = tk.Frame(root, bg=_BG, padx=14, pady=(0, 4))
umkehr_row.pack(fill="x")
umkehr_row = tk.Frame(root, bg=_BG)
umkehr_row.pack(fill="x", padx=14, pady=(0, 4))
btn_swap = _make_feedback_btn(umkehr_row, text="Umkehren", command=swap_languages,
bg=_BTN_SEC, fg=_BTN_PRI, active_bg="#E8F4FA",
font_spec=("Segoe UI", 9, "bold"), padx=12, pady=4)
@@ -979,8 +1025,8 @@ def main(parent=None):
bg=_BTN_SEC, fg=_BTN_PRI, active_bg="#E8F4FA", font_spec=("Segoe UI", 9),
padx=10, pady=4).pack(anchor="center")
btn_frame = tk.Frame(root, bg=_BG, padx=14, pady=(0, 8))
btn_frame.pack(fill="x")
btn_frame = tk.Frame(root, bg=_BG)
btn_frame.pack(fill="x", padx=14, pady=(0, 8))
status_var = tk.StringVar(value="Bereit.")
status_row = ttk.Frame(btn_frame)
status_row.pack(fill="x", pady=(0, 4))
@@ -2556,8 +2602,22 @@ def main(parent=None):
ttk.Sizegrip(root).place(relx=1.0, rely=1.0, anchor="se")
_MAIN_ROOT = root
try:
root.bind("<Destroy>", lambda e: _clear_main_root(e.widget) if e.widget is root else None, add="+")
except Exception:
pass
try:
from aza_ui_helpers import bring_tool_window_to_front, center_tool_window
center_tool_window(root, parent=parent if _embedded else None, vertical_center=True)
bring_tool_window_to_front(root, flash_ms=1200)
except Exception:
pass
if not _embedded:
root.mainloop()
return root
if __name__ == "__main__":