Konfiguration wird geladen und gespeichert.
This commit is contained in:
+18
-7
@@ -1,16 +1,17 @@
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
from sys import platform
|
||||
from typing import Tuple, Type
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict, JsonConfigSettingsSource
|
||||
|
||||
app_name = "DocuMentor"
|
||||
|
||||
|
||||
if platform == "win32":
|
||||
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"
|
||||
elif platform == "darwin":
|
||||
config_path = f"~/Library/Application Support/{app_name}/͏͏͏͏config.json"
|
||||
@@ -76,20 +77,30 @@ class AppSettings(BaseSettings):
|
||||
|
||||
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):
|
||||
global config_path
|
||||
if not config_path.exists():
|
||||
# Datei existert nicht
|
||||
if not config_path.parent.exists():
|
||||
# Ordner existiert nicht
|
||||
config_path.parent.mkdir()
|
||||
# Ordner existert nicht
|
||||
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Konfiguration speichern
|
||||
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):
|
||||
"""
|
||||
|
||||
+7
-2
@@ -6,7 +6,7 @@ from ui.MainWindow import MainWindow
|
||||
from ui.AppSettings import AppSettingsDlg
|
||||
from conf import app_settings
|
||||
|
||||
#import qdarktheme
|
||||
# import qdarktheme
|
||||
|
||||
|
||||
def main():
|
||||
@@ -23,7 +23,12 @@ def main():
|
||||
# Hauptfenster anzeigen
|
||||
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!
|
||||
dlg = AppSettingsDlg(window, app_settings)
|
||||
dlg.exec()
|
||||
|
||||
@@ -582,6 +582,8 @@ class AppSettingsDlg(QDialog):
|
||||
self.settings.apache_fops = self.temp_apache_fops.copy()
|
||||
self.settings.xsl_dirs = self.temp_xsl_dirs.copy()
|
||||
|
||||
self.settings.save()
|
||||
|
||||
super().accept()
|
||||
|
||||
def get_settings(self) -> AppSettings:
|
||||
|
||||
Reference in New Issue
Block a user