Wizard can now make a minimal project
This commit is contained in:
+64
-15
@@ -171,20 +171,53 @@ class NWProject():
|
||||
# Project Methods
|
||||
##
|
||||
|
||||
def newProject(self):
|
||||
def newProject(self, projData={}):
|
||||
"""Create a new project by populating the project tree with a
|
||||
few starter items.
|
||||
"""
|
||||
self.projName = "New Project"
|
||||
hNovel = self.newRoot("Novel", nwItemClass.NOVEL)
|
||||
hChars = self.newRoot("Characters", nwItemClass.CHARACTER)
|
||||
hWorld = self.newRoot("Plot", nwItemClass.PLOT)
|
||||
hWorld = self.newRoot("World", nwItemClass.WORLD)
|
||||
hChapt = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel)
|
||||
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt)
|
||||
print(projData)
|
||||
# Project Title and Authors
|
||||
if "projName" in projData:
|
||||
self.setProjectName(projData["projName"])
|
||||
else:
|
||||
self.setProjectName("New Project")
|
||||
if "projTitle" in projData:
|
||||
self.setBookTitle(projData["projTitle"])
|
||||
if "projAuthors" in projData:
|
||||
self.setBookAuthors(projData["projAuthors"])
|
||||
|
||||
popMinimal = True
|
||||
popSample = False
|
||||
popCustom = False
|
||||
if "popMinimal" in projData:
|
||||
popMinimal = projData["popMinimal"]
|
||||
if "popSample" in projData:
|
||||
popSample = projData["popSample"]
|
||||
if "popCustom" in projData:
|
||||
popCustom = projData["popCustom"]
|
||||
|
||||
if popMinimal:
|
||||
hNovel = self.newRoot("Novel", nwItemClass.NOVEL)
|
||||
hChars = self.newRoot("Characters", nwItemClass.CHARACTER)
|
||||
hWorld = self.newRoot("Plot", nwItemClass.PLOT)
|
||||
hWorld = self.newRoot("World", nwItemClass.WORLD)
|
||||
hChapF = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel)
|
||||
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapF)
|
||||
|
||||
elif popSample:
|
||||
pass
|
||||
|
||||
elif popCustom:
|
||||
pass
|
||||
|
||||
else:
|
||||
# Fallback just in case.
|
||||
self.newRoot("Novel", nwItemClass.NOVEL)
|
||||
|
||||
self.projOpened = time()
|
||||
self.setProjectChanged(True)
|
||||
self.saveProject(autoSave=True)
|
||||
|
||||
return True
|
||||
|
||||
def clearProject(self):
|
||||
@@ -728,13 +761,24 @@ class NWProject():
|
||||
projPath = path.expanduser(projPath)
|
||||
self.projPath = path.abspath(projPath)
|
||||
|
||||
if newProject and self.mainConf.showGUI:
|
||||
if listdir(self.projPath):
|
||||
self.theParent.makeAlert((
|
||||
"New project folder is not empty. "
|
||||
"Each project requires a dedicated project folder."
|
||||
), nwAlert.ERROR)
|
||||
return False
|
||||
if newProject:
|
||||
if not path.isdir(projPath):
|
||||
try:
|
||||
mkdir(projPath)
|
||||
logger.debug("Created folder %s" % projPath)
|
||||
except Exception as e:
|
||||
self.theParent.makeAlert((
|
||||
["Could not create new project folder.", str(e)]
|
||||
), nwAlert.ERROR)
|
||||
return False
|
||||
|
||||
if path.isdir(projPath):
|
||||
if self.mainConf.showGUI and listdir(self.projPath):
|
||||
self.theParent.makeAlert((
|
||||
"New project folder is not empty. "
|
||||
"Each project requires a dedicated project folder."
|
||||
), nwAlert.ERROR)
|
||||
return False
|
||||
|
||||
self.ensureFolderStructure()
|
||||
self.setProjectChanged(True)
|
||||
@@ -759,13 +803,18 @@ class NWProject():
|
||||
def setBookAuthors(self, bookAuthors):
|
||||
"""A line separated list of book authors, parsed into an array.
|
||||
"""
|
||||
if not isinstance(bookAuthors, str):
|
||||
return False
|
||||
|
||||
self.bookAuthors = []
|
||||
for bookAuthor in bookAuthors.split("\n"):
|
||||
bookAuthor = bookAuthor.strip()
|
||||
if bookAuthor == "":
|
||||
continue
|
||||
self.bookAuthors.append(bookAuthor)
|
||||
|
||||
self.setProjectChanged(True)
|
||||
|
||||
return True
|
||||
|
||||
def setProjBackup(self, doBackup):
|
||||
|
||||
@@ -139,7 +139,7 @@ class ProjWizardIntroPage(QWizardPage):
|
||||
|
||||
self.registerField("projName*", self.projName)
|
||||
self.registerField("projTitle", self.projTitle)
|
||||
self.registerField("projAuthors", self.projAuthors)
|
||||
self.registerField("projAuthors", self.projAuthors, "plainText")
|
||||
|
||||
# Assemble
|
||||
self.outerBox = QVBoxLayout()
|
||||
|
||||
+43
-13
@@ -47,7 +47,7 @@ from nw.gui import (
|
||||
GuiAbout
|
||||
)
|
||||
from nw.core import NWProject, NWDoc, NWIndex
|
||||
from nw.constants import nwItemType, nwAlert
|
||||
from nw.constants import nwItemType, nwItemClass, nwAlert
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -274,8 +274,12 @@ class GuiMain(QMainWindow):
|
||||
)
|
||||
return False
|
||||
|
||||
projData = {}
|
||||
if projPath is None:
|
||||
projPath = self.newProjectDialog()
|
||||
projData = self.newProjectDialog()
|
||||
if "projPath" in projData:
|
||||
projPath = projData["projPath"]
|
||||
|
||||
if projPath is None:
|
||||
return False
|
||||
|
||||
@@ -289,12 +293,13 @@ class GuiMain(QMainWindow):
|
||||
|
||||
logger.info("Creating new project")
|
||||
if self.theProject.setProjectPath(projPath, newProject=True):
|
||||
self.theProject.newProject()
|
||||
self.theProject.newProject(projData)
|
||||
self.rebuildTree()
|
||||
self.saveProject()
|
||||
self.hasProject = True
|
||||
self.statusBar.setRefTime(self.theProject.projOpened)
|
||||
else:
|
||||
self.theProject.clearProject()
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -767,19 +772,44 @@ class GuiMain(QMainWindow):
|
||||
return None
|
||||
|
||||
def newProjectDialog(self):
|
||||
"""Select where to save new project.
|
||||
"""Open the wizard and assemble the project options dict.
|
||||
"""
|
||||
newProj = GuiProjectWizard(self)
|
||||
newProj.exec_()
|
||||
# dlgOpt = QFileDialog.Options()
|
||||
# dlgOpt |= QFileDialog.ShowDirsOnly
|
||||
# dlgOpt |= QFileDialog.DontUseNativeDialog
|
||||
# projPath = QFileDialog.getExistingDirectory(
|
||||
# self, "Select Location for New novelWriter Project", "", options=dlgOpt
|
||||
# )
|
||||
# if projPath:
|
||||
# return projPath
|
||||
return None
|
||||
|
||||
projData = {
|
||||
"projName": newProj.field("projName"),
|
||||
"projTitle": newProj.field("projTitle"),
|
||||
"projAuthors": newProj.field("projAuthors"),
|
||||
"projPath": newProj.field("projPath"),
|
||||
"popSample": newProj.field("popSample"),
|
||||
"popMinimal": newProj.field("popMinimal"),
|
||||
"popCustom": newProj.field("popCustom"),
|
||||
"addRoots": [],
|
||||
"numChapters": 0,
|
||||
"numScenes": 0,
|
||||
"chFolders": False,
|
||||
}
|
||||
if newProj.field("popCustom"):
|
||||
addRoots = []
|
||||
if newProj.field("addPlot"):
|
||||
addRoots.append(nwItemClass.PLOT)
|
||||
if newProj.field("addChar"):
|
||||
addRoots.append(nwItemClass.CHARACTER)
|
||||
if newProj.field("addWorld"):
|
||||
addRoots.append(nwItemClass.WORLD)
|
||||
if newProj.field("addTime"):
|
||||
addRoots.append(nwItemClass.TIMELINE)
|
||||
if newProj.field("addObject"):
|
||||
addRoots.append(nwItemClass.OBJECT)
|
||||
if newProj.field("addEntity"):
|
||||
addRoots.append(nwItemClass.ENTITY)
|
||||
projData["addRoots"] = addRoots
|
||||
projData["numChapters"] = newProj.field("numChapters")
|
||||
projData["numScenes"] = newProj.field("numScenes")
|
||||
projData["chFolders"] = newProj.field("chFolders")
|
||||
|
||||
return projData
|
||||
|
||||
def editConfigDialog(self):
|
||||
"""Open the preferences dialog.
|
||||
|
||||
Reference in New Issue
Block a user