296 Zeilen
9.4 KiB
Python
296 Zeilen
9.4 KiB
Python
"""
|
|
Export-Dialog für Account-Profile
|
|
|
|
Ermöglicht Auswahl von Export-Formaten.
|
|
"""
|
|
|
|
import logging
|
|
from PyQt5.QtWidgets import (
|
|
QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton,
|
|
QCheckBox, QFrame, QGraphicsDropShadowEffect, QGroupBox
|
|
)
|
|
from PyQt5.QtCore import Qt, pyqtSignal
|
|
from PyQt5.QtGui import QFont, QColor
|
|
|
|
logger = logging.getLogger("profile_export_dialog")
|
|
|
|
|
|
class ProfileExportDialog(QDialog):
|
|
"""Dialog zur Auswahl von Export-Optionen"""
|
|
|
|
# Signal wird emittiert wenn Export bestätigt wird
|
|
# Parameter: (formats: List[str], password_protect: bool)
|
|
export_confirmed = pyqtSignal(list, bool)
|
|
|
|
def __init__(self, parent=None, account_username: str = ""):
|
|
"""
|
|
Initialisiert den Export-Dialog.
|
|
|
|
Args:
|
|
parent: Parent-Widget
|
|
account_username: Username des zu exportierenden Accounts
|
|
"""
|
|
super().__init__(parent)
|
|
self.account_username = account_username
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
"""Initialisiert die UI"""
|
|
|
|
# Dialog-Eigenschaften
|
|
self.setWindowTitle("Profil exportieren")
|
|
self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint)
|
|
self.setAttribute(Qt.WA_TranslucentBackground, True)
|
|
self.setModal(True)
|
|
self.setFixedSize(450, 600)
|
|
|
|
# Hauptlayout
|
|
main_layout = QVBoxLayout(self)
|
|
main_layout.setContentsMargins(20, 20, 20, 20)
|
|
|
|
# Container mit modernem Design
|
|
self.container = QFrame()
|
|
self.container.setObjectName("exportDialogContainer")
|
|
self.container.setStyleSheet("""
|
|
#exportDialogContainer {
|
|
background-color: white;
|
|
border-radius: 12px;
|
|
border: 1px solid #E5E7EB;
|
|
}
|
|
""")
|
|
|
|
# Schatten-Effekt
|
|
shadow = QGraphicsDropShadowEffect()
|
|
shadow.setBlurRadius(30)
|
|
shadow.setXOffset(0)
|
|
shadow.setYOffset(10)
|
|
shadow.setColor(QColor(0, 0, 0, 80))
|
|
self.container.setGraphicsEffect(shadow)
|
|
|
|
# Container-Layout
|
|
container_layout = QVBoxLayout(self.container)
|
|
container_layout.setSpacing(20)
|
|
container_layout.setContentsMargins(30, 25, 30, 25)
|
|
|
|
# Titel
|
|
title_label = QLabel("Profil exportieren")
|
|
title_font = QFont("Poppins", 16)
|
|
title_font.setWeight(QFont.DemiBold)
|
|
title_label.setFont(title_font)
|
|
title_label.setStyleSheet("color: #1F2937;")
|
|
container_layout.addWidget(title_label)
|
|
|
|
# Account-Info
|
|
if self.account_username:
|
|
account_label = QLabel(f"Account: {self.account_username}")
|
|
account_label.setStyleSheet("color: #6B7280; font-size: 13px; font-family: 'Poppins', sans-serif;")
|
|
container_layout.addWidget(account_label)
|
|
|
|
# Abstand vor Format-GroupBox
|
|
container_layout.addSpacing(15)
|
|
|
|
# Format-Auswahl GroupBox
|
|
format_group = QGroupBox("Format")
|
|
format_group.setMinimumHeight(150) # Mehr Platz für 3 Checkboxen
|
|
format_group.setStyleSheet("""
|
|
QGroupBox {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
font-family: 'Poppins', sans-serif;
|
|
color: #374151;
|
|
border: 1px solid #E5E7EB;
|
|
border-radius: 8px;
|
|
margin-top: 20px;
|
|
padding-top: 30px;
|
|
}
|
|
QGroupBox::title {
|
|
subcontrol-origin: margin;
|
|
subcontrol-position: top left;
|
|
left: 12px;
|
|
top: 2px;
|
|
padding: 2px 8px 2px 8px;
|
|
background-color: white;
|
|
}
|
|
""")
|
|
format_layout = QVBoxLayout(format_group)
|
|
format_layout.setSpacing(12)
|
|
format_layout.setContentsMargins(20, 25, 20, 20)
|
|
|
|
# Format-Checkboxen
|
|
self.csv_checkbox = QCheckBox("CSV")
|
|
self.csv_checkbox.setChecked(False) # Standard: nicht aktiviert
|
|
self.csv_checkbox.setStyleSheet("""
|
|
QCheckBox {
|
|
font-size: 13px;
|
|
font-family: 'Poppins', sans-serif;
|
|
color: #374151;
|
|
spacing: 8px;
|
|
}
|
|
QCheckBox::indicator {
|
|
width: 18px;
|
|
height: 18px;
|
|
border-radius: 4px;
|
|
border: 2px solid #D1D5DB;
|
|
}
|
|
QCheckBox::indicator:checked {
|
|
background-color: #0099CC;
|
|
border-color: #0099CC;
|
|
}
|
|
""")
|
|
|
|
self.json_checkbox = QCheckBox("JSON")
|
|
self.json_checkbox.setChecked(False) # Standard: nicht aktiviert
|
|
self.json_checkbox.setStyleSheet(self.csv_checkbox.styleSheet())
|
|
|
|
self.pdf_checkbox = QCheckBox("PDF")
|
|
self.pdf_checkbox.setChecked(False) # Standard: nicht aktiviert
|
|
self.pdf_checkbox.setStyleSheet(self.csv_checkbox.styleSheet())
|
|
|
|
# Checkboxen zum Format-Layout hinzufügen
|
|
format_layout.addWidget(self.csv_checkbox)
|
|
format_layout.addWidget(self.json_checkbox)
|
|
format_layout.addWidget(self.pdf_checkbox)
|
|
|
|
container_layout.addWidget(format_group)
|
|
|
|
# Spacer
|
|
container_layout.addStretch()
|
|
|
|
# Button-Layout
|
|
button_layout = QHBoxLayout()
|
|
button_layout.setSpacing(10)
|
|
button_layout.addStretch()
|
|
|
|
# Abbrechen-Button
|
|
self.cancel_button = QPushButton("Abbrechen")
|
|
self.cancel_button.setMinimumHeight(38)
|
|
self.cancel_button.setMinimumWidth(100)
|
|
self.cancel_button.setCursor(Qt.PointingHandCursor)
|
|
self.cancel_button.setStyleSheet("""
|
|
QPushButton {
|
|
background-color: #F3F4F6;
|
|
color: #374151;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
font-family: 'Poppins', sans-serif;
|
|
padding: 8px 16px;
|
|
}
|
|
QPushButton:hover {
|
|
background-color: #E5E7EB;
|
|
}
|
|
QPushButton:pressed {
|
|
background-color: #D1D5DB;
|
|
}
|
|
""")
|
|
self.cancel_button.clicked.connect(self.reject)
|
|
|
|
# Exportieren-Button
|
|
self.export_button = QPushButton("Exportieren")
|
|
self.export_button.setMinimumHeight(38)
|
|
self.export_button.setMinimumWidth(120)
|
|
self.export_button.setCursor(Qt.PointingHandCursor)
|
|
self.export_button.setStyleSheet("""
|
|
QPushButton {
|
|
background-color: #0099CC;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
font-family: 'Poppins', sans-serif;
|
|
padding: 8px 16px;
|
|
}
|
|
QPushButton:hover {
|
|
background-color: #0078A3;
|
|
}
|
|
QPushButton:pressed {
|
|
background-color: #005C7A;
|
|
}
|
|
""")
|
|
self.export_button.clicked.connect(self.on_export_clicked)
|
|
|
|
button_layout.addWidget(self.cancel_button)
|
|
button_layout.addWidget(self.export_button)
|
|
|
|
container_layout.addLayout(button_layout)
|
|
|
|
# Container zum Hauptlayout hinzufügen
|
|
main_layout.addWidget(self.container)
|
|
|
|
def on_export_clicked(self):
|
|
"""Handler für Export-Button"""
|
|
|
|
# Sammle ausgewählte Formate
|
|
selected_formats = []
|
|
if self.csv_checkbox.isChecked():
|
|
selected_formats.append("csv")
|
|
if self.json_checkbox.isChecked():
|
|
selected_formats.append("json")
|
|
if self.pdf_checkbox.isChecked():
|
|
selected_formats.append("pdf")
|
|
|
|
# Validierung: Mindestens ein Format muss ausgewählt sein
|
|
if not selected_formats:
|
|
from views.widgets.modern_message_box import show_warning
|
|
show_warning(
|
|
self,
|
|
"Kein Format ausgewählt",
|
|
"Bitte wählen Sie mindestens ein Export-Format aus."
|
|
)
|
|
return
|
|
|
|
# Passwortschutz ist entfernt - immer False
|
|
password_protect = False
|
|
|
|
# Signal emittieren
|
|
self.export_confirmed.emit(selected_formats, password_protect)
|
|
|
|
# Dialog schließen
|
|
self.accept()
|
|
|
|
def get_selected_options(self):
|
|
"""
|
|
Gibt die ausgewählten Optionen zurück.
|
|
|
|
Returns:
|
|
Tuple: (formats: List[str], password_protect: bool)
|
|
"""
|
|
formats = []
|
|
if self.csv_checkbox.isChecked():
|
|
formats.append("csv")
|
|
if self.json_checkbox.isChecked():
|
|
formats.append("json")
|
|
if self.pdf_checkbox.isChecked():
|
|
formats.append("pdf")
|
|
|
|
# Passwortschutz ist entfernt - immer False
|
|
password_protect = False
|
|
|
|
return formats, password_protect
|
|
|
|
|
|
# Helper-Funktionen für einfache Verwendung
|
|
|
|
def show_export_dialog(parent, account_username: str = ""):
|
|
"""
|
|
Zeigt den Export-Dialog modal an.
|
|
|
|
Args:
|
|
parent: Parent-Widget
|
|
account_username: Username des Accounts
|
|
|
|
Returns:
|
|
Tuple: (accepted: bool, formats: List[str], password_protect: bool)
|
|
accepted ist True wenn Export bestätigt wurde
|
|
"""
|
|
dialog = ProfileExportDialog(parent, account_username)
|
|
result = dialog.exec_()
|
|
|
|
if result == QDialog.Accepted:
|
|
formats, password_protect = dialog.get_selected_options()
|
|
return True, formats, password_protect
|
|
else:
|
|
return False, [], False
|