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