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