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
+5 -5
View File
@@ -215,25 +215,25 @@ def main(sysArgs=None):
errorCode = 0
if sys.hexversion < 0x030600f0:
errorData.append(
"At least Python 3.6.0 is required, found %s" % CONFIG.verPyString
"At least Python 3.6 is required, found %s" % CONFIG.verPyString
)
errorCode |= 4
errorCode |= 0x04
if CONFIG.verQtValue < 50300:
errorData.append(
"At least Qt5 version 5.3 is required, found %s" % CONFIG.verQtString
)
errorCode |= 8
errorCode |= 0x08
if CONFIG.verPyQtValue < 50300:
errorData.append(
"At least PyQt5 version 5.3 is required, found %s" % CONFIG.verPyQtString
)
errorCode |= 16
errorCode |= 0x10
try:
import lxml # noqa: F401
except ImportError:
errorData.append("Python module 'lxml' is missing")
errorCode |= 32
errorCode |= 0x20
if errorData:
errApp = QApplication([])
+20
View File
@@ -174,6 +174,26 @@ def hexToInt(value, default=0):
return default
def checkIntRange(value, first, last, default):
"""Check that an int is in a given range. If it isn't, return the
default value.
"""
if isinstance(value, int):
if value >= first and value <= last:
return value
return default
def checkIntTuple(value, valid, default):
"""Check that an int is an element of a tuple. If it isn't, return
the default value.
"""
if isinstance(value, int):
if value in valid:
return value
return default
# =============================================================================================== #
# Formatting Functions
# =============================================================================================== #
+12 -12
View File
@@ -307,12 +307,12 @@ class Config:
if not os.path.isdir(self.confPath):
try:
os.mkdir(self.confPath)
except Exception as e:
except Exception as exc:
logger.error("Could not create folder: %s", self.confPath)
logException()
self.hasError = True
self.errData.append("Could not create folder: %s" % self.confPath)
self.errData.append(str(e))
self.errData.append(str(exc))
self.confPath = None
# Check if config file exists
@@ -330,12 +330,12 @@ class Config:
if not os.path.isdir(self.dataPath):
try:
os.mkdir(self.dataPath)
except Exception as e:
except Exception as exc:
logger.error("Could not create folder: %s", self.dataPath)
logException()
self.hasError = True
self.errData.append("Could not create folder: %s" % self.dataPath)
self.errData.append(str(e))
self.errData.append(str(exc))
self.dataPath = None
# Host and Kernel
@@ -425,12 +425,12 @@ class Config:
try:
with open(cnfPath, mode="r", encoding="utf-8") as inFile:
theConf.read_file(inFile)
except Exception as e:
except Exception as exc:
logger.error("Could not load config file")
logException()
self.hasError = True
self.errData.append("Could not load config file")
self.errData.append(str(e))
self.errData.append(str(exc))
return False
# Main
@@ -655,12 +655,12 @@ class Config:
with open(cnfPath, mode="w", encoding="utf-8") as outFile:
theConf.write(outFile)
self.confChanged = False
except Exception as e:
except Exception as exc:
logger.error("Could not save config file")
logException()
self.hasError = True
self.errData.append("Could not save config file")
self.errData.append(str(e))
self.errData.append(str(exc))
return False
return True
@@ -688,10 +688,10 @@ class Config:
"words": theEntry.get("words", 0),
}
except Exception as e:
except Exception as exc:
self.hasError = True
self.errData.append("Could not load recent project cache")
self.errData.append(str(e))
self.errData.append(str(exc))
return False
return True
@@ -708,10 +708,10 @@ class Config:
try:
with open(cacheTemp, mode="w+", encoding="utf-8") as outFile:
json.dump(self.recentProj, outFile, indent=2)
except Exception as e:
except Exception as exc:
self.hasError = True
self.errData.append("Could not save recent project cache")
self.errData.append(str(e))
self.errData.append(str(exc))
return False
if os.path.isfile(cacheFile):
+6 -6
View File
@@ -100,8 +100,8 @@ class NWDoc():
# Load the rest of the file
theText += inFile.read()
except Exception as e:
self._docError = str(e)
except Exception as exc:
self._docError = str(exc)
return None
else:
@@ -149,8 +149,8 @@ class NWDoc():
with open(docTemp, mode="w", encoding="utf-8") as outFile:
outFile.write(docMeta)
outFile.write(docText)
except Exception as e:
self._docError = str(e)
except Exception as exc:
self._docError = str(exc)
return False
# If we're here, the file was successfully saved, so we can
@@ -184,8 +184,8 @@ class NWDoc():
try:
os.unlink(chkFile)
logger.debug("Deleted: %s", chkFile)
except Exception as e:
self._docError = str(e)
except Exception as exc:
self._docError = str(exc)
return False
return True
-22
View File
@@ -185,26 +185,4 @@ class OptionState():
return checkBool(self._theState[group].get(name, default), default)
return default
##
# Validators
##
def validIntRange(self, value, first, last, default):
"""Check that an int is in a given range. If it isn't, return
the default value.
"""
if isinstance(value, int):
if value >= first and value <= last:
return value
return default
def validIntTuple(self, value, valid, default):
"""Check that an int is an element of a tuple. If it isn't,
return the default value.
"""
if isinstance(value, int):
if value in valid:
return value
return default
# END Class OptionState
+42 -42
View File
@@ -415,10 +415,10 @@ class NWProject():
try:
nwXML = etree.parse(fileName)
except Exception as e:
self.theParent.makeAlert([
self.tr("Failed to parse project xml."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Failed to parse project xml."
), nwAlert.ERROR, exception=exc)
# Trying to open backup file instead
backFile = fileName[:-3]+"bak"
@@ -428,10 +428,10 @@ class NWProject():
), nwAlert.INFO)
try:
nwXML = etree.parse(backFile)
except Exception as e:
self.theParent.makeAlert([
self.tr("Failed to parse project xml."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Failed to parse project xml."
), nwAlert.ERROR, exception=exc)
self.clearProject()
return False
else:
@@ -487,8 +487,8 @@ class NWProject():
self.tr("File Version"),
self.tr(
"The file format of your project is about to be updated. "
"If you proceed, this project can no longer be opened by "
"an older version of novelWriter. Continue?"
"If you proceed, older versions of novelWriter will no "
"longer be able to open this project. Continue?"
)
)
if not msgYes:
@@ -708,10 +708,10 @@ class NWProject():
encoding="utf-8",
xml_declaration=True
))
except Exception as e:
self.theParent.makeAlert([
self.tr("Failed to save project."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Failed to save project."
), nwAlert.ERROR, exception=exc)
return False
# If we're here, the file was successfully saved,
@@ -788,21 +788,21 @@ class NWProject():
if self.mainConf.backupPath is None or self.mainConf.backupPath == "":
self.theParent.makeAlert(self.tr(
"Cannot backup project because no backup path is set. "
"Please set a valid backup location in Tools > Preferences."
"Please set a valid backup location in Preferences."
), nwAlert.ERROR)
return False
if self.projName is None or self.projName == "":
self.theParent.makeAlert(self.tr(
"Cannot backup project because no project name is set. "
"Please set a Working Title in Project > Project Settings."
"Please set a Working Title in Project Settings."
), nwAlert.ERROR)
return False
if not os.path.isdir(self.mainConf.backupPath):
self.theParent.makeAlert(self.tr(
"Cannot backup project because the backup path does not exist. "
"Please set a valid backup location in Tools > Preferences."
"Please set a valid backup location in Preferences."
), nwAlert.ERROR)
return False
@@ -812,17 +812,17 @@ class NWProject():
try:
os.mkdir(baseDir)
logger.debug("Created folder: %s", baseDir)
except Exception as e:
self.theParent.makeAlert([
self.tr("Could not create backup folder."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Could not create backup folder."
), nwAlert.ERROR, exception=exc)
return False
if os.path.commonpath([self.projPath, baseDir]) == self.projPath:
self.theParent.makeAlert(self.tr(
"Cannot backup project because the backup path is within the "
"project folder to be backed up. Please choose a different "
"backup path in Tools > Preferences."
"backup path in Preferences."
), nwAlert.ERROR)
return False
@@ -839,10 +839,10 @@ class NWProject():
"Backup archive file written to: {0}"
).format(f"{os.path.join(cleanName, archName)}.zip"), nwAlert.INFO)
except Exception as e:
self.theParent.makeAlert([
self.tr("Could not write backup archive."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Could not write backup archive."
), nwAlert.ERROR, exception=exc)
return False
self.theParent.setStatus(self.tr(
@@ -872,10 +872,10 @@ class NWProject():
try:
shutil.unpack_archive(pkgSample, projPath)
isSuccess = True
except Exception as e:
self.theParent.makeAlert([
self.tr("Failed to create a new example project."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Failed to create a new example project."
), nwAlert.ERROR, exception=exc)
elif os.path.isdir(srcSample):
@@ -894,10 +894,10 @@ class NWProject():
isSuccess = True
except Exception as e:
self.theParent.makeAlert([
self.tr("Failed to create a new example project."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Failed to create a new example project."
), nwAlert.ERROR, exception=exc)
else:
self.theParent.makeAlert(self.tr(
@@ -933,10 +933,10 @@ class NWProject():
try:
os.mkdir(projPath)
logger.debug("Created folder: %s", projPath)
except Exception as e:
self.theParent.makeAlert([
self.tr("Could not create new project folder."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Could not create new project folder."
), nwAlert.ERROR, exception=exc)
return False
if os.path.isdir(projPath):
@@ -1327,10 +1327,10 @@ class NWProject():
try:
os.mkdir(thePath)
logger.debug("Created folder: %s", thePath)
except Exception as e:
self.theParent.makeAlert([
self.tr("Could not create folder."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.theParent.makeAlert(self.tr(
"Could not create folder."
), nwAlert.ERROR, exception=exc)
return False
return True
+1 -1
View File
@@ -776,7 +776,7 @@ class GuiPreferencesEditor(QWidget):
self.mainForm.addRow(
self.tr("Scroll past end of the document"),
self.scrollPastEnd,
self.tr("Also improves trypewriter scrolling for short documents.")
self.tr("Also improves typewriter scrolling for short documents.")
)
# Typewriter Scrolling
+4 -4
View File
@@ -183,13 +183,13 @@ def exceptionHandler(exType, exValue, exTrace):
nwGUI.closeMain()
logger.info("Emergency shutdown successful")
except Exception as e:
except Exception as exc:
logger.critical("Could not close the project before exiting")
logger.critical(str(e))
logger.critical(str(exc))
qApp.exit(1)
except Exception as e:
logger.critical(str(e))
except Exception as exc:
logger.critical(str(exc))
return
+16 -16
View File
@@ -793,28 +793,28 @@ class GuiMainMenu(QMenuBar):
# Format > Header 1 (Partition)
self.aFmtHead1 = QAction(self.tr("Header 1 (Partition)"), self)
self.aFmtHead1.setStatusTip(self.tr("Change the block format to Header 1"))
self.aFmtHead1.setStatusTip(self.tr("Set the text block format to Header 1 (Partition)"))
self.aFmtHead1.setShortcut("Ctrl+1")
self.aFmtHead1.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_H1))
self.fmtMenu.addAction(self.aFmtHead1)
# Format > Header 2 (Chapter)
self.aFmtHead2 = QAction(self.tr("Header 2 (Chapter)"), self)
self.aFmtHead2.setStatusTip(self.tr("Change the block format to Header 2"))
self.aFmtHead2.setStatusTip(self.tr("Set the text block format to Header 2 (Chapter)"))
self.aFmtHead2.setShortcut("Ctrl+2")
self.aFmtHead2.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_H2))
self.fmtMenu.addAction(self.aFmtHead2)
# Format > Header 3 (Scene)
self.aFmtHead3 = QAction(self.tr("Header 3 (Scene)"), self)
self.aFmtHead3.setStatusTip(self.tr("Change the block format to Header 3"))
self.aFmtHead3.setStatusTip(self.tr("Set the text block format to Header 3 (Scene)"))
self.aFmtHead3.setShortcut("Ctrl+3")
self.aFmtHead3.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_H3))
self.fmtMenu.addAction(self.aFmtHead3)
# Format > Header 4 (Section)
self.aFmtHead4 = QAction(self.tr("Header 4 (Section)"), self)
self.aFmtHead4.setStatusTip(self.tr("Change the block format to Header 4"))
self.aFmtHead4.setStatusTip(self.tr("Set the text block format to Header 4 (Section)"))
self.aFmtHead4.setShortcut("Ctrl+4")
self.aFmtHead4.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_H4))
self.fmtMenu.addAction(self.aFmtHead4)
@@ -824,13 +824,13 @@ class GuiMainMenu(QMenuBar):
# Format > Novel Title
self.aFmtTitle = QAction(self.tr("Novel Title"), self)
self.aFmtTitle.setStatusTip(self.tr("Change the block format to Novel Title"))
self.aFmtTitle.setStatusTip(self.tr("Set the text block format to Novel Title"))
self.aFmtTitle.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_TTL))
self.fmtMenu.addAction(self.aFmtTitle)
# Format > Unnumbered Chapter
self.aFmtUnNum = QAction(self.tr("Unnumbered Chapter"), self)
self.aFmtUnNum.setStatusTip(self.tr("Change the block format to Unnumbered Chapter"))
self.aFmtUnNum.setStatusTip(self.tr("Set the text block format to Unnumbered Chapter"))
self.aFmtUnNum.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_UNN))
self.fmtMenu.addAction(self.aFmtUnNum)
@@ -839,21 +839,21 @@ class GuiMainMenu(QMenuBar):
# Format > Align Left
self.aFmtAlignLeft = QAction(self.tr("Align Left"), self)
self.aFmtAlignLeft.setStatusTip(self.tr("Change the block alignment to left"))
self.aFmtAlignLeft.setStatusTip(self.tr("Left-align the text block"))
self.aFmtAlignLeft.setShortcut("Ctrl+5")
self.aFmtAlignLeft.triggered.connect(lambda: self._docAction(nwDocAction.ALIGN_L))
self.fmtMenu.addAction(self.aFmtAlignLeft)
# Format > Align Centre
self.aFmtAlignCentre = QAction(self.tr("Align Centre"), self)
self.aFmtAlignCentre.setStatusTip(self.tr("Change the block alignment to centre"))
self.aFmtAlignCentre.setStatusTip(self.tr("Centre the text block"))
self.aFmtAlignCentre.setShortcut("Ctrl+6")
self.aFmtAlignCentre.triggered.connect(lambda: self._docAction(nwDocAction.ALIGN_C))
self.fmtMenu.addAction(self.aFmtAlignCentre)
# Format > Align Right
self.aFmtAlignRight = QAction(self.tr("Align Right"), self)
self.aFmtAlignRight.setStatusTip(self.tr("Change the block alignment to right"))
self.aFmtAlignRight.setStatusTip(self.tr("Right-align the text block"))
self.aFmtAlignRight.setShortcut("Ctrl+7")
self.aFmtAlignRight.triggered.connect(lambda: self._docAction(nwDocAction.ALIGN_R))
self.fmtMenu.addAction(self.aFmtAlignRight)
@@ -863,14 +863,14 @@ class GuiMainMenu(QMenuBar):
# Format > Indent Left
self.aFmtIndentLeft = QAction(self.tr("Indent Left"), self)
self.aFmtIndentLeft.setStatusTip(self.tr("Increase the block's left margin"))
self.aFmtIndentLeft.setStatusTip(self.tr("Increase the text block's left margin"))
self.aFmtIndentLeft.setShortcut("Ctrl+8")
self.aFmtIndentLeft.triggered.connect(lambda: self._docAction(nwDocAction.INDENT_L))
self.fmtMenu.addAction(self.aFmtIndentLeft)
# Format > Indent Right
self.aFmtIndentRight = QAction(self.tr("Indent Right"), self)
self.aFmtIndentRight.setStatusTip(self.tr("Increase the block's right margin"))
self.aFmtIndentRight.setStatusTip(self.tr("Increase the text block's right margin"))
self.aFmtIndentRight.setShortcut("Ctrl+9")
self.aFmtIndentRight.triggered.connect(lambda: self._docAction(nwDocAction.INDENT_R))
self.fmtMenu.addAction(self.aFmtIndentRight)
@@ -880,14 +880,14 @@ class GuiMainMenu(QMenuBar):
# Format > Comment
self.aFmtComment = QAction(self.tr("Comment"), self)
self.aFmtComment.setStatusTip(self.tr("Change the block format to comment"))
self.aFmtComment.setStatusTip(self.tr("Change the text block format to comment"))
self.aFmtComment.setShortcut("Ctrl+/")
self.aFmtComment.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_COM))
self.fmtMenu.addAction(self.aFmtComment)
# Format > Remove Block Format
self.aFmtNoFormat = QAction(self.tr("Remove Block Format"), self)
self.aFmtNoFormat.setStatusTip(self.tr("Strips block format"))
self.aFmtNoFormat.setStatusTip(self.tr("Strip text block format"))
self.aFmtNoFormat.setShortcuts(["Ctrl+0", "Ctrl+Shift+/"])
self.aFmtNoFormat.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_TXT))
self.fmtMenu.addAction(self.aFmtNoFormat)
@@ -898,7 +898,7 @@ class GuiMainMenu(QMenuBar):
# Format > Replace Single Quotes
self.aFmtReplSng = QAction(self.tr("Replace Single Quotes"), self)
self.aFmtReplSng.setStatusTip(
self.tr("Replace all straight single quotes in selected text")
self.tr("Replace all straight single quotes in the selected text")
)
self.aFmtReplSng.triggered.connect(lambda: self._docAction(nwDocAction.REPL_SNG))
self.fmtMenu.addAction(self.aFmtReplSng)
@@ -906,7 +906,7 @@ class GuiMainMenu(QMenuBar):
# Format > Replace Double Quotes
self.aFmtReplDbl = QAction(self.tr("Replace Double Quotes"), self)
self.aFmtReplDbl.setStatusTip(
self.tr("Replace all straight double quotes in selected text")
self.tr("Replace all straight double quotes in the selected text")
)
self.aFmtReplDbl.triggered.connect(lambda: self._docAction(nwDocAction.REPL_DBL))
self.fmtMenu.addAction(self.aFmtReplDbl)
@@ -914,7 +914,7 @@ class GuiMainMenu(QMenuBar):
# Format > Remove In-Paragraph Breaks
self.aFmtRmBreaks = QAction(self.tr("Remove In-Paragraph Breaks"), self)
self.aFmtRmBreaks.setStatusTip(
self.tr("Removes all line breaks within paragraphs in the selected text")
self.tr("Remove all line breaks within paragraphs in the selected text")
)
self.aFmtRmBreaks.triggered.connect(lambda: self._docAction(nwDocAction.RM_BREAKS))
self.fmtMenu.addAction(self.aFmtRmBreaks)
+34 -33
View File
@@ -500,10 +500,10 @@ class GuiMain(QMainWindow):
),
self.tr(
"Note: If the program or the computer previously "
"crashed, the lock can safely be overridden. If, "
"however, another instance of novelWriter has the "
"project open, overriding the lock may corrupt the "
"project, and is not recommended."
"crashed, the lock can safely be overridden. However, "
"overriding it is not recommended if the project is "
"open in another instance of novelWriter. Doing so "
"may corrupt the project."
),
lockDetails
),
@@ -730,10 +730,10 @@ class GuiMain(QMainWindow):
with open(loadFile, mode="rt", encoding="utf-8") as inFile:
theText = inFile.read()
self.mainConf.setLastPath(loadFile)
except Exception as e:
self.makeAlert([
self.tr("Could not read file. The file must be an existing text file."), str(e)
], nwAlert.ERROR)
except Exception as exc:
self.makeAlert(self.tr(
"Could not read file. The file must be an existing text file."
), nwAlert.ERROR, exception=exc)
return False
if self.docEditor.docHandle() is None:
@@ -1116,51 +1116,52 @@ class GuiMain(QMainWindow):
return
def makeAlert(self, theMessage, theLevel=nwAlert.INFO):
def makeAlert(self, message, level=nwAlert.INFO, exception=None):
"""Alert both the user and the logger at the same time. The
message can be either a string or a list of strings.
"""
if isinstance(theMessage, list):
theMessage = list(filter(None, theMessage)) # Strip empty strings
popMsg = "<br>".join(theMessage)
logMsg = theMessage
if isinstance(message, list):
message = list(filter(None, message)) # Strip empty strings
popMsg = "<br>".join(message)
logMsg = " ".join(message)
else:
popMsg = theMessage
logMsg = [theMessage]
popMsg = str(message)
logMsg = str(message)
kw = {}
if exception is not None:
kw["exc_info"] = exception
popMsg = f"{popMsg}<br>{type(exception).__name__}: {str(exception)}"
# Write to Log
if theLevel == nwAlert.INFO:
for msgLine in logMsg:
logger.info(msgLine)
elif theLevel == nwAlert.WARN:
for msgLine in logMsg:
logger.warning(msgLine)
elif theLevel == nwAlert.ERROR:
for msgLine in logMsg:
logger.error(msgLine)
elif theLevel == nwAlert.BUG:
for msgLine in logMsg:
logger.error(msgLine)
if level == nwAlert.INFO:
logger.info(logMsg, **kw)
elif level == nwAlert.WARN:
logger.warning(logMsg, **kw)
elif level == nwAlert.ERROR:
logger.error(logMsg, **kw)
elif level == nwAlert.BUG:
logger.error(logMsg, **kw)
# Popup
msgBox = QMessageBox()
if theLevel == nwAlert.INFO:
if level == nwAlert.INFO:
msgBox.information(self, self.tr("Information"), popMsg)
elif theLevel == nwAlert.WARN:
elif level == nwAlert.WARN:
msgBox.warning(self, self.tr("Warning"), popMsg)
elif theLevel == nwAlert.ERROR:
elif level == nwAlert.ERROR:
msgBox.critical(self, self.tr("Error"), popMsg)
elif theLevel == nwAlert.BUG:
elif level == nwAlert.BUG:
popMsg += "<br>%s" % self.tr("This is a bug!")
msgBox.critical(self, self.tr("Internal Error"), popMsg)
return
def askQuestion(self, theTitle, theQuestion):
def askQuestion(self, title, question):
"""Ask the user a Yes/No question.
"""
msgBox = QMessageBox()
msgRes = msgBox.question(self, theTitle, theQuestion, QMessageBox.Yes | QMessageBox.No)
msgRes = msgBox.question(self, title, question, QMessageBox.Yes | QMessageBox.No)
return msgRes == QMessageBox.Yes
def reportConfErr(self):
+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