Performance improvements to Build and Writing Stats, and making sure only one of each can be opened
This commit is contained in:
@@ -29,6 +29,8 @@ import logging
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import qApp
|
||||||
|
|
||||||
from nw.constants import nwConst, nwUnicode
|
from nw.constants import nwConst, nwUnicode
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -251,3 +253,11 @@ def makeFileNameSafe(theText):
|
|||||||
if c.isalpha() or c.isdigit() or c == " ":
|
if c.isalpha() or c.isdigit() or c == " ":
|
||||||
cleanName += c
|
cleanName += c
|
||||||
return cleanName
|
return cleanName
|
||||||
|
|
||||||
|
def getGuiItem(theName):
|
||||||
|
"""Returns a QtWidget based on its objectName.
|
||||||
|
"""
|
||||||
|
for qWidget in qApp.topLevelWidgets():
|
||||||
|
if qWidget.objectName() == theName:
|
||||||
|
return qWidget
|
||||||
|
return None
|
||||||
|
|||||||
+23
-12
@@ -36,10 +36,10 @@ from datetime import datetime
|
|||||||
from PyQt5.QtCore import Qt, QByteArray, QTimer
|
from PyQt5.QtCore import Qt, QByteArray, QTimer
|
||||||
from PyQt5.QtPrintSupport import QPrinter, QPrintPreviewDialog
|
from PyQt5.QtPrintSupport import QPrinter, QPrintPreviewDialog
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QPalette, QColor, QTextDocumentWriter, QFont
|
QPalette, QColor, QTextDocumentWriter, QFont, QCursor
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel,
|
qApp, QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel,
|
||||||
QLineEdit, QGroupBox, QGridLayout, QProgressBar, QMenu, QAction,
|
QLineEdit, QGroupBox, QGridLayout, QProgressBar, QMenu, QAction,
|
||||||
QFileDialog, QFontDialog, QSpinBox, QScrollArea, QSplitter, QWidget,
|
QFileDialog, QFontDialog, QSpinBox, QScrollArea, QSplitter, QWidget,
|
||||||
QSizePolicy
|
QSizePolicy
|
||||||
@@ -483,7 +483,11 @@ class GuiBuildNovel(QDialog):
|
|||||||
|
|
||||||
logger.debug("GuiBuildNovel initialisation complete")
|
logger.debug("GuiBuildNovel initialisation complete")
|
||||||
|
|
||||||
# Load from Cache
|
return
|
||||||
|
|
||||||
|
def viewCachedDoc(self):
|
||||||
|
"""Load the previously generated document from cache.
|
||||||
|
"""
|
||||||
if self._loadCache():
|
if self._loadCache():
|
||||||
textFont = self.textFont.text()
|
textFont = self.textFont.text()
|
||||||
textSize = self.textSize.value()
|
textSize = self.textSize.value()
|
||||||
@@ -497,19 +501,22 @@ class GuiBuildNovel(QDialog):
|
|||||||
|
|
||||||
htmlSize = sum([len(x) for x in self.htmlText])
|
htmlSize = sum([len(x) for x in self.htmlText])
|
||||||
if htmlSize < nwConst.maxBuildSize:
|
if htmlSize < nwConst.maxBuildSize:
|
||||||
|
qApp.processEvents()
|
||||||
self.docView.setContent(self.htmlText, self.buildTime)
|
self.docView.setContent(self.htmlText, self.buildTime)
|
||||||
else:
|
else:
|
||||||
self.docView.setText(
|
self.docView.setText(
|
||||||
"Failed to generate preview. The result is too big."
|
"Failed to generate preview. The result is too big."
|
||||||
)
|
)
|
||||||
self._enableQtSave(False)
|
self._enableQtSave(False)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.htmlText = []
|
self.htmlText = []
|
||||||
self.htmlStyle = []
|
self.htmlStyle = []
|
||||||
self.nwdText = []
|
self.nwdText = []
|
||||||
self.buildTime = 0
|
self.buildTime = 0
|
||||||
|
return False
|
||||||
|
|
||||||
return
|
return True
|
||||||
|
|
||||||
##
|
##
|
||||||
# Slots
|
# Slots
|
||||||
@@ -578,6 +585,7 @@ class GuiBuildNovel(QDialog):
|
|||||||
makeHtml.doConvert()
|
makeHtml.doConvert()
|
||||||
self.htmlText.append(makeHtml.getResult())
|
self.htmlText.append(makeHtml.getResult())
|
||||||
self.nwdText.append(makeHtml.getFilteredMarkdown())
|
self.nwdText.append(makeHtml.getFilteredMarkdown())
|
||||||
|
htmlSize += makeHtml.getResultSize()
|
||||||
|
|
||||||
elif self._checkInclude(tItem, noteFiles, novelFiles, ignoreFlag):
|
elif self._checkInclude(tItem, noteFiles, novelFiles, ignoreFlag):
|
||||||
makeHtml.setText(tItem.itemHandle)
|
makeHtml.setText(tItem.itemHandle)
|
||||||
@@ -640,7 +648,6 @@ class GuiBuildNovel(QDialog):
|
|||||||
self.docView.setText(
|
self.docView.setText(
|
||||||
"Failed to generate preview. The result is too big."
|
"Failed to generate preview. The result is too big."
|
||||||
)
|
)
|
||||||
allowQtSave = False
|
|
||||||
self._enableQtSave(False)
|
self._enableQtSave(False)
|
||||||
|
|
||||||
self._saveCache()
|
self._saveCache()
|
||||||
@@ -981,7 +988,8 @@ class GuiBuildNovel(QDialog):
|
|||||||
"""Capture the user closing the window so we can save settings.
|
"""Capture the user closing the window so we can save settings.
|
||||||
"""
|
"""
|
||||||
self._saveSettings()
|
self._saveSettings()
|
||||||
QDialog.closeEvent(self, theEvent)
|
self.docView.clear()
|
||||||
|
theEvent.accept()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -1099,6 +1107,12 @@ class GuiBuildNovelDocView(QTextBrowser):
|
|||||||
theFont.setPointSize(self.mainConf.textSize)
|
theFont.setPointSize(self.mainConf.textSize)
|
||||||
self.setFont(theFont)
|
self.setFont(theFont)
|
||||||
|
|
||||||
|
# Set the tab stops
|
||||||
|
if self.mainConf.verQtValue >= 51000:
|
||||||
|
self.setTabStopDistance(self.mainConf.getTabWidth())
|
||||||
|
else:
|
||||||
|
self.setTabStopWidth(self.mainConf.getTabWidth())
|
||||||
|
|
||||||
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))
|
||||||
@@ -1162,17 +1176,13 @@ class GuiBuildNovelDocView(QTextBrowser):
|
|||||||
|
|
||||||
self.buildTime = timeStamp
|
self.buildTime = timeStamp
|
||||||
sPos = self.verticalScrollBar().value()
|
sPos = self.verticalScrollBar().value()
|
||||||
|
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||||
# Refresh the tab stops
|
|
||||||
if self.mainConf.verQtValue >= 51000:
|
|
||||||
self.setTabStopDistance(self.mainConf.getTabWidth())
|
|
||||||
else:
|
|
||||||
self.setTabStopWidth(self.mainConf.getTabWidth())
|
|
||||||
|
|
||||||
theText = theText.replace("\t", "!!tab!!")
|
theText = theText.replace("\t", "!!tab!!")
|
||||||
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)
|
||||||
|
qApp.processEvents()
|
||||||
|
|
||||||
while self.find("!!tab!!"):
|
while self.find("!!tab!!"):
|
||||||
theCursor = self.textCursor()
|
theCursor = self.textCursor()
|
||||||
@@ -1184,6 +1194,7 @@ class GuiBuildNovelDocView(QTextBrowser):
|
|||||||
# Since we change the content while it may still be rendering, we mark
|
# Since we change the content while it may still be rendering, we mark
|
||||||
# the document dirty again to make sure it's re-rendered properly.
|
# the document dirty again to make sure it's re-rendered properly.
|
||||||
self.qDocument.markContentsDirty(0, self.qDocument.characterCount())
|
self.qDocument.markContentsDirty(0, self.qDocument.characterCount())
|
||||||
|
qApp.restoreOverrideCursor()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import os
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtGui import QPixmap
|
from PyQt5.QtGui import QPixmap, QCursor
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
qApp, QDialog, QTreeWidget, QTreeWidgetItem, QDialogButtonBox, QGridLayout,
|
qApp, QDialog, QTreeWidget, QTreeWidgetItem, QDialogButtonBox, QGridLayout,
|
||||||
QLabel, QGroupBox, QMenu, QAction, QFileDialog, QSpinBox, QHBoxLayout
|
QLabel, QGroupBox, QMenu, QAction, QFileDialog, QSpinBox, QHBoxLayout
|
||||||
@@ -253,10 +253,15 @@ class GuiWritingStats(QDialog):
|
|||||||
|
|
||||||
logger.debug("GuiWritingStats initialisation complete")
|
logger.debug("GuiWritingStats initialisation complete")
|
||||||
|
|
||||||
qApp.processEvents()
|
return
|
||||||
|
|
||||||
|
def populateGUI(self):
|
||||||
|
"""Populate list box with data from the log file.
|
||||||
|
"""
|
||||||
|
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||||
self._loadLogFile()
|
self._loadLogFile()
|
||||||
self._updateListBox()
|
self._updateListBox()
|
||||||
|
qApp.restoreOverrideCursor()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|||||||
+15
-2
@@ -48,6 +48,7 @@ from nw.gui import (
|
|||||||
)
|
)
|
||||||
from nw.core import NWProject, NWDoc, NWIndex
|
from nw.core import NWProject, NWDoc, NWIndex
|
||||||
from nw.constants import nwItemType, nwItemClass, nwAlert
|
from nw.constants import nwItemType, nwItemClass, nwAlert
|
||||||
|
from nw.common import getGuiItem
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -816,9 +817,15 @@ class GuiMain(QMainWindow):
|
|||||||
logger.error("No project open")
|
logger.error("No project open")
|
||||||
return
|
return
|
||||||
|
|
||||||
dlgBuild = GuiBuildNovel(self, self.theProject)
|
dlgBuild = getGuiItem("GuiBuildNovel")
|
||||||
|
if dlgBuild is None:
|
||||||
|
dlgBuild = GuiBuildNovel(self, self.theProject)
|
||||||
|
|
||||||
dlgBuild.setModal(False)
|
dlgBuild.setModal(False)
|
||||||
dlgBuild.show()
|
dlgBuild.show()
|
||||||
|
qApp.processEvents()
|
||||||
|
dlgBuild.viewCachedDoc()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def showWritingStatsDialog(self):
|
def showWritingStatsDialog(self):
|
||||||
@@ -828,9 +835,15 @@ class GuiMain(QMainWindow):
|
|||||||
logger.error("No project open")
|
logger.error("No project open")
|
||||||
return
|
return
|
||||||
|
|
||||||
dlgStats = GuiWritingStats(self, self.theProject)
|
dlgStats = getGuiItem("GuiWritingStats")
|
||||||
|
if dlgStats is None:
|
||||||
|
dlgStats = GuiWritingStats(self, self.theProject)
|
||||||
|
|
||||||
dlgStats.setModal(False)
|
dlgStats.setModal(False)
|
||||||
dlgStats.show()
|
dlgStats.show()
|
||||||
|
qApp.processEvents()
|
||||||
|
dlgStats.populateGUI()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def showAboutNWDialog(self):
|
def showAboutNWDialog(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user