Fix and optimise code (#904)

* Fix bug in early error reporting in main init
* Update docstrings and optimise code in GuiMain
* Update docstrings and optimise code in Config
* Update docstrings and optimise code in common module
* Update docstrings and optimise code in main project classes
* Update the OptionState class
* Update the spell checker class
* Update the file converter classes and extend tests
* Update the about, merge, split and item editor classes and extend tests
* Update item editor test
* Update about dialog tests
* Some minor test cleanup
* Fix typo and add clarification in contributing guide
This commit is contained in:
Veronica Berglyd Olsen
2021-10-14 20:35:42 +01:00
committed by GitHub
parent 2a06db0a2b
commit 1c45331b0a
31 changed files with 1042 additions and 666 deletions
+6 -6
View File
@@ -65,7 +65,7 @@ class GuiAbout(QDialog):
self.nwIcon = QLabel()
self.nwIcon.setPixmap(self.theParent.theTheme.getPixmap("novelwriter", (nPx, nPx)))
self.lblName = QLabel("<b>novelWriter</b>")
self.lblVers = QLabel("v%s" % novelwriter.__version__)
self.lblVers = QLabel(f"v{novelwriter.__version__}")
self.lblDate = QLabel(datetime.strptime(novelwriter.__date__, "%Y-%m-%d").strftime("%x"))
self.leftBox = QVBoxLayout()
@@ -178,7 +178,7 @@ class GuiAbout(QDialog):
),
)
aboutMsg += "<h4>%s</h4><p>%s</p>" % (
aboutMsg += "<h4>{0}</h4><p>{1}</p>".format(
self.tr("Translations"),
self._wrapTable([
("English", "Veronica Berglyd Olsen"),
@@ -193,7 +193,7 @@ class GuiAbout(QDialog):
theIcons = self.theParent.theTheme.theIcons
if theTheme.themeName and theTheme.themeAuthor != "N/A":
licURL = f"<a href='{theTheme.themeLicenseUrl}'>{theTheme.themeLicense}</a>"
aboutMsg += "<h4>%s</h4><p>%s</p>" % (
aboutMsg += "<h4>{0}</h4><p>{1}</p>".format(
self.tr("Theme: {0}").format(theTheme.themeName),
self._wrapTable([
(self.tr("Author"), theTheme.themeAuthor),
@@ -204,7 +204,7 @@ class GuiAbout(QDialog):
if theIcons.themeName:
licURL = f"<a href='{theIcons.themeLicenseUrl}'>{theIcons.themeLicense}</a>"
aboutMsg += "<h4>%s</h4><p>%s</p>" % (
aboutMsg += "<h4>{0}</h4><p>{1}</p>".format(
self.tr("Icons: {0}").format(theIcons.themeName),
self._wrapTable([
(self.tr("Author"), theIcons.themeAuthor),
@@ -215,7 +215,7 @@ class GuiAbout(QDialog):
if theTheme.syntaxName:
licURL = f"<a href='{theTheme.syntaxLicenseUrl}'>{theTheme.syntaxLicense}</a>"
aboutMsg += "<h4>%s</h4><p>%s</p>" % (
aboutMsg += "<h4>{0}</h4><p>{1}</p>".format(
self.tr("Syntax: {0}").format(theTheme.syntaxName),
self._wrapTable([
(self.tr("Author"), theTheme.syntaxAuthor),
@@ -258,7 +258,7 @@ class GuiAbout(QDialog):
theTable.append(
f"<tr><td><b>{aLabel}:</b></td><td>{aValue}</td></tr>"
)
return "<table>%s</table>" % "".join(theTable)
return "<table>{0}</table>".format("".join(theTable))
def _setStyleSheet(self):
"""Set stylesheet for all browser tabs
+1 -1
View File
@@ -55,7 +55,7 @@ class GuiDocMerge(QDialog):
self.outerBox = QVBoxLayout()
self.setWindowTitle(self.tr("Merge Documents"))
self.headLabel = QLabel("<b>%s</b>" % self.tr("Documents to Merge"))
self.headLabel = QLabel("<b>{0}</b>".format(self.tr("Documents to Merge")))
self.helpLabel = QHelpLabel(
self.tr("Drag and drop items to change the order."), self.theParent.theTheme.helpText
)
+8 -10
View File
@@ -59,7 +59,7 @@ class GuiDocSplit(QDialog):
self.outerBox = QVBoxLayout()
self.setWindowTitle(self.tr("Split Document"))
self.headLabel = QLabel("<b>%s</b>" % self.tr("Document Headers"))
self.headLabel = QLabel("<b>{0}</b>".format(self.tr("Document Headers")))
self.helpLabel = QHelpLabel(
self.tr("Select the maximum level to split into files."),
self.theParent.theTheme.helpText
@@ -174,7 +174,7 @@ class GuiDocSplit(QDialog):
msgYes = self.theParent.askQuestion(
self.tr("Split Document"),
"%s<br><br>%s" % (
"{0}<br><br>{1}".format(
self.tr(
"The document will be split into {0} file(s) in a new folder. "
"The original document will remain intact.").format(nFiles),
@@ -196,10 +196,8 @@ class GuiDocSplit(QDialog):
# Loop through, and create the files
for wTitle, iStart, iEnd in finalOrder:
if srcItem.itemClass == nwItemClass.NOVEL:
itemLayout = nwItemLayout.DOCUMENT
else:
itemLayout = nwItemLayout.NOTE
isNovel = srcItem.itemClass == nwItemClass.NOVEL
itemLayout = nwItemLayout.DOCUMENT if isNovel else nwItemLayout.NOTE
wTitle = wTitle.lstrip("#")
wTitle = wTitle.strip()
@@ -209,9 +207,8 @@ class GuiDocSplit(QDialog):
newItem.setLayout(itemLayout)
newItem.setStatus(srcItem.itemStatus)
logger.verbose(
"Creating new document %s with text from line %d to %d" % (
nHandle, iStart+1, iEnd
)
"Creating new document '%s' with text from line %d to %d",
nHandle, iStart+1, iEnd
)
theText = "\n".join(self.sourceText[iStart:iEnd])
@@ -273,7 +270,8 @@ class GuiDocSplit(QDialog):
spLevel = self.splitLevel.currentData()
self.optState.setValue("GuiDocSplit", "spLevel", spLevel)
logger.debug(
"Scanning document %s for headings level <= %d" % (self.sourceItem, spLevel)
"Scanning document '%s' for headings level <= %d",
self.sourceItem, spLevel
)
self.sourceText = theText.splitlines()
+2 -1
View File
@@ -57,7 +57,8 @@ class GuiItemEditor(QDialog):
self.theItem = self.theProject.projTree[tHandle]
if self.theItem is None:
self._doClose()
self.close()
return
self.setWindowTitle(self.tr("Item Settings"))