Code and GUI text cleanup (#926)

* Move int range checkers from options class to common file
* Improve error handling and reporting
* Make some minor improvements to init and test suite
* Fix 'trypewriter' to 'typewriter' typo
* Remove menu path description in dialog help text
* Improve the help text for entries in the Format menu
* Reword a couple of dialog messages
This commit is contained in:
Veronica Berglyd Olsen
2021-11-07 18:17:17 +01:00
committed by GitHub
parent e71121f738
commit e8bb130245
23 changed files with 257 additions and 250 deletions
+14 -14
View File
@@ -872,8 +872,8 @@ class GuiBuildNovel(QDialog):
try:
makeOdt.saveOpenDocText(savePath)
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
elif theFmt == self.FMT_FODT:
makeOdt = ToOdt(self.theProject, isFlat=True)
@@ -881,8 +881,8 @@ class GuiBuildNovel(QDialog):
try:
makeOdt.saveFlatXML(savePath)
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
elif theFmt == self.FMT_HTM:
makeHtml = ToHtml(self.theProject)
@@ -893,8 +893,8 @@ class GuiBuildNovel(QDialog):
try:
makeHtml.saveHTML5(savePath)
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
elif theFmt == self.FMT_NWD:
makeNwd = ToMarkdown(self.theProject)
@@ -906,8 +906,8 @@ class GuiBuildNovel(QDialog):
try:
makeNwd.saveRawMarkdown(savePath)
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
elif theFmt in (self.FMT_MD, self.FMT_GH):
makeMd = ToMarkdown(self.theProject)
@@ -923,8 +923,8 @@ class GuiBuildNovel(QDialog):
try:
makeMd.saveMarkdown(savePath)
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
elif theFmt == self.FMT_JSON_H or theFmt == self.FMT_JSON_M:
jsonData = {
@@ -968,8 +968,8 @@ class GuiBuildNovel(QDialog):
with open(savePath, mode="w", encoding="utf-8") as outFile:
outFile.write(json.dumps(jsonData, indent=2))
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
elif theFmt == self.FMT_PDF:
try:
@@ -983,8 +983,8 @@ class GuiBuildNovel(QDialog):
self.docView.document().print(thePrinter)
wSuccess = True
except Exception as e:
errMsg - str(e)
except Exception as exc:
errMsg = str(exc)
else:
# If the if statements above and here match, it should not
+8 -11
View File
@@ -38,7 +38,7 @@ from PyQt5.QtWidgets import (
)
from novelwriter.enum import nwAlert
from novelwriter.common import formatTime, checkInt
from novelwriter.common import formatTime, checkInt, checkIntRange, checkIntTuple
from novelwriter.constants import nwConst, nwFiles
from novelwriter.gui.custom import QSwitch
@@ -114,13 +114,10 @@ class GuiWritingStats(QDialog):
hHeader.setTextAlignment(self.C_IDLE, Qt.AlignRight)
hHeader.setTextAlignment(self.C_COUNT, Qt.AlignRight)
sortValid = (Qt.AscendingOrder, Qt.DescendingOrder)
sortCol = self.optState.validIntRange(
self.optState.getInt("GuiWritingStats", "sortCol", 0), 0, 2, 0
)
sortOrder = self.optState.validIntTuple(
sortCol = checkIntRange(self.optState.getInt("GuiWritingStats", "sortCol", 0), 0, 2, 0)
sortOrder = checkIntTuple(
self.optState.getInt("GuiWritingStats", "sortOrder", Qt.DescendingOrder),
sortValid, Qt.DescendingOrder
(Qt.AscendingOrder, Qt.DescendingOrder), Qt.DescendingOrder
)
self.listBox.sortByColumn(sortCol, sortOrder)
self.listBox.setSortingEnabled(True)
@@ -406,8 +403,8 @@ class GuiWritingStats(QDialog):
outFile.write(f'"{sD}",{tT:.0f},{wD},{wA},{wB},{tI}\n')
wSuccess = True
except Exception as e:
errMsg = str(e)
except Exception as exc:
errMsg = str(exc)
wSuccess = False
# Report to user
@@ -482,9 +479,9 @@ class GuiWritingStats(QDialog):
self.logData.append((dStart, sDiff, wcNovel, wcNotes, sIdle))
except Exception as e:
except Exception as exc:
self.theParent.makeAlert([
self.tr("Failed to read session log file."), str(e)
self.tr("Failed to read session log file."), str(exc)
], nwAlert.ERROR)
return False