Der Projekt-Baum wird beim Öffnen des Projektes gefüllt
This commit is contained in:
+10
-1
@@ -194,7 +194,16 @@ class PdfProjectSettings(BaseModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def readSettings(cls, project_dir: Path):
|
def readSettings(cls, project_dir: Path):
|
||||||
return parse_yaml_file_as(PdfProjectSettings, project_dir / "project.yaml")
|
# Explizit UTF-8 Encoding verwenden
|
||||||
|
project_yaml_path = project_dir / "project.yaml"
|
||||||
|
with open(project_yaml_path, 'r', encoding='utf-8') as f:
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
yaml_data = yaml.load(f)
|
||||||
|
return cls.model_validate(yaml_data)
|
||||||
|
# yaml_content = f.read()
|
||||||
|
|
||||||
|
# Parse mit pydantic-yaml
|
||||||
|
|
||||||
def writeSettings(self, project_dir: Path):
|
def writeSettings(self, project_dir: Path):
|
||||||
with open(project_dir / "project.yaml", "w", encoding="utf8") as f:
|
with open(project_dir / "project.yaml", "w", encoding="utf8") as f:
|
||||||
|
|||||||
+94
-2
@@ -4,13 +4,13 @@ import time
|
|||||||
|
|
||||||
from PySide6.QtCore import Qt, QSize
|
from PySide6.QtCore import Qt, QSize
|
||||||
from PySide6.QtGui import QCursor, QPixmap, QPainter, QAction
|
from PySide6.QtGui import QCursor, QPixmap, QPainter, QAction
|
||||||
from PySide6.QtWidgets import QLabel, QMainWindow, QApplication, QStyleFactory, QMenu
|
from PySide6.QtWidgets import QLabel, QMainWindow, QApplication, QStyleFactory, QMenu, QTreeWidgetItem
|
||||||
from PySide6.QtPdf import QPdfDocument
|
from PySide6.QtPdf import QPdfDocument
|
||||||
|
|
||||||
from ui.MainWinddow_ui import Ui_MainWindow
|
from ui.MainWinddow_ui import Ui_MainWindow
|
||||||
from ui.AppSettings import AppSettingsDlg
|
from ui.AppSettings import AppSettingsDlg
|
||||||
from ui.PdfProject import PdfProjectDlg
|
from ui.PdfProject import PdfProjectDlg
|
||||||
from conf import app_settings, PdfProject, PdfProjectSettings
|
from conf import app_settings, PdfProject, PdfProjectSettings, TreeNode, XslFile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
@@ -156,12 +156,17 @@ class MainWindow(QMainWindow):
|
|||||||
self.pdf_project.writeSettings(project_dir=project.project_dir)
|
self.pdf_project.writeSettings(project_dir=project.project_dir)
|
||||||
print(f"Standard-Projekt-Einstellungen in {project_yaml_path} gespeichert")
|
print(f"Standard-Projekt-Einstellungen in {project_yaml_path} gespeichert")
|
||||||
|
|
||||||
|
# Lade die Nodes in das TreeWidget
|
||||||
|
self._load_nodes_to_tree()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Fehler beim Laden des Projekts '{project.name}': {e}")
|
print(f"Fehler beim Laden des Projekts '{project.name}': {e}")
|
||||||
# Fallback: Erstelle Standard-Einstellungen
|
# Fallback: Erstelle Standard-Einstellungen
|
||||||
try:
|
try:
|
||||||
self.pdf_project = PdfProjectSettings()
|
self.pdf_project = PdfProjectSettings()
|
||||||
print("Fallback: Standard-Projekt-Einstellungen erstellt")
|
print("Fallback: Standard-Projekt-Einstellungen erstellt")
|
||||||
|
# Auch bei Fallback die Nodes laden
|
||||||
|
self._load_nodes_to_tree()
|
||||||
except Exception as fallback_error:
|
except Exception as fallback_error:
|
||||||
print(f"Fehler beim Erstellen der Fallback-Einstellungen: {fallback_error}")
|
print(f"Fehler beim Erstellen der Fallback-Einstellungen: {fallback_error}")
|
||||||
|
|
||||||
@@ -707,6 +712,93 @@ class MainWindow(QMainWindow):
|
|||||||
self.last_drag_position = None
|
self.last_drag_position = None
|
||||||
fullsize_label.setCursor(QCursor(Qt.CursorShape.OpenHandCursor))
|
fullsize_label.setCursor(QCursor(Qt.CursorShape.OpenHandCursor))
|
||||||
|
|
||||||
|
def _load_nodes_to_tree(self):
|
||||||
|
"""
|
||||||
|
Lädt die Nodes aus den Projekt-Einstellungen in das TreeWidget.
|
||||||
|
"""
|
||||||
|
print("Lade Nodes in TreeWidget...")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# TreeWidget leeren
|
||||||
|
self.ui.treeWidget.clear()
|
||||||
|
|
||||||
|
# Prüfe ob pdf_project existiert und Nodes hat
|
||||||
|
if not hasattr(self, 'pdf_project') or not self.pdf_project:
|
||||||
|
print("Keine Projekt-Einstellungen verfügbar")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.pdf_project.nodes:
|
||||||
|
print("Keine Nodes in den Projekt-Einstellungen gefunden")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Lade alle Root-Nodes
|
||||||
|
for node in self.pdf_project.nodes:
|
||||||
|
tree_item = self._create_tree_item_from_node(node)
|
||||||
|
self.ui.treeWidget.addTopLevelItem(tree_item)
|
||||||
|
|
||||||
|
print(f"{len(self.pdf_project.nodes)} Root-Nodes in TreeWidget geladen")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fehler beim Laden der Nodes in TreeWidget: {e}")
|
||||||
|
|
||||||
|
def _create_tree_item_from_node(self, node):
|
||||||
|
"""
|
||||||
|
Erstellt ein QTreeWidgetItem aus einem TreeNode oder XslFile.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
node: TreeNode oder XslFile Objekt
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
QTreeWidgetItem: Das erstellte Tree-Item
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Erstelle Tree-Item
|
||||||
|
item = QTreeWidgetItem()
|
||||||
|
|
||||||
|
# Setze die Bezeichnung in Spalte 0 (mit expliziter UTF-8 Behandlung)
|
||||||
|
bez_text = str(node.bez) if node.bez else ""
|
||||||
|
item.setText(0, bez_text)
|
||||||
|
|
||||||
|
# Setze zusätzliche Informationen in Spalte 1
|
||||||
|
if isinstance(node, TreeNode):
|
||||||
|
# TreeNode: Zeige Anzahl der Kinder
|
||||||
|
child_count = len(node.children) if node.children else 0
|
||||||
|
item.setText(1, f"({child_count} Kinder)")
|
||||||
|
|
||||||
|
# Speichere Node-ID als Data
|
||||||
|
item.setData(0, Qt.ItemDataRole.UserRole, node.id)
|
||||||
|
|
||||||
|
# Lade Kinder rekursiv
|
||||||
|
if node.children:
|
||||||
|
for child in node.children:
|
||||||
|
child_item = self._create_tree_item_from_node(child)
|
||||||
|
item.addChild(child_item)
|
||||||
|
|
||||||
|
elif isinstance(node, XslFile):
|
||||||
|
# XslFile: Zeige XSL-Datei-Pfad
|
||||||
|
item.setText(1, str(node.xsl_file))
|
||||||
|
|
||||||
|
# Speichere XslFile-ID als Data
|
||||||
|
item.setData(0, Qt.ItemDataRole.UserRole, node.id)
|
||||||
|
|
||||||
|
# Lade XML-Dateien als Kinder
|
||||||
|
if node.xmls:
|
||||||
|
for xml in node.xmls:
|
||||||
|
xml_item = QTreeWidgetItem()
|
||||||
|
xml_item.setText(0, f"XML: {xml.xml.name}")
|
||||||
|
xml_item.setText(1, str(xml.xml))
|
||||||
|
item.addChild(xml_item)
|
||||||
|
|
||||||
|
return item
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fehler beim Erstellen des Tree-Items: {e}")
|
||||||
|
# Fallback: Erstelle einfaches Item
|
||||||
|
fallback_item = QTreeWidgetItem()
|
||||||
|
fallback_item.setText(0, "Fehler beim Laden")
|
||||||
|
fallback_item.setText(1, str(e))
|
||||||
|
return fallback_item
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
"""Wird beim Schließen der Anwendung aufgerufen."""
|
"""Wird beim Schließen der Anwendung aufgerufen."""
|
||||||
# PDF-Dokumente schließen ist bei QtPdf automatisch durch Garbage Collection
|
# PDF-Dokumente schließen ist bei QtPdf automatisch durch Garbage Collection
|
||||||
|
|||||||
Reference in New Issue
Block a user