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 PyQt5.QtWidgets import qApp
|
||||
|
||||
from nw.constants import nwConst, nwUnicode
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -251,3 +253,11 @@ def makeFileNameSafe(theText):
|
||||
if c.isalpha() or c.isdigit() or c == " ":
|
||||
cleanName += c
|
||||
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.QtPrintSupport import QPrinter, QPrintPreviewDialog
|
||||
from PyQt5.QtGui import (
|
||||
QPalette, QColor, QTextDocumentWriter, QFont
|
||||
QPalette, QColor, QTextDocumentWriter, QFont, QCursor
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel,
|
||||
qApp, QDialog, QVBoxLayout, QHBoxLayout, QTextBrowser, QPushButton, QLabel,
|
||||
QLineEdit, QGroupBox, QGridLayout, QProgressBar, QMenu, QAction,
|
||||
QFileDialog, QFontDialog, QSpinBox, QScrollArea, QSplitter, QWidget,
|
||||
QSizePolicy
|
||||
@@ -483,7 +483,11 @@ class GuiBuildNovel(QDialog):
|
||||
|
||||
logger.debug("GuiBuildNovel initialisation complete")
|
||||
|
||||
# Load from Cache
|
||||
return
|
||||
|
||||
def viewCachedDoc(self):
|
||||
"""Load the previously generated document from cache.
|
||||
"""
|
||||
if self._loadCache():
|
||||
textFont = self.textFont.text()
|
||||
textSize = self.textSize.value()
|
||||
@@ -497,19 +501,22 @@ class GuiBuildNovel(QDialog):
|
||||
|
||||
htmlSize = sum([len(x) for x in self.htmlText])
|
||||
if htmlSize < nwConst.maxBuildSize:
|
||||
qApp.processEvents()
|
||||
self.docView.setContent(self.htmlText, self.buildTime)
|
||||
else:
|
||||
self.docView.setText(
|
||||
"Failed to generate preview. The result is too big."
|
||||
)
|
||||
self._enableQtSave(False)
|
||||
|
||||
else:
|
||||
self.htmlText = []
|
||||
self.htmlStyle = []
|
||||
self.nwdText = []
|
||||
self.buildTime = 0
|
||||
return False
|
||||
|
||||
return
|
||||
return True
|
||||
|
||||
##
|
||||
# Slots
|
||||
@@ -578,6 +585,7 @@ class GuiBuildNovel(QDialog):
|
||||
makeHtml.doConvert()
|
||||
self.htmlText.append(makeHtml.getResult())
|
||||
self.nwdText.append(makeHtml.getFilteredMarkdown())
|
||||
htmlSize += makeHtml.getResultSize()
|
||||
|
||||
elif self._checkInclude(tItem, noteFiles, novelFiles, ignoreFlag):
|
||||
makeHtml.setText(tItem.itemHandle)
|
||||
@@ -640,7 +648,6 @@ class GuiBuildNovel(QDialog):
|
||||
self.docView.setText(
|
||||
"Failed to generate preview. The result is too big."
|
||||
)
|
||||
allowQtSave = False
|
||||
self._enableQtSave(False)
|
||||
|
||||
self._saveCache()
|
||||
@@ -981,7 +988,8 @@ class GuiBuildNovel(QDialog):
|
||||
"""Capture the user closing the window so we can save settings.
|
||||
"""
|
||||
self._saveSettings()
|
||||
QDialog.closeEvent(self, theEvent)
|
||||
self.docView.clear()
|
||||
theEvent.accept()
|
||||
return
|
||||
|
||||
##
|
||||
@@ -1099,6 +1107,12 @@ class GuiBuildNovelDocView(QTextBrowser):
|
||||
theFont.setPointSize(self.mainConf.textSize)
|
||||
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.setColor(QPalette.Base, QColor(255, 255, 255))
|
||||
docPalette.setColor(QPalette.Text, QColor(0, 0, 0))
|
||||
@@ -1162,17 +1176,13 @@ class GuiBuildNovelDocView(QTextBrowser):
|
||||
|
||||
self.buildTime = timeStamp
|
||||
sPos = self.verticalScrollBar().value()
|
||||
|
||||
# Refresh the tab stops
|
||||
if self.mainConf.verQtValue >= 51000:
|
||||
self.setTabStopDistance(self.mainConf.getTabWidth())
|
||||
else:
|
||||
self.setTabStopWidth(self.mainConf.getTabWidth())
|
||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||
|
||||
theText = theText.replace("\t", "!!tab!!")
|
||||
theText = theText.replace("<del>", "<span style='text-decoration: line-through;'>")
|
||||
theText = theText.replace("</del>", "</span>")
|
||||
self.setHtml(theText)
|
||||
qApp.processEvents()
|
||||
|
||||
while self.find("!!tab!!"):
|
||||
theCursor = self.textCursor()
|
||||
@@ -1184,6 +1194,7 @@ class GuiBuildNovelDocView(QTextBrowser):
|
||||
# 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.
|
||||
self.qDocument.markContentsDirty(0, self.qDocument.characterCount())
|
||||
qApp.restoreOverrideCursor()
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import os
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QPixmap
|
||||
from PyQt5.QtGui import QPixmap, QCursor
|
||||
from PyQt5.QtWidgets import (
|
||||
qApp, QDialog, QTreeWidget, QTreeWidgetItem, QDialogButtonBox, QGridLayout,
|
||||
QLabel, QGroupBox, QMenu, QAction, QFileDialog, QSpinBox, QHBoxLayout
|
||||
@@ -253,10 +253,15 @@ class GuiWritingStats(QDialog):
|
||||
|
||||
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._updateListBox()
|
||||
|
||||
qApp.restoreOverrideCursor()
|
||||
return
|
||||
|
||||
##
|
||||
|
||||
+15
-2
@@ -48,6 +48,7 @@ from nw.gui import (
|
||||
)
|
||||
from nw.core import NWProject, NWDoc, NWIndex
|
||||
from nw.constants import nwItemType, nwItemClass, nwAlert
|
||||
from nw.common import getGuiItem
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -816,9 +817,15 @@ class GuiMain(QMainWindow):
|
||||
logger.error("No project open")
|
||||
return
|
||||
|
||||
dlgBuild = GuiBuildNovel(self, self.theProject)
|
||||
dlgBuild = getGuiItem("GuiBuildNovel")
|
||||
if dlgBuild is None:
|
||||
dlgBuild = GuiBuildNovel(self, self.theProject)
|
||||
|
||||
dlgBuild.setModal(False)
|
||||
dlgBuild.show()
|
||||
qApp.processEvents()
|
||||
dlgBuild.viewCachedDoc()
|
||||
|
||||
return
|
||||
|
||||
def showWritingStatsDialog(self):
|
||||
@@ -828,9 +835,15 @@ class GuiMain(QMainWindow):
|
||||
logger.error("No project open")
|
||||
return
|
||||
|
||||
dlgStats = GuiWritingStats(self, self.theProject)
|
||||
dlgStats = getGuiItem("GuiWritingStats")
|
||||
if dlgStats is None:
|
||||
dlgStats = GuiWritingStats(self, self.theProject)
|
||||
|
||||
dlgStats.setModal(False)
|
||||
dlgStats.show()
|
||||
qApp.processEvents()
|
||||
dlgStats.populateGUI()
|
||||
|
||||
return
|
||||
|
||||
def showAboutNWDialog(self):
|
||||
|
||||
Reference in New Issue
Block a user