From 3b90eea7cb3b380988913a7582dfc40841169696 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Thu, 25 Oct 2018 23:33:13 +0200 Subject: [PATCH] Added project settings GUI --- nw/graphics/block.svg | 38 ++++++++++++++++++ nw/graphics/gradient.svg | 60 ++++++++++++++++++++++++++++ nw/gui/projecteditor.py | 67 ++++++++++++++++++++++++-------- nw/gui/winmain.py | 21 ++++++---- nw/project/project.py | 38 ++++++++++-------- sample/sampleNovel/nwProject.nwx | 11 ++++-- 6 files changed, 191 insertions(+), 44 deletions(-) create mode 100644 nw/graphics/block.svg create mode 100644 nw/graphics/gradient.svg diff --git a/nw/graphics/block.svg b/nw/graphics/block.svg new file mode 100644 index 00000000..6546646c --- /dev/null +++ b/nw/graphics/block.svg @@ -0,0 +1,38 @@ + + + + + + + image/svg+xml + + + + + + + + + diff --git a/nw/graphics/gradient.svg b/nw/graphics/gradient.svg new file mode 100644 index 00000000..28f83ef1 --- /dev/null +++ b/nw/graphics/gradient.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/nw/gui/projecteditor.py b/nw/gui/projecteditor.py index 9655a6de..d0737b10 100644 --- a/nw/gui/projecteditor.py +++ b/nw/gui/projecteditor.py @@ -13,20 +13,32 @@ import logging import nw -from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLabel, QLineEdit, QPlainTextEdit, QPushButton, QFileDialog +from os import path + +from PyQt5.QtWidgets import QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QFormLayout, QLabel, QLineEdit, QPlainTextEdit, QPushButton +from PyQt5.QtSvg import QSvgWidget from PyQt5.QtGui import QIcon logger = logging.getLogger(__name__) -class GuiProjectEditor(QWidget): +class GuiProjectEditor(QDialog): - def __init__(self): - QWidget.__init__(self) + def __init__(self, guiParent, theProject): + QDialog.__init__(self, guiParent) logger.debug("Initialising ProjectEditor ...") - self.outerBox = QVBoxLayout() + self.mainConf = nw.CONFIG + self.theProject = theProject + self.outerBox = QHBoxLayout() + self.innerBox = QVBoxLayout() + + self.gradPath = path.abspath(path.join(self.mainConf.appPath,"graphics","block.svg")) + self.svgGradient = QSvgWidget(self.gradPath) + self.svgGradient.setFixedWidth(80) self.setLayout(self.outerBox) + self.outerBox.addWidget(self.svgGradient) + self.outerBox.addLayout(self.innerBox) self.mainGroup = QGroupBox("Project Settings") self.mainForm = QFormLayout() @@ -34,29 +46,50 @@ class GuiProjectEditor(QWidget): self.editName = QLineEdit() self.editTitle = QLineEdit() self.editAuthors = QPlainTextEdit() - self.saveBox = QHBoxLayout() - self.savePath = QLineEdit() - self.saveButton = QPushButton(QIcon.fromTheme("folder"),"Browse") - self.saveButton.setToolTip("Browse for Save Path") - self.saveButton.clicked.connect(self._browseProjectPath) - self.saveBox.addWidget(self.savePath) - self.saveBox.addWidget(self.saveButton) self.mainForm.addRow("Working Title", self.editName) self.mainForm.addRow("Book Title", self.editTitle) self.mainForm.addRow("Book Authors", self.editAuthors) - self.mainForm.addRow("Save Path", self.saveBox) + + self.editName.setText(self.theProject.projName) + self.editTitle.setText(self.theProject.bookTitle) + bookAuthors = "" + for bookAuthor in self.theProject.bookAuthors: + bookAuthors += bookAuthor+"\n" + self.editAuthors.setPlainText(bookAuthors) + + self.buttonBox = QHBoxLayout() + self.closeButton = QPushButton("Close") + self.closeButton.clicked.connect(self._doClose) + self.saveButton = QPushButton("Save") + self.saveButton.clicked.connect(self._doSave) + self.buttonBox.addStretch(1) + self.buttonBox.addWidget(self.closeButton) + self.buttonBox.addWidget(self.saveButton) self.mainGroup.setLayout(self.mainForm) - self.outerBox.addWidget(self.mainGroup) + self.innerBox.addWidget(self.mainGroup) + self.innerBox.addLayout(self.buttonBox) + + self.show() logger.debug("ProjectEditor initialisation complete") return - def _browseProjectPath(self): - fileName, _ = QFileDialog.getSaveFileName(self,"Project File Name","","novelWriter File (*.nwf);;All Files (*)") - self.savePath.setText(fileName) + def _doSave(self): + logger.vverbose("ProjectEditor save button clicked") + projName = self.editName.text() + bookTitle = self.editTitle.text() + bookAuthors = self.editAuthors.toPlainText() + self.theProject.setProjectName(projName) + self.theProject.setBookTitle(bookTitle) + self.theProject.setBookAuthors(bookAuthors) + return + + def _doClose(self): + logger.vverbose("ProjectEditor close button clicked") + self.close() return # END Class GuiProjectEditor diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index 0d8c3cc4..b3daf676 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -13,14 +13,15 @@ import logging import nw -from os import path -from PyQt5.QtWidgets import qApp, QWidget, QMainWindow, QHBoxLayout, QVBoxLayout, QFrame, QSplitter, QAction, QToolBar, QFileDialog -from PyQt5.QtCore import Qt, QSize -from PyQt5.QtGui import QIcon, QStandardItemModel +from os import path +from PyQt5.QtWidgets import qApp, QWidget, QMainWindow, QHBoxLayout, QVBoxLayout, QFrame, QSplitter, QAction, QToolBar, QFileDialog +from PyQt5.QtCore import Qt, QSize +from PyQt5.QtGui import QIcon, QStandardItemModel -from nw.gui.doctree import GuiDocTree -from nw.gui.doceditor import GuiDocEditor -from nw.project.project import NWProject +from nw.gui.doctree import GuiDocTree +from nw.gui.doceditor import GuiDocEditor +from nw.gui.projecteditor import GuiProjectEditor +from nw.project.project import NWProject logger = logging.getLogger(__name__) @@ -115,6 +116,11 @@ class GuiMain(QMainWindow): self.theProject.saveProject() return True + def editProject(self): + dlgProj = GuiProjectEditor(self, self.theProject) + dlgProj.exec_() + return True + # # Document Actions # @@ -164,6 +170,7 @@ class GuiMain(QMainWindow): # File > Project Settings menuProjectSettings = QAction(QIcon.fromTheme("document-properties"), "Project Settings", menuBar) menuProjectSettings.setStatusTip("Project Settings") + menuProjectSettings.triggered.connect(self.editProject) fileMenu.addAction(menuProjectSettings) # --------------------- diff --git a/nw/project/project.py b/nw/project/project.py index 49a678d6..2e912283 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -29,6 +29,7 @@ class NWProject(): # Project Settings self.projPath = None self.projFile = "nwProject.nwx" + self.projName = "" self.bookTitle = "" self.bookAuthors = [] @@ -60,17 +61,17 @@ class NWProject(): logger.error("Project file does not appear to be a novelWriterXML file version 1.0") return False - # for xChild in xRoot: - # if xChild.tag == "book": - # logger.debug("BookOpen: Found book data") - # for xItem in xChild: - # if xItem.text is None: continue - # if xItem.tag == "title": - # logger.verbose("BookOpen: Title is '%s'" % xItem.text) - # self.bookTitle = xItem.text - # elif xItem.tag == "author": - # logger.verbose("BookOpen: Author: '%s'" % xItem.text) - # self.bookAuthors.append(xItem.text) + for xChild in xRoot: + if xChild.tag == "project": + logger.debug("Found book data") + for xItem in xChild: + if xItem.text is None: continue + if xItem.tag == "title": + logger.verbose("Title is '%s'" % xItem.text) + self.bookTitle = xItem.text + elif xItem.tag == "author": + logger.verbose("Author: '%s'" % xItem.text) + self.bookAuthors.append(xItem.text) self.mainConf.setRecent(self.projPath) @@ -92,12 +93,14 @@ class NWProject(): "appVersion" : str(nw.__version__), "timeStamp" : datetime.now().strftime("%Y-%m-%d %H:%M:%S"), }) - xBook = etree.SubElement(nwXML,"book") - xBookTitle = etree.SubElement(xBook,"title") + xProject = etree.SubElement(nwXML,"project") + xProjName = etree.SubElement(xProject,"name") + xProjName.text = self.projName + xBookTitle = etree.SubElement(xProject,"title") xBookTitle.text = self.bookTitle for bookAuthor in self.bookAuthors: if bookAuthor == "": continue - xBookAuthor = etree.SubElement(xBook,"author") + xBookAuthor = etree.SubElement(xProject,"author") xBookAuthor.text = bookAuthor # Write the xml tree to file @@ -131,8 +134,11 @@ class NWProject(): def setBookAuthors(self, bookAuthors): self.bookAuthors = [] - for bookAuthor in bookAuthors.split(","): - self.bookAuthors.append(bookAuthor.strip()) + for bookAuthor in bookAuthors.split("\n"): + bookAuthor = bookAuthor.strip() + if bookAuthor == "": + continue + self.bookAuthors.append(bookAuthor) return True # END Class NWProject diff --git a/sample/sampleNovel/nwProject.nwx b/sample/sampleNovel/nwProject.nwx index 02bf44f8..d0072fed 100644 --- a/sample/sampleNovel/nwProject.nwx +++ b/sample/sampleNovel/nwProject.nwx @@ -1,6 +1,9 @@ - - - - + + + Sample Project + Sample Project + Jane Smith + Jane Doh +