From 52c1fcea48c684d41e2e524edf224d59d6ea17ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 3 Dec 2024 11:42:33 -0500 Subject: [PATCH 1/2] Create about.py --- qtapputils/widgets/about.py | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 qtapputils/widgets/about.py diff --git a/qtapputils/widgets/about.py b/qtapputils/widgets/about.py new file mode 100644 index 0000000..5c25fa0 --- /dev/null +++ b/qtapputils/widgets/about.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +# ----------------------------------------------------------------------------- +# Copyright © QtAppUtils Project Contributors +# https://github.com/jnsebgosselin/apputils +# +# This file is part of QtAppUtils. +# Licensed under the terms of the MIT License. +# ----------------------------------------------------------------------------- + +"""About app dialog.""" + +# ---- Standard imports +import sys + + +# ---- Third party imports +from qtpy.QtCore import Qt +from qtpy.QtGui import QPixmap, QIcon +from qtpy.QtWidgets import ( + QApplication, QDialog, QDialogButtonBox, QGridLayout, QLabel, QFrame, + QWidget, QTextEdit, QVBoxLayout + ) + + +class AboutDialog(QDialog): + + def __init__(self, icon: QIcon, title: str, + copyright_holder: str, + longdesc: str, + appname: str, + website_url: str, + banner_fpath: str, + license_fpath: str = None, + parent: QWidget = None, + ): + """Create an About dialog with general information.""" + super().__init__(parent=parent) + self.setWindowFlags( + self.windowFlags() & ~Qt.WindowContextHelpButtonHint) + self.setWindowIcon(icon) + self.setWindowTitle(title) + + # Get current font properties + font = self.font() + font_family = font.family() + font_size = font.pointSize() + + self.label = QLabel(( + """ +
+

+
{appname}
+ Copyright © {copyright_holder}
+ {website_url} +

+

{longdesc}

+
+ """.format( + appname=appname, + website_url=website_url, + font_family=font_family, + font_size=font_size, + copyright_holder=copyright_holder, + longdesc=longdesc + ) + )) + self.label.setWordWrap(True) + self.label.setAlignment(Qt.AlignTop) + self.label.setOpenExternalLinks(True) + self.label.setTextInteractionFlags(Qt.TextBrowserInteraction) + + pixmap = QPixmap(banner_fpath) + self.label_pic = QLabel(self) + self.label_pic.setPixmap( + pixmap.scaledToWidth(450, Qt.SmoothTransformation)) + self.label_pic.setAlignment(Qt.AlignTop) + + content_frame = QFrame(self) + content_frame.setStyleSheet( + "QFrame {background-color: white}") + content_layout = QGridLayout(content_frame) + content_layout.addWidget(self.label_pic, 0, 0) + content_layout.addWidget(self.label, 1, 0) + content_layout.setContentsMargins(15, 15, 15, 15) + + if license_fpath is not None: + content_layout.setRowMinimumHeight(2, 10) + + license_title = QLabel('License Info :') + + license_textedit = QTextEdit() + license_textedit.insertPlainText(open(license_fpath).read()) + license_textedit.setTextInteractionFlags(Qt.TextBrowserInteraction) + license_textedit.moveCursor(license_textedit.textCursor().Start) + + content_layout.addWidget(license_title, 3, 0) + content_layout.addWidget(license_textedit, 4, 0) + + bbox = QDialogButtonBox(QDialogButtonBox.Ok) + bbox.accepted.connect(self.accept) + + # Setup the layout. + layout = QVBoxLayout(self) + layout.addWidget(content_frame) + layout.addWidget(bbox) + layout.setSizeConstraint(layout.SetFixedSize) + + def show(self): + """Overide Qt method.""" + super().show() + self.activateWindow() + self.raise_() + + +if __name__ == '__main__': + app = QApplication(sys.argv) + about = AboutDialog() + about.show() + sys.exit(app.exec_()) From 92688039eea426da1df4e976ab0f2c1cfa18db79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Gosselin?= Date: Tue, 3 Dec 2024 11:45:49 -0500 Subject: [PATCH 2/2] Update about.py --- qtapputils/widgets/about.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/qtapputils/widgets/about.py b/qtapputils/widgets/about.py index 5c25fa0..5a34c72 100644 --- a/qtapputils/widgets/about.py +++ b/qtapputils/widgets/about.py @@ -9,15 +9,12 @@ """About app dialog.""" -# ---- Standard imports -import sys - # ---- Third party imports from qtpy.QtCore import Qt from qtpy.QtGui import QPixmap, QIcon from qtpy.QtWidgets import ( - QApplication, QDialog, QDialogButtonBox, QGridLayout, QLabel, QFrame, + QDialog, QDialogButtonBox, QGridLayout, QLabel, QFrame, QWidget, QTextEdit, QVBoxLayout ) @@ -113,10 +110,3 @@ def show(self): super().show() self.activateWindow() self.raise_() - - -if __name__ == '__main__': - app = QApplication(sys.argv) - about = AboutDialog() - about.show() - sys.exit(app.exec_())