Source code for cosedaUI.about_window

"""About dialog for COSEDA."""

from importlib import resources
from pathlib import Path

from PyQt6.QtWidgets import QDialog, QLabel, QTextEdit, QPushButton, QVBoxLayout, QHBoxLayout, QGroupBox, QWidget
from PyQt6.QtCore import Qt


def _load_license_text():
    """Return the bundled license text, falling back to the source checkout."""
    resource_error = None
    try:
        license_resource = resources.files("cosedaUI").joinpath("resources", "LICENSE")
        if license_resource.is_file():
            return license_resource.read_text(encoding="utf-8")
    except Exception as exc:
        resource_error = exc

    for license_path in (
        Path(__file__).resolve().parent / "resources" / "LICENSE",
        Path(__file__).resolve().parents[2] / "LICENSE",
    ):
        try:
            if license_path.is_file():
                return license_path.read_text(encoding="utf-8")
        except OSError:
            continue

    if resource_error is not None:
        return f"Error loading LICENSE file: {resource_error}"
    return "Error loading LICENSE file: bundled license resource was not found."


[docs] class AboutWindow(QDialog): """Modal dialog that shows product name, authors, license text, and changelog.""" def __init__(self, window_title, changelog, parent=None): """Create the dialog and build its UI.""" super().__init__(parent) self.window_title = window_title self.changelog = changelog self.init_ui()
[docs] def init_ui(self): """Assemble the dialog layout and populate static text and license contents.""" # Set dialog title self.setWindowTitle("About COSEDA") # Use a vertical layout main_layout = QVBoxLayout(self) # Header with project title title_label = QLabel( "COSEDA - Continuous Serial Electron Diffraction Data Analysis", self ) title_label.setAlignment(Qt.AlignmentFlag.AlignCenter) main_layout.addWidget(title_label) # Contributors list under header contrib_label = QLabel( "Paul Hager, Gerhard Hofer, Lei Wang, Laura Pacoste, " "Buster Blomberg, Angelina Vypritskaia, Alexis Fonjallaz", self ) contrib_label.setAlignment(Qt.AlignmentFlag.AlignCenter) main_layout.addWidget(contrib_label) # Affiliation aff_label = QLabel("Stockholm University 2026", self) aff_label.setAlignment(Qt.AlignmentFlag.AlignCenter) main_layout.addWidget(aff_label) # Copyright notice copy_label = QLabel("© 2026 Paul Hager", self) copy_label.setAlignment(Qt.AlignmentFlag.AlignCenter) main_layout.addWidget(copy_label) # License box license_box = QGroupBox("License", self) box_layout = QVBoxLayout(license_box) license_edit = QTextEdit(self) license_edit.setReadOnly(True) license_edit.setPlainText(_load_license_text()) box_layout.addWidget(license_edit) main_layout.addWidget(license_box) # Close button at bottom close_btn = QPushButton("Close", self) close_btn.clicked.connect(self.close) # Center the button btn_container = QWidget(self) btn_layout = QHBoxLayout(btn_container) btn_layout.addStretch() btn_layout.addWidget(close_btn) btn_layout.addStretch() main_layout.addWidget(btn_container) # Adjust size to fit self.adjustSize()
[docs] def open_about_window(window_title, changelog, theme, parent=None): """Instantiate and display the modal About dialog.""" about_window = AboutWindow(window_title, changelog, parent) about_window.exec() # Executes the dialog modally