Add new features to new project title page
This commit is contained in:
@@ -39,7 +39,7 @@ from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
from novelwriter.common import isHandle, minmax, simplified
|
||||
from novelwriter.constants import nwConst, nwFiles, nwItemClass
|
||||
from novelwriter.constants import nwConst, nwFiles, nwItemClass, nwStats
|
||||
from novelwriter.core.item import NWItem
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.core.storage import NWStorageCreate
|
||||
@@ -428,7 +428,6 @@ class ProjectBuilder:
|
||||
|
||||
lblNewProject = self.tr("New Project")
|
||||
lblTitlePage = self.tr("Title Page")
|
||||
lblByAuthors = self.tr("By")
|
||||
|
||||
# Settings
|
||||
project.data.setUuid(None)
|
||||
@@ -441,14 +440,29 @@ class ProjectBuilder:
|
||||
# Add Root Folders
|
||||
hNovelRoot = project.newRoot(nwItemClass.NOVEL)
|
||||
hTitlePage = project.newFile(lblTitlePage, hNovelRoot)
|
||||
novelTitle = project.data.name
|
||||
|
||||
titlePage = f"#! {novelTitle}\n\n"
|
||||
if project.data.author:
|
||||
titlePage += f">> {lblByAuthors} {project.data.author} <<\n\n"
|
||||
|
||||
# Generate Title Page
|
||||
aDoc = project.storage.getDocument(hTitlePage)
|
||||
aDoc.writeDocument(titlePage)
|
||||
aDoc.writeDocument((
|
||||
"{author}[br]\n"
|
||||
"{address} 1[br]\n"
|
||||
"{address} 2 <<\n"
|
||||
"\n"
|
||||
"[vspace:5]\n"
|
||||
"\n"
|
||||
"#! {title}\n"
|
||||
"\n"
|
||||
">> **{by} {author}** <<\n"
|
||||
"\n"
|
||||
">> {count}: [field:{field}] <<\n"
|
||||
).format(
|
||||
author=project.data.author or "None",
|
||||
address=self.tr("Address"),
|
||||
title=project.data.name or "None",
|
||||
by=self.tr("By"),
|
||||
count=self.tr("Word Count"),
|
||||
field=nwStats.WORDS_TEXT,
|
||||
))
|
||||
|
||||
# Create a project structure based on selected root folders
|
||||
# and a number of chapters and scenes selected in the
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
Jane Doe
|
||||
Address 1
|
||||
Address 2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Test Project A
|
||||
|
||||
**By Jane Doe**
|
||||
|
||||
Word Count: 11
|
||||
|
||||
## Chapter 1
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
## Chapter 2
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
## Chapter 3
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
Jane Doe
|
||||
Address 1
|
||||
Address 2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Test Project B
|
||||
|
||||
**By Jane Doe**
|
||||
|
||||
Word Count: 11
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
* * *
|
||||
|
||||
@@ -31,10 +31,13 @@ import pytest
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwConst, nwFiles, nwItemClass
|
||||
from novelwriter.core.buildsettings import BuildSettings
|
||||
from novelwriter.core.coretools import (
|
||||
DocDuplicator, DocMerger, DocSearch, DocSplitter, ProjectBuilder
|
||||
)
|
||||
from novelwriter.core.docbuild import NWBuildDocument
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwBuildFmt
|
||||
|
||||
from tests.mocked import causeOSError
|
||||
from tests.tools import NWD_IGNORE, XML_IGNORE, C, buildTestProject, cmpFiles
|
||||
@@ -507,10 +510,6 @@ def testCoreTools_ProjectBuilderA(monkeypatch, fncPath, tstPaths, mockGUI, mockR
|
||||
"""Create a new project from a project dictionary, with chapters."""
|
||||
monkeypatch.setattr("uuid.uuid4", lambda *a: uuid.UUID("d0f3fe10-c6e6-4310-8bfd-181eb4224eed"))
|
||||
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_ProjectBuilderA_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_ProjectBuilderA_nwProject.nwx"
|
||||
|
||||
data = {
|
||||
"name": "Test Project A",
|
||||
"author": "Jane Doe",
|
||||
@@ -531,19 +530,34 @@ def testCoreTools_ProjectBuilderA(monkeypatch, fncPath, tstPaths, mockGUI, mockR
|
||||
builder = ProjectBuilder()
|
||||
assert builder.buildProject(data) is True
|
||||
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_ProjectBuilderA_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_ProjectBuilderA_nwProject.nwx"
|
||||
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE)
|
||||
|
||||
# Check Content
|
||||
project = NWProject()
|
||||
project.openProject(fncPath)
|
||||
|
||||
build = BuildSettings()
|
||||
|
||||
docBuild = NWBuildDocument(project, build)
|
||||
docBuild.queueAll()
|
||||
|
||||
testFile = tstPaths.outDir / "coreTools_ProjectBuilderA_Project.md"
|
||||
compFile = tstPaths.refDir / "coreTools_ProjectBuilderA_Project.md"
|
||||
|
||||
assert list(docBuild.iterBuildDocument(testFile, nwBuildFmt.EXT_MD))
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE)
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_ProjectBuilderB(monkeypatch, fncPath, tstPaths, mockGUI, mockRnd):
|
||||
"""Create a new project from a project dictionary, without chapters."""
|
||||
monkeypatch.setattr("uuid.uuid4", lambda *a: uuid.UUID("d0f3fe10-c6e6-4310-8bfd-181eb4224eed"))
|
||||
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_ProjectBuilderB_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_ProjectBuilderB_nwProject.nwx"
|
||||
|
||||
data = {
|
||||
"name": "Test Project B",
|
||||
"author": "Jane Doe",
|
||||
@@ -564,9 +578,28 @@ def testCoreTools_ProjectBuilderB(monkeypatch, fncPath, tstPaths, mockGUI, mockR
|
||||
builder = ProjectBuilder()
|
||||
assert builder.buildProject(data) is True
|
||||
|
||||
projFile = fncPath / "nwProject.nwx"
|
||||
testFile = tstPaths.outDir / "coreTools_ProjectBuilderB_nwProject.nwx"
|
||||
compFile = tstPaths.refDir / "coreTools_ProjectBuilderB_nwProject.nwx"
|
||||
|
||||
copyfile(projFile, testFile)
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE)
|
||||
|
||||
# Check Content
|
||||
project = NWProject()
|
||||
project.openProject(fncPath)
|
||||
|
||||
build = BuildSettings()
|
||||
|
||||
docBuild = NWBuildDocument(project, build)
|
||||
docBuild.queueAll()
|
||||
|
||||
testFile = tstPaths.outDir / "coreTools_ProjectBuilderB_Project.md"
|
||||
compFile = tstPaths.refDir / "coreTools_ProjectBuilderB_Project.md"
|
||||
|
||||
assert list(docBuild.iterBuildDocument(testFile, nwBuildFmt.EXT_MD))
|
||||
assert cmpFiles(testFile, compFile, ignoreStart=XML_IGNORE)
|
||||
|
||||
|
||||
@pytest.mark.core
|
||||
def testCoreTools_ProjectBuilderCopyPlain(monkeypatch, caplog, mockGUI, prjLipsum, fncPath):
|
||||
|
||||
Reference in New Issue
Block a user