From ef40d4f2de9db2cc1106f9adcceee06f98a68ae1 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 May 2020 20:51:27 +0200 Subject: [PATCH] Added the new exported option to project tree and item editor --- nw/gui/dialogs/configeditor.py | 1 + nw/gui/dialogs/itemeditor.py | 57 +++++++++++++++++++++----------- nw/gui/dialogs/projecteditor.py | 5 +-- nw/gui/elements/doctree.py | 13 ++++++-- sample/sampleNovel/nwProject.nwx | 24 ++++++++++++-- 5 files changed, 74 insertions(+), 26 deletions(-) diff --git a/nw/gui/dialogs/configeditor.py b/nw/gui/dialogs/configeditor.py index 581d7307..e3bf4f7b 100644 --- a/nw/gui/dialogs/configeditor.py +++ b/nw/gui/dialogs/configeditor.py @@ -59,6 +59,7 @@ class GuiConfigEditor(QDialog): self.setWindowTitle("Preferences") self.guiDeco = self.theParent.theTheme.loadDecoration("settings",(64,64)) + self.outerBox.setSpacing(16) self.tabGeneral = GuiConfigEditGeneralTab(self.theParent) self.tabLayout = GuiConfigEditLayoutTab(self.theParent) diff --git a/nw/gui/dialogs/itemeditor.py b/nw/gui/dialogs/itemeditor.py index 30c4721c..fbd7d4dd 100644 --- a/nw/gui/dialogs/itemeditor.py +++ b/nw/gui/dialogs/itemeditor.py @@ -30,10 +30,11 @@ import nw from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( - QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLineEdit, - QPushButton, QComboBox + QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QGridLayout, QLineEdit, + QPushButton, QComboBox, QLabel, QSpacerItem, QSizePolicy, QDialogButtonBox ) +from nw.gui.additions import QSwitch from nw.constants import nwLabels, nwItemLayout, nwItemClass, nwItemType logger = logging.getLogger(__name__) @@ -48,22 +49,26 @@ class GuiItemEditor(QDialog): self.mainConf = nw.CONFIG self.theProject = theProject self.theParent = theParent - self.theItem = self.theProject.projTree[tHandle] - self.outerBox = QHBoxLayout() self.innerBox = QVBoxLayout() + self.theItem = self.theProject.projTree[tHandle] + if self.theItem is None: + self._doClose() + self.setWindowTitle("Item Settings") self.guiDeco = self.theParent.theTheme.loadDecoration("settings",(64,64)) + self.outerBox.setSpacing(16) self.setLayout(self.outerBox) self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop) self.outerBox.addLayout(self.innerBox) self.mainGroup = QGroupBox("Item Settings") - self.mainForm = QFormLayout() + self.mainForm = QGridLayout() self.editName = QLineEdit() + self.editName.setMinimumWidth(220) self.editName.setMaxLength(200) self.editStatus = QComboBox() @@ -100,11 +105,21 @@ class GuiItemEditor(QDialog): if itemLayout in self.validLayouts: self.editLayout.addItem(nwLabels.LAYOUT_NAME[itemLayout],itemLayout) - self.mainForm.addRow("Label", self.editName) - self.mainForm.addRow("Status", self.editStatus) - self.mainForm.addRow("Layout", self.editLayout) + self.editExport = QSwitch() + self.editExport.setChecked(self.theItem.isExported) + self.textExport = QLabel("Include when building project") - self.editName.setMinimumWidth(200) + self.mainForm.addWidget(QLabel("Label"), 0, 0) + self.mainForm.addWidget(self.editName, 0, 1, 1, 2) + self.mainForm.addWidget(QLabel("Status"), 1, 0) + self.mainForm.addWidget(self.editStatus, 1, 1, 1, 2) + self.mainForm.addWidget(QLabel("Layout"), 2, 0) + self.mainForm.addWidget(self.editLayout, 2, 1, 1, 2) + self.mainForm.addWidget(self.textExport, 4, 0, 1, 2) + self.mainForm.addWidget(self.editExport, 4, 2) + + self.spacerItem = QSpacerItem(12, 12, QSizePolicy.Fixed, QSizePolicy.Fixed) + self.mainForm.addItem(self.spacerItem, 3, 0) self.editName.setText(self.theItem.itemName) statusIdx = self.editStatus.findData(self.theItem.itemStatus) @@ -114,19 +129,13 @@ class GuiItemEditor(QDialog): if layoutIdx != -1: self.editLayout.setCurrentIndex(layoutIdx) - self.buttonBox = QHBoxLayout() - self.closeButton = QPushButton("Close") - self.closeButton.clicked.connect(self._doClose) - self.saveButton = QPushButton("Save") - self.saveButton.setDefault(True) - self.saveButton.clicked.connect(self._doSave) - self.buttonBox.addStretch(1) - self.buttonBox.addWidget(self.closeButton) - self.buttonBox.addWidget(self.saveButton) + self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.accepted.connect(self._doSave) + self.buttonBox.rejected.connect(self._doClose) self.mainGroup.setLayout(self.mainForm) self.innerBox.addWidget(self.mainGroup) - self.innerBox.addLayout(self.buttonBox) + self.innerBox.addWidget(self.buttonBox) self.show() @@ -137,16 +146,26 @@ class GuiItemEditor(QDialog): return def _doSave(self): + """Save the setting to the item. + """ + logger.verbose("ItemEditor save button clicked") + itemName = self.editName.text() itemStatus = self.editStatus.currentData() itemLayout = self.editLayout.currentData() + isExported = self.editExport.isChecked() + self.theItem.setName(itemName) self.theItem.setStatus(itemStatus) self.theItem.setLayout(itemLayout) + self.theItem.setExported(isExported) + self.theProject.setProjectChanged(True) + self.accept() self.close() + return def _doClose(self): diff --git a/nw/gui/dialogs/projecteditor.py b/nw/gui/dialogs/projecteditor.py index ffcd2516..3df14269 100644 --- a/nw/gui/dialogs/projecteditor.py +++ b/nw/gui/dialogs/projecteditor.py @@ -54,10 +54,10 @@ class GuiProjectEditor(QDialog): self.outerBox = QHBoxLayout() self.innerBox = QVBoxLayout() - self.setWindowTitle("Project Settings") - self.setLayout(self.outerBox) + self.setWindowTitle("Project Settings") self.guiDeco = self.theParent.theTheme.loadDecoration("settings",(64,64)) + self.outerBox.setSpacing(16) self.theProject.countStatus() self.tabMain = GuiProjectEditMain(self.theParent, self.theProject) @@ -78,6 +78,7 @@ class GuiProjectEditor(QDialog): self.buttonBox.accepted.connect(self._doSave) self.buttonBox.rejected.connect(self._doClose) + self.setLayout(self.outerBox) self.innerBox.addWidget(self.tabWidget) self.innerBox.addWidget(self.buttonBox) diff --git a/nw/gui/elements/doctree.py b/nw/gui/elements/doctree.py index 92a006de..193295e1 100644 --- a/nw/gui/elements/doctree.py +++ b/nw/gui/elements/doctree.py @@ -36,7 +36,7 @@ from PyQt5.QtWidgets import ( from nw.core import NWDoc from nw.constants import ( - nwLabels, nwItemType, nwItemClass, nwItemLayout, nwAlert + nwLabels, nwItemType, nwItemClass, nwItemLayout, nwAlert, nwUnicode ) logger = logging.getLogger(__name__) @@ -254,6 +254,8 @@ class GuiDocTree(QTreeWidget): return theList def getColumnSizes(self): + """Return the column widths for the tree columns. + """ retVals = [ self.columnWidth(0), self.columnWidth(1), @@ -401,7 +403,8 @@ class GuiDocTree(QTreeWidget): return True def setTreeItemValues(self, tHandle): - + """Set the name and flag values for a tree item. + """ trItem = self._getTreeItem(tHandle) nwItem = self.theProject.projTree[tHandle] tName = nwItem.itemName @@ -409,7 +412,11 @@ class GuiDocTree(QTreeWidget): tHandle = nwItem.itemHandle pHandle = nwItem.parHandle - tStatus = nwLabels.CLASS_FLAG[nwItem.itemClass] + if nwItem.isExported: + tStatus = nwUnicode.U_CHECK + else: + tStatus = " " + tStatus += " "+nwLabels.CLASS_FLAG[nwItem.itemClass] if nwItem.itemType == nwItemType.FILE: tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout] iStatus = nwItem.itemStatus diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index a452021d..68ac9522 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -10,7 +10,7 @@ True True - 96b68994dfa3d + 6a2d6d5f4f401 b3e74dbc1f584 875 @@ -41,6 +41,7 @@ NOVEL Started True + True Title Page @@ -48,6 +49,7 @@ NOVEL Started False + True TITLE 72 15 @@ -60,6 +62,7 @@ NOVEL 1st Draft True + True Chapter One @@ -67,6 +70,7 @@ NOVEL Notes False + True CHAPTER 12 3 @@ -79,6 +83,7 @@ NOVEL 1st Draft False + True SCENE 1199 216 @@ -91,6 +96,7 @@ NOVEL 1st Draft False + True SCENE 476 93 @@ -103,6 +109,7 @@ NOVEL Finished False + True UNNUMBERED 633 101 @@ -115,6 +122,7 @@ NOVEL 2nd Draft False + False NOTE 1692 313 @@ -127,6 +135,7 @@ NOVEL 1st Draft False + True CHAPTER 139 28 @@ -139,6 +148,7 @@ NOVEL 1st Draft False + True SCENE 189 37 @@ -151,6 +161,7 @@ CHARACTER None True + True Main Characters @@ -158,6 +169,7 @@ CHARACTER None True + True John Smith @@ -165,6 +177,7 @@ CHARACTER Minor False + True NOTE 49 9 @@ -177,6 +190,7 @@ CHARACTER Major False + True NOTE 55 9 @@ -189,6 +203,7 @@ WORLD None True + True Earth @@ -196,6 +211,7 @@ WORLD Main False + True NOTE 76 15 @@ -208,6 +224,7 @@ WORLD Minor False + True NOTE 115 24 @@ -220,6 +237,7 @@ WORLD Major False + True NOTE 28 6 @@ -232,6 +250,7 @@ TRASH None True + True Delete Me! @@ -239,6 +258,7 @@ NOVEL New False + True SCENE 30 6