Der AppSettings-Dialog wird beim Start automatisch geöffnet, um fehlende Einstellungen eintragen zu können

* Es wurden weitere Dialoge für einzelne Tabellen erstellt.
This commit is contained in:
2025-06-12 20:43:31 +02:00
parent fc55436d7e
commit cb203112d6
3 changed files with 608 additions and 10 deletions
+99
View File
@@ -0,0 +1,99 @@
from os import path
from pathlib import Path
from sys import platform
from pydantic import BaseModel
from pydantic_settings import BaseSettings, SettingsConfigDict
app_name = "DocuMentor"
if platform == "win32":
config_path = f"%APPDATA%\\{app_name}\\config.json"
elif platform == "linux" or platform == "linux2":
config_path = f"~/.config/{app_name}/config.json"
elif platform == "darwin":
config_path = f"~/Library/Application Support/{app_name}/͏͏͏͏config.json"
else:
config_path = f"~/.config/{app_name}/config.json"
config_path = Path(path.expandvars(config_path))
class JavaVm(BaseModel):
id: int
version: str
path_to_binary_file: Path
class DiffPdf(BaseModel):
id: int
version: str
path_to_binary_file: Path
default_params: list[str]
output_file_extension: str = "pdf"
class SaxonJar(BaseModel):
id: int
version: str
path_to_jar_file: Path
output_file_extension: str = "fo"
class ApacheFop(BaseModel):
id: int
version: str
path_to_dir: Path
output_file_extension: str = "pdf"
class XslDir(BaseModel):
id: int
name: str
path_to_root_dir: Path
class PdfProject(BaseModel):
id: int
name: str
project_dir: Path
java_vm_id: int
diff_pdf_id: int
saxon_jar_id: int
apache_fop_id: int
xsl_dir_id: int
default_xslt_params: dict[str, str] = {}
class AppSettings(BaseSettings):
java_vms: list[JavaVm] = []
diff_pdfs: list[DiffPdf] = []
saxon_jars: list[SaxonJar] = []
apache_fops: list[ApacheFop] = []
xsl_dirs: list[XslDir] = []
pdf_projects: list[PdfProject] = []
model_config = SettingsConfigDict(json_file=config_path)
def save(self):
global config_path
if not config_path.exists():
# Datei existert nicht
if not config_path.parent.exists():
# Ordner existiert nicht
config_path.parent.mkdir()
# Konfiguration speichern
with open(config_path, "wb") as c:
c.write(app_settings.model_dump_json(indent=4).encode())
app_settings = AppSettings()
class PdfProjectSettings(BaseSettings):
"""
Speichert Projekt-Einstellungen direkt im Ordner des Projekts in einer Klartextdatei JSON
"""
pass