From 0d04432d8ba854f9cdaf7452ff45adaf97019ad2 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 31 Oct 2021 19:50:33 +0100 Subject: [PATCH] add version and ok button to about dialog --- VERSION.info | 1 + aboutdialog.py | 21 +++++++++++++++++++-- vbox.py | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 VERSION.info create mode 100644 vbox.py diff --git a/VERSION.info b/VERSION.info new file mode 100644 index 0000000..9f9f47c --- /dev/null +++ b/VERSION.info @@ -0,0 +1 @@ +0.1-alpha \ No newline at end of file diff --git a/aboutdialog.py b/aboutdialog.py index 781a741..4cb17b8 100644 --- a/aboutdialog.py +++ b/aboutdialog.py @@ -5,6 +5,7 @@ from PyQt6.QtGui import QFont, QPixmap from PyQt6.QtWidgets import * from label import Label +from vbox import VBox class AboutDialog(QDialog): @@ -21,12 +22,16 @@ class AboutDialog(QDialog): heading_app_name.setAlignment(Qt.AlignmentFlag.AlignLeft) heading_app_name.setFont(QFont("default", 25)) heading_app_name.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse) + + version = QLabel(self.tr("Version: {0}".format(self._version()))) + version.setAlignment(Qt.AlignmentFlag.AlignLeft) + app_icon = QLabel() app_icon.setPixmap(QPixmap("icon7.png")) heading = QWidget(self) hbox = QHBoxLayout(heading) hbox.addWidget(app_icon) - hbox.addWidget(heading_app_name) + hbox.addWidget(VBox(heading_app_name, version)) hbox.addSpacerItem(QSpacerItem(1, 1, hPolicy=QSizePolicy.Policy.Expanding)) heading.layout = hbox @@ -38,6 +43,11 @@ class AboutDialog(QDialog): self.layout.addWidget(tabs) + buttons = QDialogButtonBox(self) + buttons.setStandardButtons(QDialogButtonBox.StandardButton.Ok) + buttons.accepted.connect(self.close) + self.layout.addWidget(buttons) + def _about(self) -> QWidget: result = QWidget() result.layout = QVBoxLayout(result) @@ -53,7 +63,14 @@ class AboutDialog(QDialog): result.layout = QVBoxLayout(result) result.layout.addWidget(Label(self.tr(textwrap.dedent(""" """)))) return result + + def _version(self): + with open('VERSION.info', "rt") as f: + line = f.readline() + version = line.strip() + return version diff --git a/vbox.py b/vbox.py new file mode 100644 index 0000000..7a733de --- /dev/null +++ b/vbox.py @@ -0,0 +1,9 @@ +from PyQt6.QtWidgets import QWidget, QVBoxLayout + + +class VBox(QWidget): + def __init__(self, *widgets: QWidget): + super(VBox, self).__init__() + self.layout = QVBoxLayout(self) + for widget in widgets: + self.layout.addWidget(widget)