Minor code improvements and consistent naming of XML functions

This commit is contained in:
Veronica K. B. Olsen
2020-09-17 14:05:51 +02:00
parent 27ee82aad0
commit 904bdd9001
3 changed files with 13 additions and 15 deletions
+9 -8
View File
@@ -481,7 +481,7 @@ class NWProject():
# Changes: # Changes:
# 1.0 : Original file format. # 1.0 : Original file format.
# 1.1 : Changes the way documents are structure in the project # 1.1 : Changes the way documents are structured in the project
# folder from data_X, where X is the first hex value of # folder from data_X, where X is the first hex value of
# the handle, to a single content folder. # the handle, to a single content folder.
# 1.2 : Changes the way autoReplace entries are stored. The 1.1 # 1.2 : Changes the way autoReplace entries are stored. The 1.1
@@ -518,15 +518,16 @@ class NWProject():
msgRes = msgBox.question(self.theParent, "Version Conflict", ( msgRes = msgBox.question(self.theParent, "Version Conflict", (
"This project was saved by a newer version of novelWriter, version %s. " "This project was saved by a newer version of novelWriter, version %s. "
"This is version %s. If you continue to open the project, some attributes " "This is version %s. If you continue to open the project, some attributes "
"and settings may not be preserved. Continue opening the project?" "and settings may not be preserved, but the overall project should be fine. "
"Continue opening the project?"
) % ( ) % (
appVersion, nw.__version__ appVersion, nw.__version__
)) ))
if msgRes != QMessageBox.Yes: if msgRes != QMessageBox.Yes:
return False return False
# Start Parsing XML # Start Parsing the XML
# ================= # =====================
for xChild in xRoot: for xChild in xRoot:
if xChild.tag == "project": if xChild.tag == "project":
@@ -578,9 +579,9 @@ class NWProject():
elif xItem.tag == "notesWordCount": elif xItem.tag == "notesWordCount":
self.notesWCount = checkInt(xItem.text, 0, False) self.notesWCount = checkInt(xItem.text, 0, False)
elif xItem.tag == "status": elif xItem.tag == "status":
self.statusItems.unpackEntries(xItem) self.statusItems.unpackXML(xItem)
elif xItem.tag == "importance": elif xItem.tag == "importance":
self.importItems.unpackEntries(xItem) self.importItems.unpackXML(xItem)
elif xItem.tag == "autoReplace": elif xItem.tag == "autoReplace":
for xEntry in xItem: for xEntry in xItem:
if xEntry.tag == "entry": if xEntry.tag == "entry":
@@ -684,9 +685,9 @@ class NWProject():
self._packProjectValue(xTitleFmt, aKey, aValue) self._packProjectValue(xTitleFmt, aKey, aValue)
xStatus = etree.SubElement(xSettings, "status") xStatus = etree.SubElement(xSettings, "status")
self.statusItems.packEntries(xStatus) self.statusItems.packXML(xStatus)
xStatus = etree.SubElement(xSettings, "importance") xStatus = etree.SubElement(xSettings, "importance")
self.importItems.packEntries(xStatus) self.importItems.packXML(xStatus)
# Save Tree Content # Save Tree Content
logger.debug("Writing project content") logger.debug("Writing project content")
+2 -5
View File
@@ -89,13 +89,10 @@ class NWSpellCheck():
@staticmethod @staticmethod
def expandLanguage(spTag): def expandLanguage(spTag):
"""Translate a language tag to something more suer friendly. """Translate a language tag to something more user friendly.
""" """
spBits = spTag.split("_") spBits = spTag.split("_")
if spBits[0] in isoLanguage.ISO_639_1: spLang = isoLanguage.ISO_639_1.get(spBits[0], spBits[0])
spLang = isoLanguage.ISO_639_1[spBits[0]]
else:
spLang = spBits[0]
if len(spBits) > 1: if len(spBits) > 1:
spLang += " (%s)" % spBits[1] spLang += " (%s)" % spBits[1]
return spLang return spLang
+2 -2
View File
@@ -115,7 +115,7 @@ class NWStatus():
self.theCounts[theIndex] += 1 self.theCounts[theIndex] += 1
return return
def packEntries(self, xParent): def packXML(self, xParent):
"""Pack the status entries into an XML object for saving to the """Pack the status entries into an XML object for saving to the
main project file. main project file.
""" """
@@ -128,7 +128,7 @@ class NWStatus():
xSub.text = self.theLabels[n] xSub.text = self.theLabels[n]
return True return True
def unpackEntries(self, xParent): def unpackXML(self, xParent):
"""Unpack an XML tree and set the class values. """Unpack an XML tree and set the class values.
""" """
theLabels = [] theLabels = []