The build dialog should show the result from last build when opening

This commit is contained in:
Veronica K. B. Olsen
2020-05-31 13:38:16 +02:00
parent e9fd3f6fa4
commit 199ecc28e3
2 changed files with 73 additions and 1 deletions
+1
View File
@@ -45,6 +45,7 @@ class nwFiles():
INDEX_FILE = "tagsIndex.json"
OPTS_FILE = "guiOptions.json"
RECENT_FILE = "recentProjects.json"
BUILD_CACHE = "prevBuild.json"
# END Class nwFiles
+72 -1
View File
@@ -26,6 +26,7 @@
"""
import logging
import json
import nw
from os import path
@@ -45,7 +46,7 @@ from PyQt5.QtWidgets import (
from nw.gui.additions import QSwitch
from nw.core import ToHtml
from nw.constants import (
nwAlert, nwItemType, nwItemLayout, nwItemClass
nwAlert, nwFiles, nwItemType, nwItemLayout, nwItemClass
)
logger = logging.getLogger(__name__)
@@ -372,6 +373,15 @@ class GuiBuildNovel(QDialog):
logger.debug("GuiBuildNovel initialisation complete")
# Load from Cache
if self._loadCache():
self.docView.setStyleSheet(self.htmlStyle)
self.docView.setContent(self.htmlText)
else:
self.htmlText = []
self.htmlStyle = []
self.nwdText = []
return
##
@@ -459,6 +469,8 @@ class GuiBuildNovel(QDialog):
self.docView.setStyleSheet(self.htmlStyle)
self.docView.setContent(self.htmlText)
self._saveCache()
return
def _checkInclude(self, theItem, noteFiles, novelFiles, ignoreFlag):
@@ -683,6 +695,60 @@ class GuiBuildNovel(QDialog):
self.textSize.setValue(theFont.pointSize())
return
def _loadCache(self):
"""Save the current data to cache.
"""
buildCache = path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
dataCount = 0
if path.isfile(buildCache):
logger.debug("Loading build cache")
try:
with open(buildCache, mode="r", encoding="utf8") as inFile:
theJson = inFile.read()
theData = json.loads(theJson)
except Exception as e:
logger.error("Failed to load build cache")
logger.error(str(e))
return False
if "htmlText" in theData.keys():
self.htmlText = theData["htmlText"]
dataCount += 1
if "htmlStyle" in theData.keys():
self.htmlStyle = theData["htmlStyle"]
dataCount += 1
if "nwdText" in theData.keys():
self.nwdText = theData["nwdText"]
dataCount += 1
return dataCount == 3
def _saveCache(self):
"""Save the current data to cache.
"""
buildCache = path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
if self.mainConf.debugInfo:
nIndent = 2
else:
nIndent = None
logger.debug("Saving build cache")
try:
with open(buildCache, mode="w+", encoding="utf8") as outFile:
outFile.write(json.dumps({
"htmlText" : self.htmlText,
"htmlStyle" : self.htmlStyle,
"nwdText" : self.nwdText,
}, indent=nIndent))
except Exception as e:
logger.error("Failed to save build cache")
logger.error(str(e))
return False
return True
def _doClose(self):
"""Close button was clicked.
"""
@@ -762,6 +828,11 @@ class GuiBuildNovelDocView(QTextBrowser):
self.qDocument = self.document()
self.qDocument.setDocumentMargin(self.mainConf.textMargin)
self.setPlaceholderText(
"This area will show the content of the document to be "
"exported or printed. Press the \"Build Novel Project\" "
"button to generate content."
)
theFont = QFont()
if self.mainConf.textFont is None: