From 59eaf9177eba5e407ae45582e03f49e217e3c7f3 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 22 Feb 2021 19:29:01 +0100 Subject: [PATCH 1/4] Remove some debug print statements --- nw/common.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nw/common.py b/nw/common.py index d05d814b1..6d609f6e6 100644 --- a/nw/common.py +++ b/nw/common.py @@ -167,7 +167,7 @@ def colRange(rgbStart, rgbEnd, nStep): cA = rgbStart[c] cB = rgbEnd[c] dC[c] = (cB-cA)/(nStep-1) - print(dC) + retCol = [rgbStart] for n in range(nStep): if n > 0 and n < nStep: @@ -177,7 +177,6 @@ def colRange(rgbStart, rgbEnd, nStep): int(retCol[n-1][2] + dC[2]), ]) retCol[-1] = rgbEnd - print(retCol) return retCol From c89cb32871e5161d3bfbb5f919bb8654f0c50b41 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:21:22 +0100 Subject: [PATCH 2/4] Make the QConfigLayout custom class more responsive to the length of labels due to translations --- nw/gui/custom.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nw/gui/custom.py b/nw/gui/custom.py index 1ecd7b8bd..7df275f8c 100644 --- a/nw/gui/custom.py +++ b/nw/gui/custom.py @@ -36,7 +36,8 @@ from PyQt5.QtWidgets import ( QGridLayout, QLabel, QWidget, QVBoxLayout, QHBoxLayout, QSizePolicy, QAbstractButton, QDialog, QTabWidget, QTabBar, QStyle, QDialogButtonBox, - QStylePainter, QStyleOptionTab, QListWidget, QListWidgetItem, QFrame + QStylePainter, QStyleOptionTab, QListWidget, QListWidgetItem, QFrame, + QLineEdit ) from nw.constants import trConst, nwUnicode, nwQuotes @@ -61,6 +62,7 @@ def __init__(self): wSp = nw.CONFIG.pxInt(8) self.setHorizontalSpacing(wSp) self.setVerticalSpacing(wSp) + self.setColumnStretch(0, 1) return @@ -151,6 +153,7 @@ def addRow(self, theLabel, theWidget, helpText=None, theUnit=None, theButton=Non labelBox.addWidget(qLabel) labelBox.addWidget(qHelp) labelBox.setSpacing(0) + labelBox.addStretch(1) thisEntry["help"] = qHelp self.addLayout(labelBox, self._nextRow, 0, 1, 1, Qt.AlignLeft | Qt.AlignTop) @@ -163,15 +166,22 @@ def addRow(self, theLabel, theWidget, helpText=None, theUnit=None, theButton=Non controlBox.addWidget(qWidget, 0, Qt.AlignVCenter) controlBox.addWidget(QLabel(theUnit), 0, Qt.AlignVCenter) controlBox.setSpacing(wSp) - self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter) + self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop) + elif theButton is not None: controlBox = QHBoxLayout() controlBox.addWidget(qWidget, 0, Qt.AlignVCenter) controlBox.addWidget(theButton, 0, Qt.AlignVCenter) controlBox.setSpacing(wSp) - self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter) + self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop) + else: - self.addWidget(qWidget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter) + if isinstance(theWidget, QLineEdit): + qLayout = QHBoxLayout() + qLayout.addWidget(theWidget) + self.addLayout(qLayout, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop) + else: + self.addWidget(qWidget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop) qLabel.setBuddy(qWidget) @@ -207,6 +217,9 @@ def __init__(self, theText, textCol, fontSize=0.9): lblFont.setPointSizeF(fontSize*lblFont.pointSizeF()) self.setFont(lblFont) + self.setWordWrap(True) + self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + return # END Class QHelpLabel @@ -409,6 +422,7 @@ class VerticalTabBar(QTabBar): def __init__(self, theParent=None): QTabBar.__init__(self, parent=theParent) + self._mW = nw.CONFIG.pxInt(150) return def tabSizeHint(self, theIndex): @@ -416,6 +430,7 @@ def tabSizeHint(self, theIndex): """ tSize = QTabBar.tabSizeHint(self, theIndex) tSize.transpose() + tSize.setWidth(min(tSize.width(), self._mW)) return tSize def paintEvent(self, theEvent): From 2152f540666af64297cae3325c28375b956f4486 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:22:49 +0100 Subject: [PATCH 3/4] Make use of the improved layout class in Project Settings and Preferences --- nw/gui/preferences.py | 18 +++++++++++++++++- nw/gui/projsettings.py | 17 +++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/nw/gui/preferences.py b/nw/gui/preferences.py index 3dcff6084..2db6528ef 100644 --- a/nw/gui/preferences.py +++ b/nw/gui/preferences.py @@ -74,12 +74,14 @@ def __init__(self, theParent, theProject): self.buttonBox.rejected.connect(self._doClose) self.addControls(self.buttonBox) + self.resize(*self.mainConf.getPreferencesSize()) + logger.debug("GuiPreferences initialisation complete") return ## - # Buttons + # Slots ## def _doSave(self): @@ -102,6 +104,7 @@ def _doSave(self): nwAlert.INFO ) + self._saveWindowSize() self.accept() return @@ -109,9 +112,22 @@ def _doSave(self): def _doClose(self): """Close the preferences without saving the changes. """ + self._saveWindowSize() self.reject() return + ## + # Internal Functions + ## + + def _saveWindowSize(self): + """Save the dialog window size. + """ + winWidth = self.mainConf.rpxInt(self.width()) + winHeight = self.mainConf.rpxInt(self.height()) + self.mainConf.setPreferencesSize(winWidth, winHeight) + return + # END Class GuiPreferences class GuiPreferencesGeneral(QWidget): diff --git a/nw/gui/projsettings.py b/nw/gui/projsettings.py index fcbb20355..dca620404 100644 --- a/nw/gui/projsettings.py +++ b/nw/gui/projsettings.py @@ -169,11 +169,11 @@ def __init__(self, theParent, theProject): self.mainForm.addGroupLabel(self.tr("Project Settings")) xW = self.mainConf.pxInt(250) - xH = self.mainConf.pxInt(100) + xH = self.mainConf.pxInt(80) self.editName = QLineEdit() self.editName.setMaxLength(200) - self.editName.setFixedWidth(xW) + self.editName.setMaximumWidth(xW) self.editName.setText(self.theProject.projName) self.mainForm.addRow( self.tr("Working title"), @@ -183,7 +183,7 @@ def __init__(self, theParent, theProject): self.editTitle = QLineEdit() self.editTitle.setMaxLength(200) - self.editTitle.setFixedWidth(xW) + self.editTitle.setMaximumWidth(xW) self.editTitle.setText(self.theProject.bookTitle) self.mainForm.addRow( self.tr("Novel title"), @@ -192,12 +192,9 @@ def __init__(self, theParent, theProject): ) self.editAuthors = QPlainTextEdit() - bookAuthors = "" - for bookAuthor in self.theProject.bookAuthors: - bookAuthors += bookAuthor+"\n" - self.editAuthors.setPlainText(bookAuthors) - self.editAuthors.setFixedHeight(xH) - self.editAuthors.setFixedWidth(xW) + self.editAuthors.setMinimumHeight(xH) + self.editAuthors.setMaximumWidth(xW) + self.editAuthors.setPlainText("\n".join(self.theProject.bookAuthors)) self.mainForm.addRow( self.tr("Author(s)"), self.editAuthors, @@ -205,7 +202,7 @@ def __init__(self, theParent, theProject): ) self.spellLang = QComboBox(self) - self.spellLang.setFixedWidth(xW) + self.spellLang.setMaximumWidth(xW) theDict = self.theParent.docEditor.theDict self.spellLang.addItem(self.tr("Default"), "None") if theDict is not None: From 66282d4ed039fcbb88f015934d6c8487241782e7 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:23:14 +0100 Subject: [PATCH 4/4] Add Preferences window size to Config and update tests --- nw/config.py | 14 ++++++++++++++ tests/reference/baseConfig_novelwriter.conf | 1 + tests/reference/guiPreferences_novelwriter.conf | 1 + tests/test_gui/test_gui_projsettings.py | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/nw/config.py b/nw/config.py index a24aef0a0..4ef8867b5 100644 --- a/nw/config.py +++ b/nw/config.py @@ -104,6 +104,7 @@ def __init__(self): ## Sizes self.winGeometry = [1200, 650] + self.prefGeometry = [700, 615] self.treeColWidth = [200, 50, 30] self.novelColWidth = [200, 50] self.projColWidth = [200, 60, 140] @@ -472,6 +473,9 @@ def loadConfig(self): self.winGeometry = self._parseLine( cnfParse, cnfSec, "geometry", self.CNF_I_LST, self.winGeometry ) + self.prefGeometry = self._parseLine( + cnfParse, cnfSec, "preferences", self.CNF_I_LST, self.prefGeometry + ) self.treeColWidth = self._parseLine( cnfParse, cnfSec, "treecols", self.CNF_I_LST, self.treeColWidth ) @@ -701,6 +705,7 @@ def saveConfig(self): cnfSec = "Sizes" cnfParse.add_section(cnfSec) cnfParse.set(cnfSec, "geometry", self._packList(self.winGeometry)) + cnfParse.set(cnfSec, "preferences", self._packList(self.prefGeometry)) cnfParse.set(cnfSec, "treecols", self._packList(self.treeColWidth)) cnfParse.set(cnfSec, "novelcols", self._packList(self.novelColWidth)) cnfParse.set(cnfSec, "projcols", self._packList(self.projColWidth)) @@ -921,6 +926,12 @@ def setWinSize(self, newWidth, newHeight): self.confChanged = True return True + def setPreferencesSize(self, newWidth, newHeight): + self.prefGeometry[0] = int(newWidth/self.guiScale) + self.prefGeometry[1] = int(newHeight/self.guiScale) + self.confChanged = True + return True + def setTreeColWidths(self, colWidths): self.treeColWidth = [int(x/self.guiScale) for x in colWidths] self.confChanged = True @@ -984,6 +995,9 @@ def setViewSynopsis(self, viewState): def getWinSize(self): return [int(x*self.guiScale) for x in self.winGeometry] + def getPreferencesSize(self): + return [int(x*self.guiScale) for x in self.prefGeometry] + def getTreeColWidths(self): return [int(x*self.guiScale) for x in self.treeColWidth] diff --git a/tests/reference/baseConfig_novelwriter.conf b/tests/reference/baseConfig_novelwriter.conf index 4ec14a137..3f7cf6df1 100644 --- a/tests/reference/baseConfig_novelwriter.conf +++ b/tests/reference/baseConfig_novelwriter.conf @@ -11,6 +11,7 @@ guilang = en-GB [Sizes] geometry = 1200, 650 +preferences = 700, 615 treecols = 200, 50, 30 novelcols = 200, 50 projcols = 200, 60, 140 diff --git a/tests/reference/guiPreferences_novelwriter.conf b/tests/reference/guiPreferences_novelwriter.conf index b7cf116c1..8b8f52b41 100644 --- a/tests/reference/guiPreferences_novelwriter.conf +++ b/tests/reference/guiPreferences_novelwriter.conf @@ -11,6 +11,7 @@ guilang = en-GB [Sizes] geometry = 1200, 650 +preferences = 700, 615 treecols = 200, 50, 30 novelcols = 200, 50 projcols = 200, 60, 140 diff --git a/tests/test_gui/test_gui_projsettings.py b/tests/test_gui/test_gui_projsettings.py index 9955aac85..cb2e5b701 100644 --- a/tests/test_gui/test_gui_projsettings.py +++ b/tests/test_gui/test_gui_projsettings.py @@ -79,7 +79,7 @@ def testGuiProjSettings_Dialog(qtbot, monkeypatch, nwGUI, fncDir, fncProj, outDi assert projEdit.tabMain.editName.text() == "New Project" assert projEdit.tabMain.editTitle.text() == "" - assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Smith\nJohn Smith\n" + assert projEdit.tabMain.editAuthors.toPlainText() == "Jane Smith\nJohn Smith" assert projEdit.tabMain.spellLang.currentData() == "en" assert projEdit.tabMain.doBackup.isChecked() is False