54 lines
2.0 KiB
Python

from PyQt6.QtWidgets import QTextBrowser, QWidget, QLabel, QVBoxLayout
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QDesktopServices, QPixmap
from ...resources import get_resource_path
import logging
log = logging.getLogger(__name__)
class MarkdownView(QTextBrowser):
def __init__(self, parent=None):
super().__init__(parent)
self.setReadOnly(True)
# open links with the OS web browser
self.anchorClicked.connect(QDesktopServices.openUrl)
# dont follow links
self.setOpenLinks(False)
class About(QWidget):
"""
Small about text with logo
"""
def __init__(self, parent=None):
super().__init__(parent)
self.setLayout(QVBoxLayout())
# show the logo via a pixmap in a label
img_path = get_resource_path("icons/logo.svg")
pixmap = QPixmap(img_path)
pixmap = pixmap.scaled(128, 128, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
# qt cant find the file
w_label = QLabel()
w_label.setPixmap(pixmap)
w_label.setAlignment(Qt.AlignmentFlag.AlignCenter) # center the image
self.layout().addWidget(w_label)
# show about.md
w_md_view = MarkdownView()
filepath = get_resource_path("small_about.md")
try:
with open(filepath, "r") as file:
content = file.read()
try:
from importlib.metadata import version
cpdversion = version('cpdctrl_gui')
content += f"\n- Version: {cpdversion}"
except Exception as e:
log.info(f"Failed to get cpdctrl_gui version: {e}")
# content += f"\n- Version: Unknown"
w_md_view.setMarkdown(content)
except FileNotFoundError:
log.error(f"File not found: {filepath}")
w_md_view.setMarkdown(f"## File not found\n`{filepath}`")
self.layout().addWidget(w_md_view)