From 61359f746c501502537d78def1ecdd21f6f28348 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 4 Oct 2020 18:23:48 +0200 Subject: [PATCH] Make the whole build tool dialog more dynamic in sizes and areas --- nw/core/options.py | 2 + nw/gui/build.py | 132 ++++++++++++++++++++++++++++++++------------- 2 files changed, 98 insertions(+), 36 deletions(-) diff --git a/nw/core/options.py b/nw/core/options.py index 76d8621b..b5938490 100644 --- a/nw/core/options.py +++ b/nw/core/options.py @@ -62,6 +62,8 @@ class OptionState(): "GuiBuildNovel": { "winWidth", "winHeight", + "boxWidth", + "docWidth", "addNovel", "addNotes", "ignoreFlag", diff --git a/nw/gui/build.py b/nw/gui/build.py index c7a558a2..8ba754b3 100644 --- a/nw/gui/build.py +++ b/nw/gui/build.py @@ -41,7 +41,8 @@ from PyQt5.QtGui import ( from PyQt5.QtWidgets import ( QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel, QLineEdit, QGroupBox, QGridLayout, QProgressBar, QMenu, QAction, - QFileDialog, QFontDialog, QSpinBox + QFileDialog, QFontDialog, QSpinBox, QScrollArea, QSplitter, QWidget, + QSizePolicy ) from nw.common import fuzzyTime, makeFileNameSafe @@ -82,17 +83,14 @@ class GuiBuildNovel(QDialog): self.buildTime = 0 # The timestamp of the last build self.setWindowTitle("Build Novel Project") - self.setMinimumWidth(self.mainConf.pxInt(900)) - self.setMinimumHeight(self.mainConf.pxInt(800)) + self.setMinimumWidth(self.mainConf.pxInt(700)) + self.setMinimumHeight(self.mainConf.pxInt(600)) self.resize( self.mainConf.pxInt(self.optState.getInt("GuiBuildNovel", "winWidth", 900)), self.mainConf.pxInt(self.optState.getInt("GuiBuildNovel", "winHeight", 800)) ) - self.outerBox = QHBoxLayout() - self.toolsBox = QVBoxLayout() - self.docView = GuiBuildNovelDocView(self, self.theProject) # Title Formats @@ -118,11 +116,11 @@ class GuiBuildNovel(QDialog): r"be centred automatically and only appear between sections of " r"the same type." ) - xFmt = self.mainConf.pxInt(220) + xFmt = self.mainConf.pxInt(100) self.fmtTitle = QLineEdit() self.fmtTitle.setMaxLength(200) - self.fmtTitle.setFixedWidth(xFmt) + self.fmtTitle.setMinimumWidth(xFmt) self.fmtTitle.setToolTip(fmtHelp) self.fmtTitle.setText( self._reFmtCodes(self.theProject.titleFormat["title"]) @@ -130,7 +128,7 @@ class GuiBuildNovel(QDialog): self.fmtChapter = QLineEdit() self.fmtChapter.setMaxLength(200) - self.fmtChapter.setFixedWidth(xFmt) + self.fmtChapter.setMinimumWidth(xFmt) self.fmtChapter.setToolTip(fmtHelp) self.fmtChapter.setText( self._reFmtCodes(self.theProject.titleFormat["chapter"]) @@ -138,7 +136,7 @@ class GuiBuildNovel(QDialog): self.fmtUnnumbered = QLineEdit() self.fmtUnnumbered.setMaxLength(200) - self.fmtUnnumbered.setFixedWidth(xFmt) + self.fmtUnnumbered.setMinimumWidth(xFmt) self.fmtUnnumbered.setToolTip(fmtHelp) self.fmtUnnumbered.setText( self._reFmtCodes(self.theProject.titleFormat["unnumbered"]) @@ -146,7 +144,7 @@ class GuiBuildNovel(QDialog): self.fmtScene = QLineEdit() self.fmtScene.setMaxLength(200) - self.fmtScene.setFixedWidth(xFmt) + self.fmtScene.setMinimumWidth(xFmt) self.fmtScene.setToolTip(fmtHelp + fmtScHelp) self.fmtScene.setText( self._reFmtCodes(self.theProject.titleFormat["scene"]) @@ -154,25 +152,37 @@ class GuiBuildNovel(QDialog): self.fmtSection = QLineEdit() self.fmtSection.setMaxLength(200) - self.fmtSection.setFixedWidth(xFmt) + self.fmtSection.setMinimumWidth(xFmt) self.fmtSection.setToolTip(fmtHelp + fmtScHelp) self.fmtSection.setText( self._reFmtCodes(self.theProject.titleFormat["section"]) ) - self.titleForm.addWidget(QLabel("Title"), 0, 0, 1, 1, Qt.AlignLeft) - self.titleForm.addWidget(self.fmtTitle, 0, 1, 1, 1, Qt.AlignRight) - self.titleForm.addWidget(QLabel("Chapter"), 1, 0, 1, 1, Qt.AlignLeft) - self.titleForm.addWidget(self.fmtChapter, 1, 1, 1, 1, Qt.AlignRight) - self.titleForm.addWidget(QLabel("Unnumbered"), 2, 0, 1, 1, Qt.AlignLeft) - self.titleForm.addWidget(self.fmtUnnumbered, 2, 1, 1, 1, Qt.AlignRight) - self.titleForm.addWidget(QLabel("Scene"), 3, 0, 1, 1, Qt.AlignLeft) - self.titleForm.addWidget(self.fmtScene, 3, 1, 1, 1, Qt.AlignRight) - self.titleForm.addWidget(QLabel("Section"), 4, 0, 1, 1, Qt.AlignLeft) - self.titleForm.addWidget(self.fmtSection, 4, 1, 1, 1, Qt.AlignRight) + # Dummy boxes due to QGridView and QLineEdit expand bug + self.boxTitle = QHBoxLayout() + self.boxTitle.addWidget(self.fmtTitle) + self.boxChapter = QHBoxLayout() + self.boxChapter.addWidget(self.fmtChapter) + self.boxUnnumbered = QHBoxLayout() + self.boxUnnumbered.addWidget(self.fmtUnnumbered) + self.boxScene = QHBoxLayout() + self.boxScene.addWidget(self.fmtScene) + self.boxSection = QHBoxLayout() + self.boxSection.addWidget(self.fmtSection) - self.titleForm.setColumnStretch(0, 1) - self.titleForm.setColumnStretch(1, 0) + self.titleForm.addWidget(QLabel("Title"), 0, 0, 1, 1, Qt.AlignLeft) + self.titleForm.addLayout(self.boxTitle, 0, 1, 1, 1, Qt.AlignRight) + self.titleForm.addWidget(QLabel("Chapter"), 1, 0, 1, 1, Qt.AlignLeft) + self.titleForm.addLayout(self.boxChapter, 1, 1, 1, 1, Qt.AlignRight) + self.titleForm.addWidget(QLabel("Unnumbered"), 2, 0, 1, 1, Qt.AlignLeft) + self.titleForm.addLayout(self.boxUnnumbered, 2, 1, 1, 1, Qt.AlignRight) + self.titleForm.addWidget(QLabel("Scene"), 3, 0, 1, 1, Qt.AlignLeft) + self.titleForm.addLayout(self.boxScene, 3, 1, 1, 1, Qt.AlignRight) + self.titleForm.addWidget(QLabel("Section"), 4, 0, 1, 1, Qt.AlignLeft) + self.titleForm.addLayout(self.boxSection, 4, 1, 1, 1, Qt.AlignRight) + + self.titleForm.setColumnStretch(0, 0) + self.titleForm.setColumnStretch(1, 1) # Text Options # ============= @@ -183,7 +193,7 @@ class GuiBuildNovel(QDialog): ## Font Family self.textFont = QLineEdit() self.textFont.setReadOnly(True) - self.textFont.setFixedWidth(self.mainConf.pxInt(182)) + self.textFont.setMinimumWidth(xFmt) self.textFont.setText( self.optState.getString("GuiBuildNovel", "textFont", self.mainConf.textFont) ) @@ -219,8 +229,12 @@ class GuiBuildNovel(QDialog): self.optState.getBool("GuiBuildNovel", "noStyling", False) ) + # Dummy box due to QGridView and QLineEdit expand bug + self.boxFont = QHBoxLayout() + self.boxFont.addWidget(self.textFont) + self.formatForm.addWidget(QLabel("Font family"), 0, 0, 1, 1, Qt.AlignLeft) - self.formatForm.addWidget(self.textFont, 0, 1, 1, 1, Qt.AlignRight) + self.formatForm.addLayout(self.boxFont, 0, 1, 1, 1, Qt.AlignRight) self.formatForm.addWidget(self.fontButton, 0, 2, 1, 1, Qt.AlignRight) self.formatForm.addWidget(QLabel("Font size"), 1, 0, 1, 1, Qt.AlignLeft) self.formatForm.addWidget(self.textSize, 1, 1, 1, 2, Qt.AlignRight) @@ -229,8 +243,8 @@ class GuiBuildNovel(QDialog): self.formatForm.addWidget(QLabel("Disable styling"), 3, 0, 1, 1, Qt.AlignLeft) self.formatForm.addWidget(self.noStyling, 3, 1, 1, 2, Qt.AlignRight) - self.formatForm.setColumnStretch(0, 1) - self.formatForm.setColumnStretch(1, 0) + self.formatForm.setColumnStretch(0, 0) + self.formatForm.setColumnStretch(1, 1) self.formatForm.setColumnStretch(2, 0) # Include Switches @@ -384,20 +398,56 @@ class GuiBuildNovel(QDialog): # Assemble GUI # ============ + + # Splitter Position + boxWidth = self.mainConf.pxInt(350) + boxWidth = self.optState.getInt("GuiBuildNovel", "boxWidth", boxWidth) + docWidth = max(self.width() - boxWidth, 100) + docWidth = self.optState.getInt("GuiBuildNovel", "docWidth", docWidth) + + # The Tool Box + self.toolsBox = QVBoxLayout() self.toolsBox.addWidget(self.titleGroup) self.toolsBox.addWidget(self.formatGroup) self.toolsBox.addWidget(self.textGroup) self.toolsBox.addWidget(self.fileGroup) self.toolsBox.addStretch(1) - self.toolsBox.addWidget(self.buildProgress) - self.toolsBox.addWidget(self.buildNovel) - self.toolsBox.addSpacing(8) - self.toolsBox.addLayout(self.buttonBox) - self.outerBox.addLayout(self.toolsBox) - self.outerBox.addWidget(self.docView) - self.outerBox.setStretch(0, 0) - self.outerBox.setStretch(1, 1) + # Tool Box Wrapper Widget + self.toolsWidget = QWidget() + self.toolsWidget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum) + self.toolsWidget.setLayout(self.toolsBox) + + # Tool Box Scroll Area + self.toolsArea = QScrollArea() + self.toolsArea.setMinimumWidth(self.mainConf.pxInt(250)) + self.toolsArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self.toolsArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) + self.toolsArea.setWidgetResizable(True) + self.toolsArea.setWidget(self.toolsWidget) + + # Tools and Buttons Layout + self.innerBox = QVBoxLayout() + self.innerBox.addWidget(self.toolsArea) + self.innerBox.addSpacing(8) + self.innerBox.addWidget(self.buildProgress) + self.innerBox.addWidget(self.buildNovel) + self.innerBox.addSpacing(8) + self.innerBox.addLayout(self.buttonBox) + + # Tools and Buttons Wrapper Widget + self.innerWidget = QWidget() + self.innerWidget.setLayout(self.innerBox) + + # Main Dialog Splitter + self.mainSplit = QSplitter(Qt.Horizontal) + self.mainSplit.addWidget(self.innerWidget) + self.mainSplit.addWidget(self.docView) + self.mainSplit.setSizes([boxWidth, docWidth]) + + # Outer Layout + self.outerBox = QHBoxLayout() + self.outerBox.addWidget(self.mainSplit) self.setLayout(self.outerBox) self.buildNovel.setFocus() @@ -897,9 +947,19 @@ class GuiBuildNovel(QDialog): incKeywords = self.includeKeywords.isChecked() incBodyText = self.includeBody.isChecked() + mainSplit = self.mainSplit.sizes() + if len(mainSplit) == 2: + boxWidth = self.mainConf.rpxInt(mainSplit[0]) + docWidth = self.mainConf.rpxInt(mainSplit[1]) + else: + boxWidth = 100 + docWidth = 100 + # GUI Settings self.optState.setValue("GuiBuildNovel", "winWidth", winWidth) self.optState.setValue("GuiBuildNovel", "winHeight", winHeight) + self.optState.setValue("GuiBuildNovel", "boxWidth", boxWidth) + self.optState.setValue("GuiBuildNovel", "docWidth", docWidth) self.optState.setValue("GuiBuildNovel", "justifyText", justifyText) self.optState.setValue("GuiBuildNovel", "noStyling", noStyling) self.optState.setValue("GuiBuildNovel", "textFont", textFont)