Added open project functionality.
This commit is contained in:
@@ -22,3 +22,4 @@ Future features that will be added:
|
||||
|
||||
* python3-pyqt5
|
||||
* python3-appdirs
|
||||
* python3-lxml
|
||||
|
||||
+15
-3
@@ -37,8 +37,6 @@ class GuiMain(QMainWindow):
|
||||
self.setTitle()
|
||||
self.setWindowIcon(QIcon(path.join(self.mainConf.appPath,"..","novelWriter.svg")))
|
||||
|
||||
self.statBar = self.statusBar()
|
||||
|
||||
self.docEditor = GuiDocEditor()
|
||||
|
||||
self.treePane = QFrame()
|
||||
@@ -65,7 +63,9 @@ class GuiMain(QMainWindow):
|
||||
self.show()
|
||||
|
||||
logger.debug("GUI initialisation complete")
|
||||
self.statBar.showMessage("Ready")
|
||||
|
||||
statBar = self.statusBar()
|
||||
statBar.showMessage("Ready")
|
||||
|
||||
return
|
||||
|
||||
@@ -91,6 +91,17 @@ class GuiMain(QMainWindow):
|
||||
|
||||
return
|
||||
|
||||
def openProject(self):
|
||||
dlgOpt = QFileDialog.Options()
|
||||
dlgOpt |= QFileDialog.DontUseNativeDialog
|
||||
projPath, _ = QFileDialog.getOpenFileName(
|
||||
self,"Open novelWriter Project","","novelWriter Project File (nwProject.nwx);;All Files (*)", options=dlgOpt)
|
||||
if projPath:
|
||||
self.theProject.openProject(projPath)
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
def saveProject(self):
|
||||
if self.theProject.projPath is None:
|
||||
dlgOpt = QFileDialog.Options()
|
||||
@@ -133,6 +144,7 @@ class GuiMain(QMainWindow):
|
||||
# File > Open Project
|
||||
menuOpenProject = QAction(QIcon.fromTheme("folder-open"), "Open Project", menuBar)
|
||||
menuOpenProject.setStatusTip("Open Project")
|
||||
menuOpenProject.triggered.connect(self.openProject)
|
||||
fileMenu.addAction(menuOpenProject)
|
||||
|
||||
# File > Save Project
|
||||
|
||||
+38
-2
@@ -24,8 +24,6 @@ class NWProject():
|
||||
def __init__(self):
|
||||
|
||||
self.mainConf = nw.CONFIG
|
||||
|
||||
self.projFolder = None
|
||||
self.projTree = []
|
||||
|
||||
# Project Settings
|
||||
@@ -40,6 +38,44 @@ class NWProject():
|
||||
|
||||
return True
|
||||
|
||||
def openProject(self, fileName):
|
||||
|
||||
if not path.isfile(fileName):
|
||||
logger.error("File not found: %s" % fileName)
|
||||
return False
|
||||
|
||||
self.projPath = path.dirname(fileName)
|
||||
|
||||
nwXML = etree.parse(fileName)
|
||||
xRoot = nwXML.getroot()
|
||||
|
||||
nwxRoot = xRoot.tag
|
||||
appVersion = xRoot.attrib["appVersion"]
|
||||
fileVersion = xRoot.attrib["fileVersion"]
|
||||
|
||||
logger.verbose("XML root is %s" % nwxRoot)
|
||||
logger.verbose("File version is %s" % fileVersion)
|
||||
|
||||
if not nwxRoot == "novelWriterXML" or not fileVersion == "1.0":
|
||||
logger.error("Project file does not appear to be a novelWriterXML file version 1.0")
|
||||
return False
|
||||
|
||||
# for xChild in xRoot:
|
||||
# if xChild.tag == "book":
|
||||
# logger.debug("BookOpen: Found book data")
|
||||
# for xItem in xChild:
|
||||
# if xItem.text is None: continue
|
||||
# if xItem.tag == "title":
|
||||
# logger.verbose("BookOpen: Title is '%s'" % xItem.text)
|
||||
# self.bookTitle = xItem.text
|
||||
# elif xItem.tag == "author":
|
||||
# logger.verbose("BookOpen: Author: '%s'" % xItem.text)
|
||||
# self.bookAuthors.append(xItem.text)
|
||||
|
||||
self.mainConf.setRecent(self.projPath)
|
||||
|
||||
return True
|
||||
|
||||
def saveProject(self):
|
||||
|
||||
if self.projPath is None:
|
||||
|
||||
Reference in New Issue
Block a user