35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import json
|
|
import os
|
|
from nicegui import ui
|
|
|
|
# 1. Pfad zur JSON Datei berechnen
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
JSON_PATH = os.path.join(BASE_DIR, "info_texts.json")
|
|
|
|
# 2. JSON Datei in den Speicher laden
|
|
def load_info_texts():
|
|
if os.path.exists(JSON_PATH):
|
|
# encoding="utf-8" ist wichtig für deutsche Umlaute (ä, ö, ü)!
|
|
with open(JSON_PATH, "r", encoding="utf-8") as file:
|
|
return json.load(file)
|
|
else:
|
|
print("FEHLER! Keine info_texts.json gefunden!")
|
|
return {}
|
|
|
|
# Wir laden das Wörterbuch genau 1x beim Serverstart
|
|
TEXT_DICTIONARY = load_info_texts()
|
|
|
|
# 3. Unser neuer Baustein für die Webseite
|
|
def create_info_button(topic_key):
|
|
# Den Text aus dem Wörterbuch holen. Falls nicht vorhanden wird eine Fehlermeldung geworfen.
|
|
texts = TEXT_DICTIONARY.get(topic_key, ["Hilfetext nicht gefunden!"])
|
|
|
|
# --- DER DIALOG (Unsichtbar im Hintergrund) ---
|
|
with ui.dialog().classes("w-full items-center") as info_dialog, ui.card().classes("items-center text-textnormal"):
|
|
# Loopen durch die Sätze in der JSON
|
|
for sentence in texts:
|
|
ui.markdown(sentence).classes("font-bold text-white text-lg text-center")
|
|
|
|
# --- DER BUTTON (Sichtbar auf der Seite) ---
|
|
ui.button(icon="info_outline", color= "", on_click=info_dialog.open).props('round dense')
|