From 43d7b9a620070e2871ffd5a5fc7f4a2008ba9421 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 12 Mar 2021 13:42:22 +0100 Subject: [PATCH] [help] store size settings, flake8 --- blipblop/main.py | 2 -- blipblop/ui/help.py | 45 ++++++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/blipblop/main.py b/blipblop/main.py index 183aa1c..6929a56 100644 --- a/blipblop/main.py +++ b/blipblop/main.py @@ -14,7 +14,6 @@ except ImportError: pass def main(): - print("executing main.main") app = QApplication(sys.argv) app.setApplicationName(cnst.application_name) app.setApplicationVersion(str(cnst.application_version)) @@ -33,7 +32,6 @@ def main(): window.show() code = app.exec_() - print("Application exit!") pos = window.pos() settings.setValue("app/width", window.width()) settings.setValue("app/height", window.height()) diff --git a/blipblop/ui/help.py b/blipblop/ui/help.py index 362799d..de95caf 100644 --- a/blipblop/ui/help.py +++ b/blipblop/ui/help.py @@ -1,30 +1,39 @@ from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QFrame, QHBoxLayout, QPushButton, QSizePolicy, QTextBrowser, QVBoxLayout, QWidget -from PyQt5.QtCore import QUrl +from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QFrame, QHBoxLayout +from PyQt5.QtWidgets import QPushButton, QSizePolicy, QTextBrowser, QVBoxLayout, QWidget +from PyQt5.QtCore import QSettings, QUrl import blipblop.constants as cnst + class HelpDialog(QDialog): - - def __init__(self, parent = None) -> None: + + def __init__(self, parent=None) -> None: super().__init__(parent=parent) - - self.setModal(True) - self.setMinimumSize(500, 750) + self._settings = QSettings() + width = int(self._settings.value("help/width", 640)) + height = int(self._settings.value("help/height", 480)) + x = int(self._settings.value("help/pos_x", 100)) + y = int(self._settings.value("help/pos_y", 100)) + self.setModal(True) + self.setMinimumSize(640, 480) + self.resize(width, height) + self.move(x, y) + self.finished.connect(self.on_finished) self.help = HelpBrowser() self.help._edit.historyChanged.connect(self._on_history_changed) - + self.back_btn = QPushButton(QIcon(":/icons/docs_back"), "back") self.back_btn.setEnabled(False) self.back_btn.clicked.connect(self.help._edit.backward) - self.home_btn = QPushButton(QIcon(":/icons/docs_home"),"home") + self.home_btn = QPushButton(QIcon(":/icons/docs_home"), "home") self.home_btn.clicked.connect(self.help._edit.home) - self.fwd_btn = QPushButton(QIcon(":/icons/docs_fwd"),"forward") + self.fwd_btn = QPushButton(QIcon(":/icons/docs_fwd"), "forward") self.fwd_btn.setEnabled(False) self.fwd_btn.clicked.connect(self.help._edit.forward) - + empty = QWidget() empty.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) @@ -32,8 +41,8 @@ class HelpDialog(QDialog): hbox.addWidget(self.back_btn) hbox.addWidget(self.home_btn) hbox.addWidget(self.fwd_btn) - hbox.addWidget(empty) - + hbox.addWidget(empty) + bbox = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok) bbox.accepted.connect(self.accept) layout = QVBoxLayout() @@ -42,17 +51,23 @@ class HelpDialog(QDialog): layout.addWidget(self.help) layout.addWidget(bbox) self.setLayout(layout) - + def _on_history_changed(self): self.back_btn.setEnabled(self.help._edit.isBackwardAvailable()) self.fwd_btn.setEnabled(self.help._edit.isForwardAvailable()) + def on_finished(self): + self._settings.setValue("help/width", self.width()) + self._settings.setValue("help/height", self.height()) + self._settings.setValue("help/pos_x", self.x()) + self._settings.setValue("help/pos_y", self.y()) + class HelpBrowser(QWidget): + def __init__(self, parent=None) -> None: super().__init__(parent=parent) self.setLayout(QVBoxLayout()) - # FIXME https://stackoverflow.com/a/43217828 about loading from resource files doc_url = QUrl.fromLocalFile(cnst.DOCS_ROOT_FILE) self._edit = QTextBrowser() self._edit.setOpenLinks(True)