diff --git a/src/conf.py b/src/conf.py
index 8332d68..b484908 100644
--- a/src/conf.py
+++ b/src/conf.py
@@ -2,6 +2,8 @@ from os import path
from pathlib import Path
from sys import platform
from typing import Tuple, Type
+from pydantic_yaml import to_yaml_str, parse_yaml_file_as
+import polars as pl
from pydantic import BaseModel
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict, JsonConfigSettingsSource
@@ -152,10 +154,18 @@ class TreeNode(BaseModel):
class PdfProjectSettings(BaseModel):
"""
- Speichert Projekt-Einstellungen direkt im Ordner des Projekts in einer Klartextdatei JSON
+ Speichert Projekt-Einstellungen direkt im Ordner des Projekts in einer Klartextdatei YAML
"""
nodes: list[TreeNode] = []
+ @classmethod
+ def readSettings(cls, project_dir: Path):
+ return parse_yaml_file_as(PdfProjectSettings, project_dir / "project.yaml")
+
+ def writeSettings(self, project_dir: Path):
+ with open(project_dir / "project.yaml", "w", encoding="utf8") as f:
+ f.write(to_yaml_str(self))
+
diff --git a/src/ui/MainWinddow.ui b/src/ui/MainWinddow.ui
index 83f41fb..c426ce9 100644
--- a/src/ui/MainWinddow.ui
+++ b/src/ui/MainWinddow.ui
@@ -165,6 +165,18 @@
QFrame::Shadow::Raised
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
-
@@ -293,6 +305,18 @@
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
-
diff --git a/src/ui/MainWinddow_ui.py b/src/ui/MainWinddow_ui.py
index 71b8dbe..d86919e 100644
--- a/src/ui/MainWinddow_ui.py
+++ b/src/ui/MainWinddow_ui.py
@@ -144,6 +144,7 @@ class Ui_MainWindow(object):
self.frame_3.setFrameShadow(QFrame.Shadow.Raised)
self.verticalLayout_4 = QVBoxLayout(self.frame_3)
self.verticalLayout_4.setObjectName(u"verticalLayout_4")
+ self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
self.frame_4 = QFrame(self.frame_3)
self.frame_4.setObjectName(u"frame_4")
self.frame_4.setFrameShape(QFrame.Shape.StyledPanel)
@@ -206,6 +207,7 @@ class Ui_MainWindow(object):
self.scrollAreaWidgetContents_2.setGeometry(QRect(0, 0, 794, 801))
self.verticalLayout_3 = QVBoxLayout(self.scrollAreaWidgetContents_2)
self.verticalLayout_3.setObjectName(u"verticalLayout_3")
+ self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.label_3 = QLabel(self.scrollAreaWidgetContents_2)
self.label_3.setObjectName(u"label_3")
diff --git a/src/ui/MainWindow.py b/src/ui/MainWindow.py
index f964155..97ac741 100644
--- a/src/ui/MainWindow.py
+++ b/src/ui/MainWindow.py
@@ -10,7 +10,7 @@ from PySide6.QtPdf import QPdfDocument
from ui.MainWinddow_ui import Ui_MainWindow
from ui.AppSettings import AppSettingsDlg
from ui.PdfProject import PdfProjectDlg
-from conf import app_settings, PdfProject
+from conf import app_settings, PdfProject, PdfProjectSettings
from pathlib import Path
@@ -139,15 +139,31 @@ class MainWindow(QMainWindow):
print(f"Öffne Projekt: {project.name}")
print(f"Projekt-Ordner: {project.project_dir}")
- # Hier könnte die Logik zum Laden des Projekts implementiert werden
- # Zum Beispiel:
- # - PDF-Dateien aus dem Projekt-Ordner laden
- # - Projekt-spezifische Einstellungen anwenden
- # - UI entsprechend aktualisieren
-
- # Für jetzt nur eine Meldung ausgeben
- print(f"Projekt '{project.name}' wurde ausgewählt")
- # TODO: Implementiere Projekt-Lade-Logik
+ try:
+ # Prüfe ob project.yaml existiert und nicht leer ist
+ project_yaml_path = Path(project.project_dir) / 'project.yaml'
+
+ if project_yaml_path.exists() and project_yaml_path.stat().st_size > 0:
+ # Versuche die Projekt-Einstellungen zu laden
+ self.pdf_project = PdfProjectSettings.readSettings(project_dir=project.project_dir)
+ print(f"Projekt-Einstellungen aus {project_yaml_path} geladen!")
+ else:
+ # Erstelle Standard-Projekt-Einstellungen wenn Datei leer oder nicht vorhanden
+ print("project.yaml ist leer oder nicht vorhanden, erstelle Standard-Einstellungen")
+ self.pdf_project = PdfProjectSettings()
+
+ # Speichere die Standard-Einstellungen in die project.yaml
+ self.pdf_project.writeSettings(project_dir=project.project_dir)
+ print(f"Standard-Projekt-Einstellungen in {project_yaml_path} gespeichert")
+
+ except Exception as e:
+ print(f"Fehler beim Laden des Projekts '{project.name}': {e}")
+ # Fallback: Erstelle Standard-Einstellungen
+ try:
+ self.pdf_project = PdfProjectSettings()
+ print("Fallback: Standard-Projekt-Einstellungen erstellt")
+ except Exception as fallback_error:
+ print(f"Fehler beim Erstellen der Fallback-Einstellungen: {fallback_error}")
def change_theme(self, theme_name):
"""
@@ -605,11 +621,16 @@ class MainWindow(QMainWindow):
project_yaml_path = project_dir / 'project.yaml'
- # Projekt-Datei erstellen, wenn nicht vorhanden
+ # Erstelle Standard-Projekt-Einstellungen und speichere sie
if not project_yaml_path.exists():
- project_yaml_path.touch()
-
- print(f"project.yaml erstellt: {project_yaml_path}")
+ # Erstelle Standard-PdfProjectSettings
+ default_settings = PdfProjectSettings()
+
+ # Speichere die Standard-Einstellungen in die project.yaml
+ default_settings.writeSettings(project_dir=project_dir)
+ print(f"project.yaml mit Standard-Einstellungen erstellt: {project_yaml_path}")
+ else:
+ print(f"project.yaml existiert bereits: {project_yaml_path}")
except Exception as e:
print(f"Fehler beim Erstellen der Projekt-Struktur: {e}")