Added a document header to the build tool document stating when it was generated

This commit is contained in:
Veronica K. B. Olsen
2020-06-23 19:55:19 +02:00
parent e83717f286
commit b47d6b6546
+76 -8
View File
@@ -31,6 +31,7 @@ import nw
from os import path from os import path
from time import time from time import time
from datetime import datetime
from PyQt5.QtCore import Qt, QByteArray from PyQt5.QtCore import Qt, QByteArray
from PyQt5.QtPrintSupport import QPrinter, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrinter, QPrintPreviewDialog
@@ -39,7 +40,7 @@ from PyQt5.QtGui import (
) )
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel, QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel,
QLineEdit, QGroupBox, QGridLayout, QProgressBar, QMenu, QAction, QLineEdit, QGroupBox, QGridLayout, QProgressBar, QMenu, QAction, QFrame,
QFileDialog, QFontDialog, QSpinBox QFileDialog, QFontDialog, QSpinBox
) )
@@ -76,6 +77,7 @@ class GuiBuildNovel(QDialog):
self.htmlText = [] # List of html document self.htmlText = [] # List of html document
self.htmlStyle = [] # List of html styles self.htmlStyle = [] # List of html styles
self.nwdText = [] # List of markdown documents self.nwdText = [] # List of markdown documents
self.buildTime = 0 # The timestamp of the last build
self.setWindowTitle("Build Novel Project") self.setWindowTitle("Build Novel Project")
self.setMinimumWidth(self.mainConf.pxInt(900)) self.setMinimumWidth(self.mainConf.pxInt(900))
@@ -411,11 +413,12 @@ class GuiBuildNovel(QDialog):
self.docView.clearStyleSheet() self.docView.clearStyleSheet()
else: else:
self.docView.setStyleSheet(self.htmlStyle) self.docView.setStyleSheet(self.htmlStyle)
self.docView.setContent(self.htmlText) self.docView.setContent(self.htmlText, self.buildTime)
else: else:
self.htmlText = [] self.htmlText = []
self.htmlStyle = [] self.htmlStyle = []
self.nwdText = [] self.nwdText = []
self.buildTime = 0
return return
@@ -509,6 +512,7 @@ class GuiBuildNovel(QDialog):
tEnd = time() tEnd = time()
logger.debug("Built project in %.3f ms" % (1000*(tEnd-tStart))) logger.debug("Built project in %.3f ms" % (1000*(tEnd-tStart)))
self.htmlStyle = makeHtml.getStyleSheet() self.htmlStyle = makeHtml.getStyleSheet()
self.buildTime = tEnd
# Load the preview document with the html data # Load the preview document with the html data
self.docView.setTextFont(textFont, textSize) self.docView.setTextFont(textFont, textSize)
@@ -517,7 +521,7 @@ class GuiBuildNovel(QDialog):
self.docView.clearStyleSheet() self.docView.clearStyleSheet()
else: else:
self.docView.setStyleSheet(self.htmlStyle) self.docView.setStyleSheet(self.htmlStyle)
self.docView.setContent(self.htmlText) self.docView.setContent(self.htmlText, self.buildTime)
self._saveCache() self._saveCache()
@@ -694,6 +698,7 @@ class GuiBuildNovel(QDialog):
"workingTitle" : self.theProject.projName, "workingTitle" : self.theProject.projName,
"novelTitle" : self.theProject.bookTitle, "novelTitle" : self.theProject.bookTitle,
"authors" : self.theProject.bookAuthors, "authors" : self.theProject.bookAuthors,
"buildTime" : self.buildTime,
} }
} }
@@ -808,6 +813,8 @@ class GuiBuildNovel(QDialog):
if "nwdText" in theData.keys(): if "nwdText" in theData.keys():
self.nwdText = theData["nwdText"] self.nwdText = theData["nwdText"]
dataCount += 1 dataCount += 1
if "buildTime" in theData.keys():
self.buildTime = theData["buildTime"]
return dataCount == 3 return dataCount == 3
@@ -828,6 +835,7 @@ class GuiBuildNovel(QDialog):
"htmlText" : self.htmlText, "htmlText" : self.htmlText,
"htmlStyle" : self.htmlStyle, "htmlStyle" : self.htmlStyle,
"nwdText" : self.nwdText, "nwdText" : self.nwdText,
"buildTime" : self.buildTime,
}, indent=nIndent)) }, indent=nIndent))
except Exception as e: except Exception as e:
logger.error("Failed to save build cache") logger.error("Failed to save build cache")
@@ -924,12 +932,13 @@ class GuiBuildNovelDocView(QTextBrowser):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theProject = theProject self.theProject = theProject
self.theParent = theParent self.theParent = theParent
self.theTheme = theParent.theTheme
self.setMinimumWidth(40*self.theParent.theTheme.textNWidth) self.setMinimumWidth(40*self.theParent.theTheme.textNWidth)
self.setOpenExternalLinks(False) self.setOpenExternalLinks(False)
self.qDocument = self.document() self.qDocument = self.document()
self.qDocument.setDocumentMargin(self.mainConf.textMargin) self.qDocument.setDocumentMargin(self.mainConf.getTextMargin())
self.setPlaceholderText( self.setPlaceholderText(
"This area will show the content of the document to be " "This area will show the content of the document to be "
"exported or printed. Press the \"Build Novel Project\" " "exported or printed. Press the \"Build Novel Project\" "
@@ -946,12 +955,29 @@ class GuiBuildNovelDocView(QTextBrowser):
docPalette = self.palette() docPalette = self.palette()
docPalette.setColor(QPalette.Base, QColor(255, 255, 255)) docPalette.setColor(QPalette.Base, QColor(255, 255, 255))
docPalette.setColor(QPalette.Text, QColor( 0, 0, 0)) docPalette.setColor(QPalette.Text, QColor(0, 0, 0))
self.setPalette(docPalette) self.setPalette(docPalette)
self.setStyleSheet() lblPalette = self.palette()
lblPalette.setColor(QPalette.Background, lblPalette.toolTipBase().color())
lblPalette.setColor(QPalette.Foreground, lblPalette.toolTipText().color())
self.show() lblFont = self.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
fPx = int(1.1*self.theTheme.fontPixelSize)
mPx = self.mainConf.pxInt(4)
self.theTitle = QLabel("", self)
self.theTitle.setIndent(0)
self.theTitle.setAutoFillBackground(True)
self.theTitle.setAlignment(Qt.AlignCenter)
self.theTitle.setFixedHeight(fPx)
self.theTitle.setPalette(lblPalette)
self.theTitle.setFont(lblFont)
self._updateDocMargins()
self.setStyleSheet()
logger.debug("GuiBuildNovelDocView initialisation complete") logger.debug("GuiBuildNovelDocView initialisation complete")
@@ -977,15 +1003,23 @@ class GuiBuildNovelDocView(QTextBrowser):
self.setFont(theFont) self.setFont(theFont)
return return
def setContent(self, theText): def setContent(self, theText, timeStamp):
"""Set the content, either from text or list of text. """Set the content, either from text or list of text.
""" """
if isinstance(theText, list): if isinstance(theText, list):
theText = "".join(theText) theText = "".join(theText)
theText = theText.replace(" ", " "*4) theText = theText.replace(" ", " "*4)
theText = theText.replace("<del>", "<span style='text-decoration: line-through;'>") theText = theText.replace("<del>", "<span style='text-decoration: line-through;'>")
theText = theText.replace("</del>", "</span>") theText = theText.replace("</del>", "</span>")
self.setHtml(theText) self.setHtml(theText)
if timeStamp > 0:
strBuildTime = datetime.fromtimestamp(timeStamp).strftime("%x %X")
else:
strBuildTime = "Unknown"
self.theTitle.setText("Build Time: %s" % strBuildTime)
return return
def setStyleSheet(self, theStyles=[]): def setStyleSheet(self, theStyles=[]):
@@ -1007,4 +1041,38 @@ class GuiBuildNovelDocView(QTextBrowser):
self.qDocument.setDefaultStyleSheet("") self.qDocument.setDefaultStyleSheet("")
return return
##
# Events
##
def resizeEvent(self, theEvent):
"""Make sure the document title is the same width as the window.
"""
QTextBrowser.resizeEvent(self, theEvent)
self._updateDocMargins()
return
##
# Internal Functions
##
def _updateDocMargins(self):
"""Automatically adjust the header to fill the top of the
document within the viewport.
"""
vBar = self.verticalScrollBar()
if vBar.isVisible():
sW = vBar.width()
else:
sW = 0
tB = self.frameWidth()
tW = self.width() - 2*tB - sW
tH = self.theTitle.height()
self.theTitle.setGeometry(tB, tB, tW, tH)
self.setViewportMargins(0, tH, 0, 0)
return
# END Class GuiBuildNovelDocView # END Class GuiBuildNovelDocView