update
This commit is contained in:
@@ -8,9 +8,14 @@ Prompt-Vorlagen sind ein eigenes Modul und NICHT Teil dieser UI.
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox, ttk
|
||||
from tkinter import ttk
|
||||
from typing import Any, Callable, List
|
||||
|
||||
from aza_ui_helpers import (
|
||||
aza_askyesno,
|
||||
aza_showinfo,
|
||||
)
|
||||
|
||||
from aza_bibliothek import (
|
||||
CATEGORY_LABELS,
|
||||
CATEGORY_TO_STORE,
|
||||
@@ -71,36 +76,14 @@ def _btn(parent, text: str, command, *, primary: bool = False, danger: bool = Fa
|
||||
)
|
||||
|
||||
|
||||
def _center_top(win, w: int, h: int) -> None:
|
||||
"""Zentriert das Fenster horizontal, leicht oben (analog AzA-Werkzeugfenster)."""
|
||||
try:
|
||||
win.update_idletasks()
|
||||
sw = win.winfo_screenwidth()
|
||||
sh = win.winfo_screenheight()
|
||||
x = max(0, (sw - w) // 2)
|
||||
y = max(0, int(sh * 0.06))
|
||||
win.geometry(f"{w}x{h}+{x}+{y}")
|
||||
except Exception:
|
||||
win.geometry(f"{w}x{h}")
|
||||
def _center_top(win, w: int, h: int, *, parent=None) -> None:
|
||||
from aza_ui_helpers import center_tool_window
|
||||
center_tool_window(win, w, h, parent=parent, y_ratio=0.06)
|
||||
|
||||
|
||||
def _bring_to_front(win) -> None:
|
||||
"""Kurz topmost, dann wieder normal — wie bestehende AzA-Tools."""
|
||||
try:
|
||||
win.lift()
|
||||
win.attributes("-topmost", True)
|
||||
win.after(300, lambda: _safe_untopmost(win))
|
||||
win.focus_force()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _safe_untopmost(win) -> None:
|
||||
try:
|
||||
if win.winfo_exists():
|
||||
win.attributes("-topmost", False)
|
||||
except Exception:
|
||||
pass
|
||||
from aza_ui_helpers import bring_tool_window_to_front
|
||||
bring_tool_window_to_front(win)
|
||||
|
||||
|
||||
def open_bibliothek_window(app: Any) -> None:
|
||||
@@ -120,16 +103,29 @@ def open_bibliothek_window(app: Any) -> None:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _sync_public_library_bg():
|
||||
import threading
|
||||
|
||||
def _worker():
|
||||
try:
|
||||
from aza_bibliothek import sync_public_library_from_server
|
||||
sync_public_library_from_server(app)
|
||||
try:
|
||||
if win.winfo_exists() and state.get("scope") == "public":
|
||||
app.after(0, _refresh_list)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
threading.Thread(target=_worker, daemon=True).start()
|
||||
|
||||
win = tk.Toplevel(app)
|
||||
app._bibliothek_win = win
|
||||
win.title("Bibliothek")
|
||||
win.configure(bg=_BG)
|
||||
win.minsize(_WIN_MIN_W, _WIN_MIN_H)
|
||||
_center_top(win, _WIN_W, _WIN_H)
|
||||
try:
|
||||
win.transient(app)
|
||||
except Exception:
|
||||
pass
|
||||
_center_top(win, _WIN_W, _WIN_H, parent=app)
|
||||
|
||||
state = {"scope": "private", "category": "medication", "selected": None}
|
||||
|
||||
@@ -355,7 +351,7 @@ def open_bibliothek_window(app: Any) -> None:
|
||||
f = detail_vars["falsch"].get().strip()
|
||||
r = detail_vars["richtig"].get().strip()
|
||||
if not f or not r:
|
||||
messagebox.showinfo("Bibliothek", "Bitte Hörvariante und bevorzugte Schreibweise ausfüllen.", parent=win)
|
||||
aza_showinfo("Bibliothek", "Bitte Hörvariante und bevorzugte Schreibweise ausfüllen.", parent=win)
|
||||
return
|
||||
save_private_correction(_store_for_state(), f, r, active=True)
|
||||
_refresh_list()
|
||||
@@ -375,7 +371,7 @@ def open_bibliothek_window(app: Any) -> None:
|
||||
row = state.get("selected")
|
||||
if not row:
|
||||
return
|
||||
if not messagebox.askyesno("Löschen?", "Eintrag wirklich löschen?", parent=win):
|
||||
if not aza_askyesno("Löschen?", "Eintrag wirklich löschen?", parent=win):
|
||||
return
|
||||
delete_private_correction(row.get("store_category") or "begriffe", row.get("term") or "")
|
||||
_refresh_list()
|
||||
@@ -383,15 +379,15 @@ def open_bibliothek_window(app: Any) -> None:
|
||||
def _adopt_public():
|
||||
row = state.get("selected")
|
||||
if not row:
|
||||
messagebox.showinfo("Bibliothek", "Bitte zuerst einen öffentlichen Eintrag auswählen.", parent=win)
|
||||
aza_showinfo("Bibliothek", "Bitte zuerst einen öffentlichen Eintrag auswählen.", parent=win)
|
||||
return
|
||||
ok, msg = adopt_public_entry(row)
|
||||
messagebox.showinfo("Bibliothek", msg, parent=win)
|
||||
aza_showinfo("Bibliothek", msg, parent=win)
|
||||
|
||||
def _details_public():
|
||||
row = state.get("selected")
|
||||
if not row:
|
||||
messagebox.showinfo("Bibliothek", "Bitte zuerst einen Eintrag auswählen.", parent=win)
|
||||
aza_showinfo("Bibliothek", "Bitte zuerst einen Eintrag auswählen.", parent=win)
|
||||
return
|
||||
lines = []
|
||||
if row.get("brand_name"):
|
||||
@@ -406,7 +402,7 @@ def open_bibliothek_window(app: Any) -> None:
|
||||
lines.append(f"Region: {row['market_region']}")
|
||||
if row.get("source"):
|
||||
lines.append(f"Herkunft: {row['source']}")
|
||||
messagebox.showinfo("Details", "\n".join(lines) or "Keine Details.", parent=win)
|
||||
aza_showinfo("Details", "\n".join(lines) or "Keine Details.", parent=win)
|
||||
|
||||
def _rebuild_buttons():
|
||||
for w in btn_row.winfo_children():
|
||||
@@ -460,4 +456,5 @@ def open_bibliothek_window(app: Any) -> None:
|
||||
|
||||
_rebuild_category_pills()
|
||||
_refresh_list()
|
||||
_sync_public_library_bg()
|
||||
_bring_to_front(win)
|
||||
|
||||
Reference in New Issue
Block a user