Konfiguration wird geladen und gespeichert.
This commit is contained in:
+24
-13
@@ -1,16 +1,17 @@
|
|||||||
from os import path
|
from os import path
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from sys import platform
|
from sys import platform
|
||||||
|
from typing import Tuple, Type
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict, JsonConfigSettingsSource
|
||||||
|
|
||||||
app_name = "DocuMentor"
|
app_name = "DocuMentor"
|
||||||
|
|
||||||
|
|
||||||
if platform == "win32":
|
if platform == "win32":
|
||||||
config_path = f"%APPDATA%\\{app_name}\\config.json"
|
config_path = f"%APPDATA%\\{app_name}\\config.json"
|
||||||
elif platform == "linux" or platform == "linux2":
|
elif platform in ("linux", "linux2"):
|
||||||
config_path = f"~/.config/{app_name}/config.json"
|
config_path = f"~/.config/{app_name}/config.json"
|
||||||
elif platform == "darwin":
|
elif platform == "darwin":
|
||||||
config_path = f"~/Library/Application Support/{app_name}/͏͏͏͏config.json"
|
config_path = f"~/Library/Application Support/{app_name}/͏͏͏͏config.json"
|
||||||
@@ -75,21 +76,31 @@ class AppSettings(BaseSettings):
|
|||||||
pdf_projects: list[PdfProject] = []
|
pdf_projects: list[PdfProject] = []
|
||||||
|
|
||||||
model_config = SettingsConfigDict(json_file=config_path)
|
model_config = SettingsConfigDict(json_file=config_path)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def settings_customise_sources(
|
||||||
|
cls,
|
||||||
|
settings_cls: Type[BaseSettings],
|
||||||
|
init_settings: PydanticBaseSettingsSource,
|
||||||
|
env_settings: PydanticBaseSettingsSource,
|
||||||
|
dotenv_settings: PydanticBaseSettingsSource,
|
||||||
|
file_secret_settings: PydanticBaseSettingsSource,
|
||||||
|
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
||||||
|
return (JsonConfigSettingsSource(settings_cls),)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
global config_path
|
global config_path
|
||||||
if not config_path.exists():
|
if not config_path.parent.exists():
|
||||||
# Datei existert nicht
|
# Ordner existert nicht
|
||||||
if not config_path.parent.exists():
|
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
# Ordner existiert nicht
|
|
||||||
config_path.parent.mkdir()
|
# Konfiguration speichern
|
||||||
|
with open(config_path, "wb") as c:
|
||||||
# Konfiguration speichern
|
c.write(app_settings.model_dump_json(indent=4).encode())
|
||||||
with open(config_path, "wb") as c:
|
|
||||||
c.write(app_settings.model_dump_json(indent=4).encode())
|
|
||||||
|
|
||||||
app_settings = AppSettings()
|
app_settings = AppSettings()
|
||||||
|
print(app_settings)
|
||||||
|
|
||||||
class PdfProjectSettings(BaseSettings):
|
class PdfProjectSettings(BaseSettings):
|
||||||
"""
|
"""
|
||||||
|
|||||||
+9
-4
@@ -6,14 +6,14 @@ from ui.MainWindow import MainWindow
|
|||||||
from ui.AppSettings import AppSettingsDlg
|
from ui.AppSettings import AppSettingsDlg
|
||||||
from conf import app_settings
|
from conf import app_settings
|
||||||
|
|
||||||
#import qdarktheme
|
# import qdarktheme
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Haupteinstiegspunkt der Anwendung."""
|
"""Haupteinstiegspunkt der Anwendung."""
|
||||||
# QApplication-Instanz erstellen
|
# QApplication-Instanz erstellen
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
# Dark Theme aktivieren
|
# Dark Theme aktivieren
|
||||||
# qdarktheme.setup_theme("auto")
|
# qdarktheme.setup_theme("auto")
|
||||||
|
|
||||||
@@ -22,8 +22,13 @@ def main():
|
|||||||
|
|
||||||
# Hauptfenster anzeigen
|
# Hauptfenster anzeigen
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
if len(app_settings.apache_fops) == 0 or len(app_settings.diff_pdfs) == 0 or len(app_settings.java_vms) == 0 or len(app_settings.saxon_jars):
|
if (
|
||||||
|
len(app_settings.apache_fops) == 0
|
||||||
|
or len(app_settings.diff_pdfs) == 0
|
||||||
|
or len(app_settings.java_vms) == 0
|
||||||
|
or len(app_settings.saxon_jars) == 0
|
||||||
|
):
|
||||||
# Als Modal Dialog öffnen!
|
# Als Modal Dialog öffnen!
|
||||||
dlg = AppSettingsDlg(window, app_settings)
|
dlg = AppSettingsDlg(window, app_settings)
|
||||||
dlg.exec()
|
dlg.exec()
|
||||||
|
|||||||
@@ -582,6 +582,8 @@ class AppSettingsDlg(QDialog):
|
|||||||
self.settings.apache_fops = self.temp_apache_fops.copy()
|
self.settings.apache_fops = self.temp_apache_fops.copy()
|
||||||
self.settings.xsl_dirs = self.temp_xsl_dirs.copy()
|
self.settings.xsl_dirs = self.temp_xsl_dirs.copy()
|
||||||
|
|
||||||
|
self.settings.save()
|
||||||
|
|
||||||
super().accept()
|
super().accept()
|
||||||
|
|
||||||
def get_settings(self) -> AppSettings:
|
def get_settings(self) -> AppSettings:
|
||||||
|
|||||||
Reference in New Issue
Block a user