From e5f04e5234de75334cfa3bb49fb1117abcdf3586 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 27 Nov 2022 16:55:54 +0100 Subject: [PATCH] Reduce number of author entries in project to one --- novelwriter/core/coretools.py | 8 ++++---- novelwriter/core/project.py | 16 --------------- novelwriter/core/projectdata.py | 29 +++++++--------------------- novelwriter/core/projectxml.py | 12 ++---------- novelwriter/core/toodt.py | 2 +- novelwriter/dialogs/projdetails.py | 4 +--- novelwriter/dialogs/projsettings.py | 30 ++++++++++++++--------------- novelwriter/guimain.py | 2 +- novelwriter/tools/build.py | 4 ++-- novelwriter/tools/projwizard.py | 18 ++++++++--------- sample/content/53b69b83cdafc.nwd | 2 +- sample/nwProject.nwx | 7 +++---- tests/tools.py | 2 +- 13 files changed, 45 insertions(+), 91 deletions(-) diff --git a/novelwriter/core/coretools.py b/novelwriter/core/coretools.py index ff002935..b87bb7b8 100644 --- a/novelwriter/core/coretools.py +++ b/novelwriter/core/coretools.py @@ -315,12 +315,12 @@ class ProjectBuilder: # Settings projName = data.get("projName", lblNewProject) projTitle = data.get("projTitle", lblNewProject) - projAuthors = data.get("projAuthors", "") + projAuthor = data.get("projAuthor", "") project.data.setUuid(None) project.data.setName(projName) project.data.setTitle(projTitle) - project.data.setAuthors(projAuthors) + project.data.setAuthor(projAuthor) project.setDefaultStatusImport() project._projOpened = int(time()) @@ -330,8 +330,8 @@ class ProjectBuilder: novelTitle = project.data.title if project.data.title else project.data.name titlePage = f"#! {novelTitle}\n\n" - if project.data.authors: - titlePage += f">> {lblByAuthors} {project.getFormattedAuthors()} <<\n\n" + if project.data.author: + titlePage += f">> {lblByAuthors} {project.data.author} <<\n\n" aDoc = project.storage.getDocument(hTitlePage) aDoc.writeDocument(titlePage) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index b60cbbc6..64c0b148 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -565,22 +565,6 @@ class NWProject(QObject): return self._lockedBy return None - def getFormattedAuthors(self): - """Return a formatted string of authors. - """ - authors = self._data.authors - nAuth = len(authors) - - result = "" - if nAuth == 1: - result = authors[0] - elif nAuth > 1: - result = "%s %s %s" % ( - ", ".join(authors[0:-1]), self.tr("and"), authors[-1] - ) - - return result - def getCurrentEditTime(self): """Get the total project edit time, including the time spent in the current session. diff --git a/novelwriter/core/projectdata.py b/novelwriter/core/projectdata.py index 40bce1a7..9fb1c9e9 100644 --- a/novelwriter/core/projectdata.py +++ b/novelwriter/core/projectdata.py @@ -46,7 +46,7 @@ class NWProjectData: self._uuid = "" self._name = "" self._title = "" - self._authors = [] + self._author = "" self._saveCount = 0 self._autoCount = 0 self._editTime = 0 @@ -97,8 +97,8 @@ class NWProjectData: return self._title @property - def authors(self): - return self._authors + def author(self): + return self._author @property def saveCount(self): @@ -160,13 +160,6 @@ class NWProjectData: # Methods ## - def addAuthor(self, value): - """Add an author to the authors list. - """ - self._authors.append(simplified(str(value))) - self.theProject.setProjectChanged(True) - return - def incSaveCount(self): """Increment the save count by one. """ @@ -226,20 +219,12 @@ class NWProjectData: self.theProject.setProjectChanged(True) return - def setAuthors(self, value): - """Set the list of authors from either a string with one author - per line, or a list of authors. + def setAuthor(self, value): + """Set the author value. """ - self._authors = [] - self.theProject.setProjectChanged(True) - if isinstance(value, str): - for author in value.splitlines(): - author = simplified(author) - if author: - self._authors.append(author) + if value != self._title: + self._author = simplified(str(value)) self.theProject.setProjectChanged(True) - elif isinstance(value, list): - self._authors = value return def setSaveCount(self, value): diff --git a/novelwriter/core/projectxml.py b/novelwriter/core/projectxml.py index 5b1b72f4..5f8912b1 100644 --- a/novelwriter/core/projectxml.py +++ b/novelwriter/core/projectxml.py @@ -245,7 +245,7 @@ class ProjectXMLReader: elif xItem.tag == "title": projData.setTitle(xItem.text) elif xItem.tag == "author": - projData.addAuthor(xItem.text) + projData.setAuthor(xItem.text) else: logger.warning("Ignored in XML", xItem.tag) @@ -517,7 +517,7 @@ class ProjectXMLWriter: xProject = etree.SubElement(xRoot, "project", attrib=projAttr) self._packSingleValue(xProject, "name", projData.name) self._packSingleValue(xProject, "title", projData.title) - self._packListValue(xProject, "author", projData.authors) + self._packSingleValue(xProject, "author", projData.author) # Save Project Settings xSettings = etree.SubElement(xRoot, "settings") @@ -590,14 +590,6 @@ class ProjectXMLWriter: xItem.text = str(value) or "" return - def _packListValue(self, xParent, name, data): - """Pack a list of values into an XML element. - """ - for value in data: - xItem = etree.SubElement(xParent, name) - xItem.text = str(value) or "" - return - def _packDictKeyValue(self, xParent, name, data): """Pack the entries of a dictionary into an XML element. """ diff --git a/novelwriter/core/toodt.py b/novelwriter/core/toodt.py index 594074ff..e05121df 100644 --- a/novelwriter/core/toodt.py +++ b/novelwriter/core/toodt.py @@ -262,7 +262,7 @@ class ToOdt(Tokenizer): if self._headerText == "": theTitle = self.theProject.data.title - theAuth = self.theProject.getFormattedAuthors() + theAuth = self.theProject.data.author self._headerText = f"{theTitle} / {theAuth} /" # Create Roots diff --git a/novelwriter/dialogs/projdetails.py b/novelwriter/dialogs/projdetails.py index 00d3d4df..8c0097e2 100644 --- a/novelwriter/dialogs/projdetails.py +++ b/novelwriter/dialogs/projdetails.py @@ -174,9 +174,7 @@ class GuiProjectDetailsMain(QWidget): self.projName.setAlignment(Qt.AlignHCenter) self.projName.setWordWrap(True) - self.bookAuthors = QLabel(self.tr("By {0}").format( - self.theProject.getFormattedAuthors() - )) + self.bookAuthors = QLabel(self.tr("By {0}").format(self.theProject.data.author)) authFont = self.bookAuthors.font() authFont.setPointSizeF(1.2*fPt) self.bookAuthors.setFont(authFont) diff --git a/novelwriter/dialogs/projsettings.py b/novelwriter/dialogs/projsettings.py index 77da0860..0688bb70 100644 --- a/novelwriter/dialogs/projsettings.py +++ b/novelwriter/dialogs/projsettings.py @@ -29,9 +29,8 @@ import novelwriter from PyQt5.QtGui import QIcon, QPixmap, QColor, QBrush from PyQt5.QtCore import Qt, QLocale from PyQt5.QtWidgets import ( - QHBoxLayout, QVBoxLayout, QLineEdit, QPlainTextEdit, QLabel, QWidget, - QDialogButtonBox, QPushButton, QColorDialog, QTreeWidget, QTreeWidgetItem, - QComboBox + QColorDialog, QComboBox, QDialogButtonBox, QHBoxLayout, QLabel, QLineEdit, + QPushButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget ) from novelwriter.enum import nwAlert @@ -108,15 +107,15 @@ class GuiProjectSettings(PagedDialog): def _doSave(self): """Save settings and close dialog. """ - projName = self.tabMain.editName.text() - bookTitle = self.tabMain.editTitle.text() - bookAuthors = self.tabMain.editAuthors.toPlainText() - spellLang = self.tabMain.spellLang.currentData() - doBackup = not self.tabMain.doBackup.isChecked() + projName = self.tabMain.editName.text() + bookTitle = self.tabMain.editTitle.text() + bookAuthor = self.tabMain.editAuthor.text() + spellLang = self.tabMain.spellLang.currentData() + doBackup = not self.tabMain.doBackup.isChecked() self.theProject.data.setName(projName) self.theProject.data.setTitle(bookTitle) - self.theProject.data.setAuthors(bookAuthors) + self.theProject.data.setAuthor(bookAuthor) self.theProject.data.setDoBackup(doBackup) # Remember this as updating spell dictionary can be expensive @@ -204,7 +203,6 @@ class GuiProjectEditMain(QWidget): self.mainForm.addGroupLabel(self.tr("Project Settings")) xW = self.mainConf.pxInt(250) - xH = round(4.8*self.mainGui.mainTheme.fontPixelSize) self.editName = QLineEdit() self.editName.setMaxLength(200) @@ -226,14 +224,14 @@ class GuiProjectEditMain(QWidget): self.tr("Change whenever you want!") ) - self.editAuthors = QPlainTextEdit() - self.editAuthors.setMaximumHeight(xH) - self.editAuthors.setMaximumWidth(xW) - self.editAuthors.setPlainText("\n".join(self.theProject.data.authors)) + self.editAuthor = QLineEdit() + self.editAuthor.setMaxLength(200) + self.editAuthor.setMaximumWidth(xW) + self.editAuthor.setText(self.theProject.data.author) self.mainForm.addRow( self.tr("Author(s)"), - self.editAuthors, - self.tr("One name per line.") + self.editAuthor, + self.tr("Change whenever you want!") ) self.spellLang = QComboBox(self) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 1aab1e88..55511bfe 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -1419,7 +1419,7 @@ class GuiMain(QMainWindow): projData = { "projName": newProj.field("projName"), "projTitle": newProj.field("projTitle"), - "projAuthors": newProj.field("projAuthors"), + "projAuthor": newProj.field("projAuthor"), "projPath": newProj.field("projPath"), "popSample": newProj.field("popSample"), "popMinimal": newProj.field("popMinimal"), diff --git a/novelwriter/tools/build.py b/novelwriter/tools/build.py index 2935c556..dbdbe16a 100644 --- a/novelwriter/tools/build.py +++ b/novelwriter/tools/build.py @@ -968,9 +968,9 @@ class GuiBuildNovel(QDialog): elif theFmt == self.FMT_JSON_H or theFmt == self.FMT_JSON_M: jsonData = { "meta": { - "workingTitle": self.theProject.data.name, + "projectName": self.theProject.data.name, "novelTitle": self.theProject.data.title, - "authors": self.theProject.data.authors, + "novelAuthor": self.theProject.data.author, "buildTime": self.buildTime, } } diff --git a/novelwriter/tools/projwizard.py b/novelwriter/tools/projwizard.py index fbd2b8ac..c9cc157b 100644 --- a/novelwriter/tools/projwizard.py +++ b/novelwriter/tools/projwizard.py @@ -29,9 +29,8 @@ import novelwriter from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( - QWizard, QWizardPage, QLabel, QVBoxLayout, QLineEdit, QPlainTextEdit, - QPushButton, QFileDialog, QHBoxLayout, QRadioButton, QFormLayout, - QGridLayout, QSpinBox + QFileDialog, QFormLayout, QGridLayout, QHBoxLayout, QLabel, QLineEdit, + QPushButton, QRadioButton, QSpinBox, QVBoxLayout, QWizard, QWizardPage ) from novelwriter.common import makeFileNameSafe @@ -111,7 +110,6 @@ class ProjWizardIntroPage(QWizardPage): self.imgCredit.setFont(lblFont) xW = self.mainConf.pxInt(300) - xH = self.mainConf.pxInt(100) vS = self.mainConf.pxInt(12) fS = self.mainConf.pxInt(4) @@ -126,20 +124,20 @@ class ProjWizardIntroPage(QWizardPage): self.projTitle.setFixedWidth(xW) self.projTitle.setPlaceholderText(self.tr("Optional")) - self.projAuthors = QPlainTextEdit() - self.projAuthors.setFixedHeight(xH) - self.projAuthors.setFixedWidth(xW) - self.projAuthors.setPlaceholderText(self.tr("Optional. One name per line.")) + self.projAuthor = QLineEdit() + self.projAuthor.setMaxLength(200) + self.projAuthor.setFixedWidth(xW) + self.projAuthor.setPlaceholderText(self.tr("Optional")) self.mainForm = QFormLayout() self.mainForm.addRow(self.tr("Project Name"), self.projName) self.mainForm.addRow(self.tr("Novel Title"), self.projTitle) - self.mainForm.addRow(self.tr("Author(s)"), self.projAuthors) + self.mainForm.addRow(self.tr("Author(s)"), self.projAuthor) self.mainForm.setVerticalSpacing(fS) self.registerField("projName*", self.projName) self.registerField("projTitle", self.projTitle) - self.registerField("projAuthors", self.projAuthors, "plainText") + self.registerField("projAuthor", self.projAuthor) # Assemble self.outerBox = QVBoxLayout() diff --git a/sample/content/53b69b83cdafc.nwd b/sample/content/53b69b83cdafc.nwd index 54fd6a26..18f8cab8 100644 --- a/sample/content/53b69b83cdafc.nwd +++ b/sample/content/53b69b83cdafc.nwd @@ -3,7 +3,7 @@ %%~kind: NOVEL/DOCUMENT #! My Novel ->> **By Jane Doh** << +>> **By Jane Smith** << >> This is the title page. << >> It should be the first document of the project. << \ No newline at end of file diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index fe3d9089..1945992d 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,10 +1,9 @@ - - + + Sample Project Sample Project Jane Smith - Jay Doh no @@ -50,7 +49,7 @@ Novel - + Title Page diff --git a/tests/tools.py b/tests/tools.py index 0883dc14..1e446912 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -174,7 +174,7 @@ def buildTestProject(theObject, projPath): theProject.data.setUuid("d0f3fe10-c6e6-4310-8bfd-181eb4224eed") theProject.data.setName("New Project") theProject.data.setTitle("New Novel") - theProject.data.setAuthors("Jane Doe") + theProject.data.setAuthor("Jane Doe") # Creating a minimal project with a few root folders and a # single chapter folder with a single file.