Fix translations and refactor makeAlert calls

This commit is contained in:
Veronica Berglyd Olsen
2021-06-10 21:42:40 +02:00
parent 904ba9b1ca
commit 6e1e40f13e
15 changed files with 252 additions and 297 deletions
+91 -109
View File
@@ -120,7 +120,7 @@ class NWProject():
CUSTOM, and always have parent handle set to None.
"""
if not self.projTree.checkRootUnique(rootClass):
self.makeAlert("Duplicate root item detected.", nwAlert.ERROR)
self.makeAlert(self.tr("Duplicate root item detected."), nwAlert.ERROR)
return None
newItem = NWItem(self)
newItem.setName(rootName)
@@ -362,7 +362,9 @@ class NWProject():
if not os.path.isfile(fileName):
fileName = os.path.join(fileName, nwFiles.PROJ_FILE)
if not os.path.isfile(fileName):
self.makeAlert(self.tr("File not found: {0}").format(fileName), nwAlert.ERROR)
self.makeAlert(self.tr(
"File not found: {0}"
).format(fileName), nwAlert.ERROR)
return False
self.clearProject()
@@ -411,20 +413,22 @@ class NWProject():
try:
nwXML = etree.parse(fileName)
except Exception as e:
self.makeAlert([self.tr("Failed to parse project xml."), str(e)], nwAlert.ERROR)
self.makeAlert([
self.tr("Failed to parse project xml."), str(e)
], nwAlert.ERROR)
# Trying to open backup file instead
backFile = fileName[:-3]+"bak"
if os.path.isfile(backFile):
self.makeAlert(
self.tr("Attempting to open backup project file instead."), nwAlert.INFO
)
self.makeAlert(self.tr(
"Attempting to open backup project file instead."
), nwAlert.INFO)
try:
nwXML = etree.parse(backFile)
except Exception as e:
self.makeAlert(
[self.tr("Failed to parse project xml."), str(e)], nwAlert.ERROR
)
self.makeAlert([
self.tr("Failed to parse project xml."), str(e)
], nwAlert.ERROR)
self.clearProject()
return False
else:
@@ -445,10 +449,9 @@ class NWProject():
# ===============
if not nwxRoot == "novelWriterXML":
self.makeAlert(
self.tr("Project file does not appear to be a novelWriterXML file."),
nwAlert.ERROR
)
self.makeAlert(self.tr(
"Project file does not appear to be a novelWriterXML file."
), nwAlert.ERROR)
self.clearProject()
return False
@@ -465,13 +468,11 @@ class NWProject():
# read the file. Introduced in version 0.10.
if fileVersion not in ("1.0", "1.1", "1.2"):
self.makeAlert((
self.tr(
"Unknown or unsupported novelWriter project file format. "
"The project cannot be opened by this version of novelWriter. "
"The file was saved with novelWriter version {0}."
).format(appVersion)
), nwAlert.ERROR)
self.makeAlert(self.tr(
"Unknown or unsupported novelWriter project file format. "
"The project cannot be opened by this version of novelWriter. "
"The file was saved with novelWriter version {0}."
).format(appVersion), nwAlert.ERROR)
self.clearProject()
return False
@@ -600,9 +601,9 @@ class NWProject():
file.
"""
if self.projPath is None:
self.makeAlert(
self.tr("Project path not set, cannot save project."), nwAlert.ERROR
)
self.makeAlert(self.tr(
"Project path not set, cannot save project."
), nwAlert.ERROR)
return False
saveTime = time()
@@ -681,7 +682,9 @@ class NWProject():
xml_declaration = True
))
except Exception as e:
self.makeAlert([self.tr("Failed to save project."), str(e)], nwAlert.ERROR)
self.makeAlert([
self.tr("Failed to save project."), str(e)
], nwAlert.ERROR)
return False
# If we're here, the file was successfully saved,
@@ -755,30 +758,24 @@ class NWProject():
self.theParent.setStatus(self.tr("Backing up project ..."))
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."
), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Cannot backup project because no backup path is set. "
"Please set a valid backup location in Tools > 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."
), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Cannot backup project because no project name is set. "
"Please set a Working Title in Project > 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."
), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Cannot backup project because the backup path does not exist. "
"Please set a valid backup location in Tools > Preferences."
), nwAlert.ERROR)
return False
cleanName = makeFileNameSafe(self.projName)
@@ -788,20 +785,17 @@ class NWProject():
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
)
self.theParent.makeAlert([
self.tr("Could not create backup folder."), str(e)
], nwAlert.ERROR)
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."
), nwAlert.ERROR
)
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."
), nwAlert.ERROR)
return False
archName = self.tr("Backup from {0}").format(formatTimeStamp(time(), fileSafe=True))
@@ -813,22 +807,19 @@ class NWProject():
self._writeLockFile()
logger.info("Backup written to: %s" % archName)
if doNotify:
self.theParent.makeAlert(
self.tr(
"Backup archive file written to: {0}"
).format(
f"{os.path.join(cleanName, archName)}.zip"
), nwAlert.INFO
)
self.theParent.makeAlert(self.tr(
"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
)
self.theParent.makeAlert([
self.tr("Could not write backup archive."), str(e)
], nwAlert.ERROR)
return False
self.theParent.setStatus(self.tr("Project backed up to '{0}'").format(f"{baseName}.zip"))
self.theParent.setStatus(self.tr(
"Project backed up to '{0}'"
).format(f"{baseName}.zip"))
return True
@@ -854,9 +845,9 @@ class NWProject():
shutil.unpack_archive(pkgSample, projPath)
isSuccess = True
except Exception as e:
self.makeAlert(
[self.tr("Failed to create a new example project."), str(e)], nwAlert.ERROR
)
self.makeAlert([
self.tr("Failed to create a new example project."), str(e)
], nwAlert.ERROR)
elif os.path.isdir(srcSample):
@@ -876,17 +867,15 @@ class NWProject():
isSuccess = True
except Exception as e:
self.makeAlert(
[self.tr("Failed to create a new example project."), str(e)], nwAlert.ERROR
)
self.makeAlert([
self.tr("Failed to create a new example project."), str(e)
], nwAlert.ERROR)
else:
self.makeAlert(
self.tr(
"Failed to create a new example project. Could not find the "
"necessary files. They seem to be missing from this installation."
), nwAlert.ERROR
)
self.makeAlert(self.tr(
"Failed to create a new example project. Could not find the "
"necessary files. They seem to be missing from this installation."
), nwAlert.ERROR)
if isSuccess:
self.clearProject()
@@ -916,19 +905,17 @@ class NWProject():
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)
self.theParent.makeAlert([
self.tr("Could not create new project folder."), str(e)
], nwAlert.ERROR)
return False
if os.path.isdir(projPath):
if os.listdir(self.projPath):
self.theParent.makeAlert(
self.tr(
"New project folder is not empty. "
"Each project requires a dedicated project folder."
), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"New project folder is not empty. "
"Each project requires a dedicated project folder."
), nwAlert.ERROR)
return False
self.ensureFolderStructure()
@@ -975,21 +962,17 @@ class NWProject():
self.doBackup = doBackup
if doBackup:
if not os.path.isdir(self.mainConf.backupPath):
self.theParent.makeAlert(
self.tr(
"You must set a valid backup path in Preferences to use "
"the automatic project backup feature."
), nwAlert.WARN
)
self.theParent.makeAlert(self.tr(
"You must set a valid backup path in Preferences to use "
"the automatic project backup feature."
), nwAlert.WARN)
return False
if self.projName == "":
self.theParent.makeAlert(
self.tr(
"You must set a valid project name in Project Settings to "
"use the automatic project backup feature."
), nwAlert.WARN
)
self.theParent.makeAlert(self.tr(
"You must set a valid project name in Project Settings to "
"use the automatic project backup feature."
), nwAlert.WARN)
return False
return True
@@ -1317,7 +1300,9 @@ class NWProject():
os.mkdir(thePath)
logger.debug("Created folder %s" % thePath)
except Exception as e:
self.makeAlert(["Could not create folder.", str(e)], nwAlert.ERROR)
self.makeAlert([
self.tr("Could not create folder."), str(e)
], nwAlert.ERROR)
return False
return True
@@ -1374,10 +1359,9 @@ class NWProject():
# Report status
if len(orphanFiles) > 0:
self.makeAlert(
self.tr("Found {0} orphaned file(s) in project folder.").format(len(orphanFiles)),
nwAlert.WARN
)
self.makeAlert(self.tr(
"Found {0} orphaned file(s) in project folder."
).format(len(orphanFiles)), nwAlert.WARN)
else:
logger.debug("File check OK")
return
@@ -1431,12 +1415,10 @@ class NWProject():
self.projTree.append(oHandle, oParent, orphItem)
if noWhere:
self.makeAlert(
self.tr(
"One or more orphaned files could not be added back into the "
"project. Make sure at least a Novel root folder exists."
), nwAlert.WARN
)
self.makeAlert(self.tr(
"One or more orphaned files could not be added back into the "
"project. Make sure at least a Novel root folder exists."
), nwAlert.WARN)
return True
+15 -15
View File
@@ -102,9 +102,9 @@ class GuiDocMerge(QDialog):
finalOrder.append(self.listBox.item(i).data(Qt.UserRole))
if len(finalOrder) == 0:
self.theParent.makeAlert(
self.tr("No source documents found. Nothing to do."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"No source documents found. Nothing to do."
), nwAlert.ERROR)
return False
theText = ""
@@ -113,16 +113,16 @@ class GuiDocMerge(QDialog):
docText = inDoc.readDocument()
docErr = inDoc.getError()
if docText is None and docErr:
self.theParent.makeAlert(
[self.tr("Failed to open document file."), docErr], nwAlert.ERROR
)
self.theParent.makeAlert([
self.tr("Failed to open document file."), docErr
], nwAlert.ERROR)
if docText:
theText += docText.rstrip("\n")+"\n\n"
if self.sourceItem is None:
self.theParent.makeAlert(
self.tr("No source folder selected. Nothing to do."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"No source folder selected. Nothing to do."
), nwAlert.ERROR)
return False
srcItem = self.theProject.projTree[self.sourceItem]
@@ -136,9 +136,9 @@ class GuiDocMerge(QDialog):
outDoc = NWDoc(self.theProject, nHandle)
if not outDoc.writeDocument(theText):
self.theParent.makeAlert(
[self.tr("Could not save document."), outDoc.getError()], nwAlert.ERROR
)
self.theParent.makeAlert([
self.tr("Could not save document."), outDoc.getError()
], nwAlert.ERROR)
return False
self.theParent.treeView.revealNewTreeItem(nHandle)
@@ -174,9 +174,9 @@ class GuiDocMerge(QDialog):
return False
if nwItem.itemType is not nwItemType.FOLDER:
self.theParent.makeAlert(
self.tr("Element selected in the project tree must be a folder."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Element selected in the project tree must be a folder."
), nwAlert.ERROR)
return False
for sHandle in self.theParent.treeView.getTreeFromHandle(tHandle):
+23 -25
View File
@@ -117,16 +117,16 @@ class GuiDocSplit(QDialog):
logger.verbose("GuiDocSplit split button clicked")
if self.sourceItem is None:
self.theParent.makeAlert(
self.tr("No source document selected. Nothing to do."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"No source document selected. Nothing to do."
), nwAlert.ERROR)
return False
srcItem = self.theProject.projTree[self.sourceItem]
if srcItem is None:
self.theParent.makeAlert(
self.tr("Could not parse source document."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Could not parse source document."
), nwAlert.ERROR)
return False
inDoc = NWDoc(self.theProject, self.sourceItem)
@@ -134,9 +134,9 @@ class GuiDocSplit(QDialog):
docErr = inDoc.getError()
if theText is None and docErr:
self.theParent.makeAlert(
[self.tr("Failed to open document file."), docErr], nwAlert.ERROR
)
self.theParent.makeAlert([
self.tr("Failed to open document file."), docErr
], nwAlert.ERROR)
if theText is None:
theText = ""
@@ -157,21 +157,19 @@ class GuiDocSplit(QDialog):
nFiles = len(finalOrder)
if nFiles == 0:
self.theParent.makeAlert(
self.tr("No headers found. Nothing to do."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"No headers found. Nothing to do."
), nwAlert.ERROR)
return False
# Check that another folder can be created
parTree = self.theProject.projTree.getItemPath(srcItem.itemParent)
if len(parTree) >= nwConst.MAX_DEPTH - 1:
self.theParent.makeAlert(
self.tr(
"Cannot add new folder for the document split. "
"Maximum folder depth has been reached. "
"Please move the file to another level in the project tree."
), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Cannot add new folder for the document split. "
"Maximum folder depth has been reached. "
"Please move the file to another level in the project tree."
), nwAlert.ERROR)
return False
msgYes = self.theParent.askQuestion(
@@ -227,9 +225,9 @@ class GuiDocSplit(QDialog):
outDoc = NWDoc(self.theProject, nHandle)
if not outDoc.writeDocument(theText):
self.theParent.makeAlert(
[self.tr("Could not save document."), outDoc.getError()], nwAlert.ERROR
)
self.theParent.makeAlert([
self.tr("Could not save document."), outDoc.getError()
], nwAlert.ERROR)
return False
self.theParent.treeView.revealNewTreeItem(nHandle)
@@ -267,9 +265,9 @@ class GuiDocSplit(QDialog):
return False
if nwItem.itemType is not nwItemType.FILE:
self.theParent.makeAlert(
self.tr("Element selected in the project tree must be a file."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Element selected in the project tree must be a file."
), nwAlert.ERROR)
return False
inDoc = NWDoc(self.theProject, self.sourceItem)
+3 -4
View File
@@ -104,10 +104,9 @@ class GuiPreferences(PagedDialog):
self.tabQuote.saveValues()
if needsRestart:
self.theParent.makeAlert(
self.tr("Some changes will not be applied until novelWriter has been restarted."),
nwAlert.INFO
)
self.theParent.makeAlert(self.tr(
"Some changes will not be applied until novelWriter has been restarted."
), nwAlert.INFO)
self._saveWindowSize()
self.accept()
+3 -3
View File
@@ -397,9 +397,9 @@ class GuiProjectEditStatus(QWidget):
self.listBox.takeTopLevelItem(iRow)
self.colChanged = True
else:
self.theParent.makeAlert(
self.tr("Cannot delete a status item that is in use."), nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Cannot delete a status item that is in use."
), nwAlert.ERROR)
return
def _saveItem(self):
+6 -5
View File
@@ -122,14 +122,15 @@ class GuiWordList(QDialog):
"""
newWord = self.newEntry.text().strip()
if newWord == "":
self.theParent.makeAlert(self.tr("Cannot add a blank word."), nwAlert.ERROR)
self.theParent.makeAlert(self.tr(
"Cannot add a blank word."
), nwAlert.ERROR)
return False
if self.listBox.findItems(newWord, Qt.MatchExactly):
self.theParent.makeAlert(
self.tr("The word '{0}' is already in the word list.").format(newWord),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"The word '{0}' is already in the word list."
).format(newWord), nwAlert.ERROR)
return False
self.listBox.addItem(newWord)
+25 -35
View File
@@ -315,17 +315,14 @@ class GuiDocEditor(QTextEdit):
docSize = len(theDoc)
if docSize > nwConst.MAX_DOCSIZE:
self.theParent.makeAlert(
self.tr(
"The document you are trying to open is too big. "
"The document size is {0} MB. "
"The maximum size allowed is {1} MB."
).format(
f"{docSize/1.0e6:.2f}",
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"The document you are trying to open is too big. "
"The document size is {0} MB. "
"The maximum size allowed is {1} MB."
).format(
f"{docSize/1.0e6:.2f}",
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
), nwAlert.ERROR)
self.clearEditor()
return False
@@ -413,17 +410,14 @@ class GuiDocEditor(QTextEdit):
"""
docSize = len(theText)
if docSize > nwConst.MAX_DOCSIZE:
self.theParent.makeAlert(
self.tr(
"The text you are trying to add is too big. "
"The text size is {0} MB. "
"The maximum size allowed is {1} MB."
).format(
f"{docSize/1.0e6:.2f}",
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"The text you are trying to add is too big. "
"The text size is {0} MB. "
"The maximum size allowed is {1} MB."
).format(
f"{docSize/1.0e6:.2f}",
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
), nwAlert.ERROR)
return False
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
@@ -1009,15 +1003,12 @@ class GuiDocEditor(QTextEdit):
self._lastFind = None
if self._qDocument.characterCount() > nwConst.MAX_DOCSIZE:
self.theParent.makeAlert(
self.tr(
"The document has grown too big and you cannot add more text to it. "
"The maximum size of a single novelWriter document is {0} MB."
).format(
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"The document has grown too big and you cannot add more text to it. "
"The maximum size of a single novelWriter document is {0} MB."
).format(
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
), nwAlert.ERROR)
self.undo()
return
@@ -1552,10 +1543,9 @@ class GuiDocEditor(QTextEdit):
self._allowAutoReplace(True)
else:
self.theParent.makeAlert(
self.tr("Please select some text before calling replace quotes."),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Please select some text before calling replace quotes."
), nwAlert.ERROR)
return
+7 -8
View File
@@ -246,14 +246,13 @@ class GuiDocViewer(QTextBrowser):
logger.debug("Loading document from tag '%s'" % theTag)
tHandle, _, sTitle = self.theParent.theIndex.getTagSource(theTag)
if tHandle is None:
self.theParent.makeAlert(
self.tr(
"Could not find the reference for tag '{0}'. It either doesn't "
"exist, or the index is out of date. The index can be updated "
"from the Tools menu, or by pressing {1}."
).format(theTag, "F9"),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Could not find the reference for tag '{0}'. It either doesn't "
"exist, or the index is out of date. The index can be updated "
"from the Tools menu, or by pressing {1}."
).format(
theTag, "F9"
), nwAlert.ERROR)
return False
else:
# Let the parent handle the opening as it also ensures that
-3
View File
@@ -99,9 +99,6 @@ class GuiNovelTree(QTreeWidget):
logger.debug("GuiNovelTree initialisation complete")
# Internal Mapping
self.makeAlert = self.theParent.makeAlert
return
def initTree(self):
+33 -31
View File
@@ -197,15 +197,13 @@ class GuiProjectTree(QTreeWidget):
# If class is still not set, alert the user and exit
if itemClass is None:
if itemType == nwItemType.FILE:
self.makeAlert(
self.tr("Please select a valid location in the tree to add the document."),
nwAlert.ERROR
)
self.makeAlert(self.tr(
"Please select a valid location in the tree to add the document."
), nwAlert.ERROR)
else:
self.makeAlert(
self.tr("Please select a valid location in the tree to add the folder."),
nwAlert.ERROR
)
self.makeAlert(self.tr(
"Please select a valid location in the tree to add the folder."
), nwAlert.ERROR)
return False
# Everything is fine, we have what we need, so we proceed
@@ -227,9 +225,9 @@ class GuiProjectTree(QTreeWidget):
# If still nothing, give up
if pHandle is None:
self.makeAlert(
self.tr("Did not find anywhere to add the file or folder!"), nwAlert.ERROR
)
self.makeAlert(self.tr(
"Did not find anywhere to add the file or folder!"
), nwAlert.ERROR)
return False
# Now check if the selected item is a file, in which case
@@ -241,15 +239,15 @@ class GuiProjectTree(QTreeWidget):
# If we again have no home, give up
if pHandle is None:
self.makeAlert(
self.tr("Did not find anywhere to add the file or folder!"), nwAlert.ERROR
)
self.makeAlert(self.tr(
"Did not find anywhere to add the file or folder!"
), nwAlert.ERROR)
return False
if self.theProject.projTree.isTrashRoot(pHandle):
self.makeAlert(
self.tr("Cannot add new files or folders to the Trash folder."), nwAlert.ERROR
)
self.makeAlert(self.tr(
"Cannot add new files or folders to the Trash folder."
), nwAlert.ERROR)
return False
parTree = self.theProject.projTree.getItemPath(pHandle)
@@ -262,9 +260,9 @@ class GuiProjectTree(QTreeWidget):
if len(parTree) >= nwConst.MAX_DEPTH - 1:
# Folders cannot be deeper than MAX_DEPTH - 1, leaving room
# for one more level of files.
self.makeAlert((
self.tr("Cannot add new folder to this item."),
self.tr("Maximum folder depth has been reached.")
self.makeAlert(self.tr(
"Cannot add new folder to this item. "
"Maximum folder depth has been reached."
), nwAlert.ERROR)
return False
tHandle = self.theProject.newFolder(self.tr("New Folder"), itemClass, pHandle)
@@ -433,9 +431,9 @@ class GuiProjectTree(QTreeWidget):
logger.debug("Emptying Trash folder")
if trashHandle is None:
self.makeAlert(
self.tr("There is currently no Trash folder in this project."), nwAlert.INFO
)
self.makeAlert(self.tr(
"There is currently no Trash folder in this project."
), nwAlert.INFO)
return False
theTrash = self.getTreeFromHandle(trashHandle)
@@ -444,7 +442,9 @@ class GuiProjectTree(QTreeWidget):
nTrash = len(theTrash)
if nTrash == 0:
self.makeAlert(self.tr("The Trash folder is already empty."), nwAlert.INFO)
self.makeAlert(self.tr(
"The Trash folder is already empty."
), nwAlert.INFO)
return False
msgYes = self.askQuestion(
@@ -857,7 +857,9 @@ class GuiProjectTree(QTreeWidget):
snItem = self.theProject.projTree[sHandle]
dnItem = self.theProject.projTree[dHandle]
if dnItem is None:
self.makeAlert(self.tr("The item cannot be moved to that location."), nwAlert.ERROR)
self.makeAlert(self.tr(
"The item cannot be moved to that location."
), nwAlert.ERROR)
return
pItem = sItem.parent()
@@ -888,7 +890,9 @@ class GuiProjectTree(QTreeWidget):
else:
theEvent.ignore()
logger.debug("Drag'n'drop of item %s not accepted" % sHandle)
self.makeAlert(self.tr("The item cannot be moved to that location."), nwAlert.ERROR)
self.makeAlert(self.tr(
"The item cannot be moved to that location."
), nwAlert.ERROR)
return
@@ -985,11 +989,9 @@ class GuiProjectTree(QTreeWidget):
elif nwItem.itemType == nwItemType.TRASH:
self.addTopLevelItem(newItem)
else:
self.makeAlert(
self.tr(
"There is nowhere to add item with name '{0}'."
).format(nwItem.itemName), nwAlert.ERROR
)
self.makeAlert(self.tr(
"There is nowhere to add item with name '{0}'."
).format(nwItem.itemName), nwAlert.ERROR)
del self._treeMap[tHandle]
return None
+9 -9
View File
@@ -397,9 +397,9 @@ class GuiTheme:
with open(themeConf, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile)
except Exception as e:
self.makeAlert(
[self.tr("Could not load theme config file."), str(e)], nwAlert.ERROR
)
self.makeAlert([
self.tr("Could not load theme config file."), str(e)
], nwAlert.ERROR)
continue
themeName = ""
if confParser.has_section("Main"):
@@ -430,9 +430,9 @@ class GuiTheme:
with open(syntaxPath, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile)
except Exception as e:
self.makeAlert(
[self.tr("Could not load syntax file."), str(e)], nwAlert.ERROR
)
self.makeAlert([
self.tr("Could not load syntax file."), str(e)
], nwAlert.ERROR)
return []
syntaxName = ""
if confParser.has_section("Main"):
@@ -745,9 +745,9 @@ class GuiIcons:
with open(themeConf, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile)
except Exception as e:
self.makeAlert(
[self.tr("Could not load theme config file."), str(e)], nwAlert.ERROR
)
self.makeAlert([
self.tr("Could not load theme config file."), str(e)
], nwAlert.ERROR)
continue
themeName = ""
if confParser.has_section("Main"):
+16 -21
View File
@@ -350,10 +350,9 @@ class GuiMain(QMainWindow):
"""
if self.hasProject:
if not self.closeProject():
self.makeAlert(
self.tr("Cannot create new project when another project is open."),
nwAlert.ERROR
)
self.makeAlert(self.tr(
"Cannot create new project when another project is open."
), nwAlert.ERROR)
return False
if projData is None:
@@ -368,12 +367,10 @@ class GuiMain(QMainWindow):
return False
if os.path.isfile(os.path.join(projPath, self.theProject.projFile)):
self.makeAlert(
self.tr(
"A project already exists in that location. "
"Please choose another folder."
), nwAlert.ERROR
)
self.makeAlert(self.tr(
"A project already exists in that location. "
"Please choose another folder."
), nwAlert.ERROR)
return False
logger.info("Creating new project")
@@ -538,10 +535,9 @@ class GuiMain(QMainWindow):
# Check if we need to rebuild the index
if self.theIndex.indexBroken:
self.makeAlert(
self.tr("The project index is outdated or broken. Rebuilding index."),
nwAlert.WARN
)
self.makeAlert(self.tr(
"The project index is outdated or broken. Rebuilding index."
), nwAlert.WARN)
self.rebuildIndex()
# Make sure the changed status is set to false on all that was
@@ -735,10 +731,9 @@ class GuiMain(QMainWindow):
return False
if self.docEditor.docHandle() is None:
self.makeAlert(
self.tr("Please open a document to import the text file into."),
nwAlert.ERROR
)
self.makeAlert(self.tr(
"Please open a document to import the text file into."
), nwAlert.ERROR)
return False
if not self.docEditor.isEmpty():
@@ -912,9 +907,9 @@ class GuiMain(QMainWindow):
qApp.restoreOverrideCursor()
if not beQuiet:
self.makeAlert(
self.tr("The project index has been successfully rebuilt."), nwAlert.INFO
)
self.makeAlert(self.tr(
"The project index has been successfully rebuilt."
), nwAlert.INFO)
return True
+10 -15
View File
@@ -747,11 +747,10 @@ class GuiBuildNovel(QDialog):
tEnd = int(time())
logger.debug("Built project in %.3f ms" % (1000*(tEnd - tStart)))
if bldObj.errData:
self.theParent.makeAlert("%s:<br>-&nbsp;%s" % (
self.tr("There were problems when building the project"),
"<br>-&nbsp;".join(bldObj.errData)), nwAlert.ERROR
)
if bldObj.errData and isinstance(bldObj.errData, list):
self.theParent.makeAlert([
self.tr("There were problems when building the project:")
] + bldObj.errData, nwAlert.ERROR)
return
@@ -998,17 +997,13 @@ class GuiBuildNovel(QDialog):
# ==============
if wSuccess:
self.theParent.makeAlert(
"%s<br>%s" % (
self.tr("{0} file successfully written to:").format(textFmt), savePath
),
nwAlert.INFO
)
self.theParent.makeAlert([
self.tr("{0} file successfully written to:").format(textFmt), savePath
], nwAlert.INFO)
else:
self.theParent.makeAlert(
self.tr("Failed to write {0} file. {1}").format(textFmt, errMsg),
nwAlert.ERROR
)
self.theParent.makeAlert(self.tr(
"Failed to write {0} file. {1}"
).format(textFmt, errMsg), nwAlert.ERROR)
return wSuccess
+10 -14
View File
@@ -412,17 +412,13 @@ class GuiWritingStats(QDialog):
# Report to user
if wSuccess:
self.theParent.makeAlert(
"%s file successfully written to:<br>%s" % (
textFmt, savePath
), nwAlert.INFO
)
self.theParent.makeAlert([
self.tr("{0} file successfully written to:").format(textFmt), savePath
], nwAlert.INFO)
else:
self.theParent.makeAlert(
"Failed to write %s file.<br>%s" % (
textFmt, errMsg
), nwAlert.ERROR
)
self.theParent.makeAlert([
self.tr("Failed to write {0} file.").format(textFmt), errMsg
], nwAlert.ERROR)
return wSuccess
@@ -487,9 +483,9 @@ class GuiWritingStats(QDialog):
self.logData.append((dStart, sDiff, wcNovel, wcNotes, sIdle))
except Exception as e:
self.theParent.makeAlert(
[self.tr("Failed to read session log file."), str(e)], nwAlert.ERROR
)
self.theParent.makeAlert([
self.tr("Failed to read session log file."), str(e)
], nwAlert.ERROR)
return False
ttWords = ttNovel + ttNotes
@@ -505,7 +501,7 @@ class GuiWritingStats(QDialog):
# Slots
##
def _updateListBox(self, dummyVar=None):
def _updateListBox(self):
"""Load/reload the content of the list box. The dummyVar
variable captures the variable sent from the widgets connecting
to it and discards it.
+1
View File
@@ -43,6 +43,7 @@ class MockGuiMain():
return
def makeAlert(self, theMessage, theLevel):
assert isinstance(theMessage, str) or isinstance(theMessage, list)
print("%s: %s" % (str(theLevel), theMessage))
self.lastAlert = str(theMessage)
return