Dialog format error (#889)

* Remove redundant format tags in project class
* Be consistent about internal function mapping
This commit is contained in:
Veronica Berglyd Olsen
2021-09-11 16:14:35 +02:00
committed by GitHub
parent 3263ce5669
commit 22662fd5eb
3 changed files with 39 additions and 45 deletions
+19 -20
View File
@@ -107,7 +107,6 @@ class NWProject():
self.doBackup = True # Run project backup on exit self.doBackup = True # Run project backup on exit
# Internal Mapping # Internal Mapping
self.makeAlert = self.theParent.makeAlert
self.tr = partial(QCoreApplication.translate, "NWProject") self.tr = partial(QCoreApplication.translate, "NWProject")
# Set Defaults # Set Defaults
@@ -124,7 +123,7 @@ class NWProject():
CUSTOM, and always have parent handle set to None. CUSTOM, and always have parent handle set to None.
""" """
if not self.projTree.checkRootUnique(rootClass): if not self.projTree.checkRootUnique(rootClass):
self.makeAlert(self.tr("Duplicate root item detected."), nwAlert.ERROR) self.theParent.makeAlert(self.tr("Duplicate root item detected."), nwAlert.ERROR)
return None return None
newItem = NWItem(self) newItem = NWItem(self)
newItem.setName(rootName) newItem.setName(rootName)
@@ -365,7 +364,7 @@ class NWProject():
if not os.path.isfile(fileName): if not os.path.isfile(fileName):
fileName = os.path.join(fileName, nwFiles.PROJ_FILE) fileName = os.path.join(fileName, nwFiles.PROJ_FILE)
if not os.path.isfile(fileName): if not os.path.isfile(fileName):
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"File not found: {0}" "File not found: {0}"
).format(fileName), nwAlert.ERROR) ).format(fileName), nwAlert.ERROR)
return False return False
@@ -416,20 +415,20 @@ class NWProject():
try: try:
nwXML = etree.parse(fileName) nwXML = etree.parse(fileName)
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Failed to parse project xml."), str(e) self.tr("Failed to parse project xml."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
# Trying to open backup file instead # Trying to open backup file instead
backFile = fileName[:-3]+"bak" backFile = fileName[:-3]+"bak"
if os.path.isfile(backFile): if os.path.isfile(backFile):
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Attempting to open backup project file instead." "Attempting to open backup project file instead."
), nwAlert.INFO) ), nwAlert.INFO)
try: try:
nwXML = etree.parse(backFile) nwXML = etree.parse(backFile)
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Failed to parse project xml."), str(e) self.tr("Failed to parse project xml."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
self.clearProject() self.clearProject()
@@ -452,7 +451,7 @@ class NWProject():
# =============== # ===============
if not nwxRoot == "novelWriterXML": if not nwxRoot == "novelWriterXML":
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Project file does not appear to be a novelWriterXML file." "Project file does not appear to be a novelWriterXML file."
), nwAlert.ERROR) ), nwAlert.ERROR)
self.clearProject() self.clearProject()
@@ -474,7 +473,7 @@ class NWProject():
# 1.5. # 1.5.
if fileVersion not in ("1.0", "1.1", "1.2", "1.3"): if fileVersion not in ("1.0", "1.1", "1.2", "1.3"):
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Unknown or unsupported novelWriter project file format. " "Unknown or unsupported novelWriter project file format. "
"The project cannot be opened by this version of novelWriter. " "The project cannot be opened by this version of novelWriter. "
"The file was saved with novelWriter version {0}." "The file was saved with novelWriter version {0}."
@@ -489,21 +488,21 @@ class NWProject():
"The file format of your project is about to be updated. " "The file format of your project is about to be updated. "
"If you proceed, this project can no longer be opened by " "If you proceed, this project can no longer be opened by "
"an older version of novelWriter. Continue?" "an older version of novelWriter. Continue?"
).format(appVersion, novelwriter.__version__) )
) )
if not msgYes: if not msgYes:
self.clearProject() self.clearProject()
return False return False
if fileVersion in ("1.0", "1.1", "1.2"): if fileVersion in ("1.0", "1.1", "1.2"):
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"The format of your project will now be updated. You may " "The format of your project will now be updated. You may "
"also have to make a few minor changes to your title page " "also have to make a few minor changes to your title page "
"and unnumbered chapters. Please check the 'Project " "and unnumbered chapters. Please check the 'Project "
"Format Changes > File Format 1.3' section of the " "Format Changes > File Format 1.3' section of the "
"documentation for more information. It is avialable from " "documentation for more information. It is avialable from "
"the Help menu." "the Help menu."
).format(appVersion), nwAlert.INFO) ), nwAlert.INFO)
# Check novelWriter Version # Check novelWriter Version
# ========================= # =========================
@@ -601,7 +600,7 @@ class NWProject():
for projItem in legacyList: for projItem in legacyList:
errList = self._legacyDataFolder(projItem, errList) errList = self._legacyDataFolder(projItem, errList)
if errList: if errList:
self.makeAlert(errList, nwAlert.ERROR) self.theParent.makeAlert(errList, nwAlert.ERROR)
# Clean up no longer used files # Clean up no longer used files
self._deprecatedFiles() self._deprecatedFiles()
@@ -631,7 +630,7 @@ class NWProject():
file. file.
""" """
if self.projPath is None: if self.projPath is None:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Project path not set, cannot save project." "Project path not set, cannot save project."
), nwAlert.ERROR) ), nwAlert.ERROR)
return False return False
@@ -709,7 +708,7 @@ class NWProject():
xml_declaration=True xml_declaration=True
)) ))
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Failed to save project."), str(e) self.tr("Failed to save project."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
return False return False
@@ -873,7 +872,7 @@ class NWProject():
shutil.unpack_archive(pkgSample, projPath) shutil.unpack_archive(pkgSample, projPath)
isSuccess = True isSuccess = True
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Failed to create a new example project."), str(e) self.tr("Failed to create a new example project."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
@@ -895,12 +894,12 @@ class NWProject():
isSuccess = True isSuccess = True
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Failed to create a new example project."), str(e) self.tr("Failed to create a new example project."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
else: else:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Failed to create a new example project. " "Failed to create a new example project. "
"Could not find the necessary files. " "Could not find the necessary files. "
"They seem to be missing from this installation." "They seem to be missing from this installation."
@@ -1328,7 +1327,7 @@ class NWProject():
os.mkdir(thePath) os.mkdir(thePath)
logger.debug("Created folder: %s", thePath) logger.debug("Created folder: %s", thePath)
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Could not create folder."), str(e) self.tr("Could not create folder."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
return False return False
@@ -1387,7 +1386,7 @@ class NWProject():
# Report status # Report status
if len(orphanFiles) > 0: if len(orphanFiles) > 0:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Found {0} orphaned file(s) in project folder." "Found {0} orphaned file(s) in project folder."
).format(len(orphanFiles)), nwAlert.WARN) ).format(len(orphanFiles)), nwAlert.WARN)
else: else:
@@ -1443,7 +1442,7 @@ class NWProject():
self.projTree.append(oHandle, oParent, orphItem) self.projTree.append(oHandle, oParent, orphItem)
if noWhere: if noWhere:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"One or more orphaned files could not be added back into the project. " "One or more orphaned files could not be added back into the project. "
"Make sure at least a Novel root folder exists." "Make sure at least a Novel root folder exists."
), nwAlert.WARN) ), nwAlert.WARN)
+17 -21
View File
@@ -128,10 +128,6 @@ class GuiProjectTree(QTreeWidget):
# Set custom settings # Set custom settings
self.initTree() self.initTree()
# Internal Function Mapping
self.makeAlert = self.theParent.makeAlert
self.askQuestion = self.theParent.askQuestion
logger.debug("GuiProjectTree initialisation complete") logger.debug("GuiProjectTree initialisation complete")
return return
@@ -194,11 +190,11 @@ class GuiProjectTree(QTreeWidget):
# If class is still not set, alert the user and exit # If class is still not set, alert the user and exit
if itemClass is None: if itemClass is None:
if itemType == nwItemType.FILE: if itemType == nwItemType.FILE:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Please select a valid location in the tree to add the document." "Please select a valid location in the tree to add the document."
), nwAlert.ERROR) ), nwAlert.ERROR)
else: else:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Please select a valid location in the tree to add the folder." "Please select a valid location in the tree to add the folder."
), nwAlert.ERROR) ), nwAlert.ERROR)
return False return False
@@ -223,7 +219,7 @@ class GuiProjectTree(QTreeWidget):
# If still nothing, give up # If still nothing, give up
if pHandle is None: if pHandle is None:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Did not find anywhere to add the file or folder!" "Did not find anywhere to add the file or folder!"
), nwAlert.ERROR) ), nwAlert.ERROR)
return False return False
@@ -237,13 +233,13 @@ class GuiProjectTree(QTreeWidget):
# If we again have no home, give up # If we again have no home, give up
if pHandle is None: if pHandle is None:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Did not find anywhere to add the file or folder!" "Did not find anywhere to add the file or folder!"
), nwAlert.ERROR) ), nwAlert.ERROR)
return False return False
if self.theProject.projTree.isTrashRoot(pHandle): if self.theProject.projTree.isTrashRoot(pHandle):
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Cannot add new files or folders to the Trash folder." "Cannot add new files or folders to the Trash folder."
), nwAlert.ERROR) ), nwAlert.ERROR)
return False return False
@@ -258,7 +254,7 @@ class GuiProjectTree(QTreeWidget):
if len(parTree) >= nwConst.MAX_DEPTH - 1: if len(parTree) >= nwConst.MAX_DEPTH - 1:
# Folders cannot be deeper than MAX_DEPTH - 1, leaving room # Folders cannot be deeper than MAX_DEPTH - 1, leaving room
# for one more level of files. # for one more level of files.
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Cannot add new folder to this item. " "Cannot add new folder to this item. "
"Maximum folder depth has been reached." "Maximum folder depth has been reached."
), nwAlert.ERROR) ), nwAlert.ERROR)
@@ -425,7 +421,7 @@ class GuiProjectTree(QTreeWidget):
logger.debug("Emptying Trash folder") logger.debug("Emptying Trash folder")
if trashHandle is None: if trashHandle is None:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"There is currently no Trash folder in this project." "There is currently no Trash folder in this project."
), nwAlert.INFO) ), nwAlert.INFO)
return False return False
@@ -436,12 +432,12 @@ class GuiProjectTree(QTreeWidget):
nTrash = len(theTrash) nTrash = len(theTrash)
if nTrash == 0: if nTrash == 0:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"The Trash folder is already empty." "The Trash folder is already empty."
), nwAlert.INFO) ), nwAlert.INFO)
return False return False
msgYes = self.askQuestion( msgYes = self.theParent.askQuestion(
self.tr("Empty Trash"), self.tr("Empty Trash"),
self.tr("Permanently delete {0} file(s) from Trash?").format(nTrash) self.tr("Permanently delete {0} file(s) from Trash?").format(nTrash)
) )
@@ -503,7 +499,7 @@ class GuiProjectTree(QTreeWidget):
# user if they want to permanently delete the file. # user if they want to permanently delete the file.
doPermanent = False doPermanent = False
if not alreadyAsked: if not alreadyAsked:
msgYes = self.askQuestion( msgYes = self.theParent.askQuestion(
self.tr("Delete File"), self.tr("Delete File"),
self.tr("Permanently delete file '{0}'?").format(nwItemS.itemName) self.tr("Permanently delete file '{0}'?").format(nwItemS.itemName)
) )
@@ -524,7 +520,7 @@ class GuiProjectTree(QTreeWidget):
delDoc = NWDoc(self.theProject, tHandle) delDoc = NWDoc(self.theProject, tHandle)
if not delDoc.deleteDocument(): if not delDoc.deleteDocument():
self.makeAlert([ self.theParent.makeAlert([
self.tr("Could not delete document file."), delDoc.getError() self.tr("Could not delete document file."), delDoc.getError()
], nwAlert.ERROR) ], nwAlert.ERROR)
return False return False
@@ -537,7 +533,7 @@ class GuiProjectTree(QTreeWidget):
else: else:
# The file is not already in the trash folder, so we # The file is not already in the trash folder, so we
# move it there. # move it there.
msgYes = self.askQuestion( msgYes = self.theParent.askQuestion(
self.tr("Delete File"), self.tr("Delete File"),
self.tr("Move file '{0}' to Trash?").format(nwItemS.itemName), self.tr("Move file '{0}' to Trash?").format(nwItemS.itemName),
) )
@@ -570,7 +566,7 @@ class GuiProjectTree(QTreeWidget):
self._deleteTreeItem(tHandle) self._deleteTreeItem(tHandle)
self._setTreeChanged(True) self._setTreeChanged(True)
else: else:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Cannot delete folder. It is not empty. " "Cannot delete folder. It is not empty. "
"Recursive deletion is not supported. " "Recursive deletion is not supported. "
"Please delete the content first." "Please delete the content first."
@@ -586,7 +582,7 @@ class GuiProjectTree(QTreeWidget):
self.theParent.mainMenu.setAvailableRoot() self.theParent.mainMenu.setAvailableRoot()
self._setTreeChanged(True) self._setTreeChanged(True)
else: else:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Cannot delete root folder. It is not empty. " "Cannot delete root folder. It is not empty. "
"Recursive deletion is not supported. " "Recursive deletion is not supported. "
"Please delete the content first." "Please delete the content first."
@@ -844,7 +840,7 @@ class GuiProjectTree(QTreeWidget):
snItem = self.theProject.projTree[sHandle] snItem = self.theProject.projTree[sHandle]
dnItem = self.theProject.projTree[dHandle] dnItem = self.theProject.projTree[dHandle]
if dnItem is None: if dnItem is None:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"The item cannot be moved to that location." "The item cannot be moved to that location."
), nwAlert.ERROR) ), nwAlert.ERROR)
return return
@@ -877,7 +873,7 @@ class GuiProjectTree(QTreeWidget):
else: else:
theEvent.ignore() theEvent.ignore()
logger.debug("Drag'n'drop of item '%s' not accepted", sHandle) logger.debug("Drag'n'drop of item '%s' not accepted", sHandle)
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"The item cannot be moved to that location." "The item cannot be moved to that location."
), nwAlert.ERROR) ), nwAlert.ERROR)
@@ -976,7 +972,7 @@ class GuiProjectTree(QTreeWidget):
elif nwItem.itemType == nwItemType.TRASH: elif nwItem.itemType == nwItemType.TRASH:
self.addTopLevelItem(newItem) self.addTopLevelItem(newItem)
else: else:
self.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"There is nowhere to add item with name '{0}'." "There is nowhere to add item with name '{0}'."
).format(nwItem.itemName), nwAlert.ERROR) ).format(nwItem.itemName), nwAlert.ERROR)
del self._treeMap[tHandle] del self._treeMap[tHandle]
+3 -4
View File
@@ -163,7 +163,6 @@ class GuiTheme:
logger.verbose("Text 'N' Width: %d", self.textNWidth) logger.verbose("Text 'N' Width: %d", self.textNWidth)
# Internal Mapping # Internal Mapping
self.makeAlert = self.theParent.makeAlert
self.tr = partial(QCoreApplication.translate, "GuiTheme") self.tr = partial(QCoreApplication.translate, "GuiTheme")
return return
@@ -401,7 +400,7 @@ class GuiTheme:
with open(themeConf, mode="r", encoding="utf-8") as inFile: with open(themeConf, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Could not load theme config file."), str(e) self.tr("Could not load theme config file."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
continue continue
@@ -434,7 +433,7 @@ class GuiTheme:
with open(syntaxPath, mode="r", encoding="utf-8") as inFile: with open(syntaxPath, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Could not load syntax file."), str(e) self.tr("Could not load syntax file."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
return [] return []
@@ -773,7 +772,7 @@ class GuiIcons:
with open(themeConf, mode="r", encoding="utf-8") as inFile: with open(themeConf, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception as e: except Exception as e:
self.makeAlert([ self.theParent.makeAlert([
self.tr("Could not load theme config file."), str(e) self.tr("Could not load theme config file."), str(e)
], nwAlert.ERROR) ], nwAlert.ERROR)
continue continue