Laden der Project.yaml aus dem Projekt-Verzeichnis

This commit is contained in:
2025-06-22 14:47:17 +02:00
parent 51e3453f92
commit b8441d1ab4
4 changed files with 72 additions and 15 deletions
+11 -1
View File
@@ -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))
+24
View File
@@ -165,6 +165,18 @@
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame_4">
<property name="frameShape">
@@ -293,6 +305,18 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
+2
View File
@@ -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")
+35 -14
View File
@@ -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}")