Fixed creating new project, opening and saving of projects.
This commit is contained in:
+15
-1
@@ -39,9 +39,14 @@ class GuiDocTree(QTreeWidget):
|
|||||||
self.debugGUI = self.mainConf.debugGUI
|
self.debugGUI = self.mainConf.debugGUI
|
||||||
self.theParent = theParent
|
self.theParent = theParent
|
||||||
self.theProject = theProject
|
self.theProject = theProject
|
||||||
self.theMap = {}
|
|
||||||
|
# Tree Settings
|
||||||
|
self.theMap = None
|
||||||
self.orphRoot = None
|
self.orphRoot = None
|
||||||
|
|
||||||
|
self.clearTree()
|
||||||
|
|
||||||
|
# Build GUI
|
||||||
self.setIconSize(QSize(13,13))
|
self.setIconSize(QSize(13,13))
|
||||||
self.setExpandsOnDoubleClick(True)
|
self.setExpandsOnDoubleClick(True)
|
||||||
self.setIndentation(13)
|
self.setIndentation(13)
|
||||||
@@ -67,6 +72,15 @@ class GuiDocTree(QTreeWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def clearTree(self):
|
||||||
|
|
||||||
|
self.clear()
|
||||||
|
|
||||||
|
self.theMap = {}
|
||||||
|
self.orphRoot = None
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
def newTreeItem(self, itemType, itemClass):
|
def newTreeItem(self, itemType, itemClass):
|
||||||
|
|
||||||
pHandle = self.getSelectedHandle()
|
pHandle = self.getSelectedHandle()
|
||||||
|
|||||||
+6
-3
@@ -103,6 +103,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
def newProject(self):
|
def newProject(self):
|
||||||
logger.info("Creating new project")
|
logger.info("Creating new project")
|
||||||
|
self.treeView.clearTree()
|
||||||
self.theProject.newProject()
|
self.theProject.newProject()
|
||||||
self.treeView.buildTree()
|
self.treeView.buildTree()
|
||||||
return
|
return
|
||||||
@@ -112,6 +113,7 @@ class GuiMain(QMainWindow):
|
|||||||
projFile = self.openProjectDialog()
|
projFile = self.openProjectDialog()
|
||||||
if projFile is None:
|
if projFile is None:
|
||||||
return False
|
return False
|
||||||
|
self.treeView.clearTree()
|
||||||
self.theProject.openProject(projFile)
|
self.theProject.openProject(projFile)
|
||||||
self.treeView.buildTree()
|
self.treeView.buildTree()
|
||||||
self._setWindowTitle(self.theProject.projName)
|
self._setWindowTitle(self.theProject.projName)
|
||||||
@@ -184,7 +186,7 @@ class GuiMain(QMainWindow):
|
|||||||
dlgOpt = QFileDialog.Options()
|
dlgOpt = QFileDialog.Options()
|
||||||
dlgOpt |= QFileDialog.DontUseNativeDialog
|
dlgOpt |= QFileDialog.DontUseNativeDialog
|
||||||
projFile, _ = QFileDialog.getOpenFileName(
|
projFile, _ = QFileDialog.getOpenFileName(
|
||||||
self,"Open novelWriter Project","","novelWriter Project File (nwProject.nwx);;All Files (*)", options=dlgOpt
|
self,"Open novelWriter Project","","novelWriter Project File (nwProject.nwx);;All Files (*)",options=dlgOpt
|
||||||
)
|
)
|
||||||
if projFile:
|
if projFile:
|
||||||
return projFile
|
return projFile
|
||||||
@@ -192,9 +194,10 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
def saveProjectDialog(self):
|
def saveProjectDialog(self):
|
||||||
dlgOpt = QFileDialog.Options()
|
dlgOpt = QFileDialog.Options()
|
||||||
|
dlgOpt |= QFileDialog.ShowDirsOnly
|
||||||
dlgOpt |= QFileDialog.DontUseNativeDialog
|
dlgOpt |= QFileDialog.DontUseNativeDialog
|
||||||
projPath, _ = QFileDialog.getSaveFileName(
|
projPath = QFileDialog.getExistingDirectory(
|
||||||
self,"Save novelWriter Project","","novelWriter Project File (nwProject.nwx);;All Files (*)", options=dlgOpt
|
self,"Save novelWriter Project","",options=dlgOpt
|
||||||
)
|
)
|
||||||
if projPath:
|
if projPath:
|
||||||
return projPath
|
return projPath
|
||||||
|
|||||||
+55
-33
@@ -31,27 +31,22 @@ class NWProject():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
# Internal
|
# Internal
|
||||||
self.mainConf = nw.CONFIG
|
self.mainConf = nw.CONFIG
|
||||||
|
|
||||||
# Project Settings
|
# Project Settings
|
||||||
self.projTree = {}
|
self.projTree = None
|
||||||
self.treeOrder = []
|
self.treeOrder = None
|
||||||
self.treeRoots = []
|
self.treeRoots = None
|
||||||
self.projPath = None
|
self.projPath = None
|
||||||
self.projFile = "nwProject.nwx"
|
self.projFile = None
|
||||||
self.projName = ""
|
self.projName = None
|
||||||
self.bookTitle = ""
|
self.bookTitle = None
|
||||||
self.bookAuthors = []
|
self.bookAuthors = None
|
||||||
|
self.statusCols = None
|
||||||
|
self.statusIcons = None
|
||||||
|
self.statusLabels = None
|
||||||
|
|
||||||
self.statusCols = [
|
self.clearProject()
|
||||||
("New", 100,100,100),
|
|
||||||
("Note", 200, 50, 0),
|
|
||||||
("Draft", 200,150, 0),
|
|
||||||
("Finished", 50,200, 0),
|
|
||||||
]
|
|
||||||
self.statusIcons = []
|
|
||||||
self.statusLabels = []
|
|
||||||
self._makeStatusIcons()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -88,19 +83,39 @@ class NWProject():
|
|||||||
return newItem.itemHandle
|
return newItem.itemHandle
|
||||||
|
|
||||||
def newProject(self):
|
def newProject(self):
|
||||||
self.projTree = {}
|
|
||||||
self.treeOrder = []
|
self.clearProject()
|
||||||
self.projPath = None
|
|
||||||
self.projFile = "nwProject.nwx"
|
|
||||||
self.projName = ""
|
|
||||||
self.bookTitle = ""
|
|
||||||
self.bookAuthors = []
|
|
||||||
self._makeStatusIcons()
|
|
||||||
hNovel = self.newRoot("Novel", nwItemClass.NOVEL)
|
hNovel = self.newRoot("Novel", nwItemClass.NOVEL)
|
||||||
hChars = self.newRoot("Characters", nwItemClass.CHARACTER)
|
hChars = self.newRoot("Characters", nwItemClass.CHARACTER)
|
||||||
hWorld = self.newRoot("World", nwItemClass.WORLD)
|
hWorld = self.newRoot("World", nwItemClass.WORLD)
|
||||||
hChapt = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel)
|
hChapt = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel)
|
||||||
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt)
|
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def clearProject(self):
|
||||||
|
|
||||||
|
# Project Settings
|
||||||
|
self.projTree = {}
|
||||||
|
self.treeOrder = []
|
||||||
|
self.treeRoots = []
|
||||||
|
self.projPath = None
|
||||||
|
self.projFile = "nwProject.nwx"
|
||||||
|
self.projName = ""
|
||||||
|
self.bookTitle = ""
|
||||||
|
self.bookAuthors = []
|
||||||
|
|
||||||
|
self.statusCols = [
|
||||||
|
("New", 100,100,100),
|
||||||
|
("Note", 200, 50, 0),
|
||||||
|
("Draft", 200,150, 0),
|
||||||
|
("Finished", 50,200, 0),
|
||||||
|
]
|
||||||
|
self.statusIcons = []
|
||||||
|
self.statusLabels = []
|
||||||
|
self._makeStatusIcons()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -115,6 +130,7 @@ class NWProject():
|
|||||||
logger.error("File not found: %s" % fileName)
|
logger.error("File not found: %s" % fileName)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self.clearProject()
|
||||||
self.projPath = path.dirname(fileName)
|
self.projPath = path.dirname(fileName)
|
||||||
logger.debug("Opening project: %s" % self.projPath)
|
logger.debug("Opening project: %s" % self.projPath)
|
||||||
|
|
||||||
@@ -211,13 +227,19 @@ class NWProject():
|
|||||||
self.projTree[tHandle].packXML(xContent)
|
self.projTree[tHandle].packXML(xContent)
|
||||||
|
|
||||||
# Write the xml tree to file
|
# Write the xml tree to file
|
||||||
with open(path.join(self.projPath,self.projFile),"wb") as outFile:
|
saveFile = path.join(self.projPath,self.projFile)
|
||||||
outFile.write(etree.tostring(
|
try:
|
||||||
nwXML,
|
with open(saveFile,"wb") as outFile:
|
||||||
pretty_print = True,
|
outFile.write(etree.tostring(
|
||||||
encoding = "utf-8",
|
nwXML,
|
||||||
xml_declaration = True
|
pretty_print = True,
|
||||||
))
|
encoding = "utf-8",
|
||||||
|
xml_declaration = True
|
||||||
|
))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to save project to %s" % saveFile)
|
||||||
|
logger.error(str(e))
|
||||||
|
return False
|
||||||
|
|
||||||
self.mainConf.setRecent(self.projPath)
|
self.mainConf.setRecent(self.projPath)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user