Make comments and docstrings comply with PEP8
This commit is contained in:
@@ -53,7 +53,8 @@ class NWDoc():
|
||||
self.clearDocument()
|
||||
return None
|
||||
|
||||
# By default, the document is editable. Except for files in the trash folder.
|
||||
# By default, the document is editable.
|
||||
# Except for files in the trash folder.
|
||||
self.docEditable = True
|
||||
if self.theItem.parHandle == self.theProject.trashRoot:
|
||||
self.docEditable = False
|
||||
@@ -70,13 +71,14 @@ class NWDoc():
|
||||
theDoc = inFile.read()
|
||||
except Exception as e:
|
||||
self.makeAlert(["Failed to open document file.",str(e)], nwAlert.ERROR)
|
||||
# Note: Document must be cleared in case of an io error, or else the auto-save or
|
||||
# save will try to overwrite it with an empty file. Return None to alert the caller.
|
||||
# Note: Document must be cleared in case of an io error,
|
||||
# or else the auto-save or save will try to overwrite it
|
||||
# with an empty file. Return None to alert the caller.
|
||||
self.clearDocument()
|
||||
return None
|
||||
else:
|
||||
# The document file does not exist, so we assume it's a new document and initialise an
|
||||
# empty text string.
|
||||
# The document file does not exist, so we assume it's a new
|
||||
# document and initialise an empty text string.
|
||||
logger.debug("The requested document does not exist.")
|
||||
return ""
|
||||
|
||||
|
||||
+23
-14
@@ -130,7 +130,8 @@ class NWIndex():
|
||||
return False
|
||||
|
||||
def saveIndex(self):
|
||||
"""Save the current index as a json file in the project meta folder.
|
||||
"""Save the current index as a json file in the project meta
|
||||
folder.
|
||||
"""
|
||||
|
||||
indexFile = path.join(self.theProject.projMeta, nwFiles.INDEX_FILE)
|
||||
@@ -155,7 +156,8 @@ class NWIndex():
|
||||
return True
|
||||
|
||||
def checkIndex(self):
|
||||
"""Check that the entries in the index are valid and contain the elements it should.
|
||||
"""Check that the entries in the index are valid and contain the
|
||||
elements it should.
|
||||
"""
|
||||
|
||||
self.indexBroken = False
|
||||
@@ -193,8 +195,9 @@ class NWIndex():
|
||||
##
|
||||
|
||||
def scanText(self, tHandle, theText):
|
||||
"""Scan a piece of text associated with a handle. This will update the indices accordingly.
|
||||
This function takes the handle and text as separate inputs as we want to primarily scan the
|
||||
"""Scan a piece of text associated with a handle. This will
|
||||
update the indices accordingly. This function takes the handle
|
||||
and text as separate inputs as we want to primarily scan the
|
||||
files before we save them, unless we're rebuilding the index.
|
||||
"""
|
||||
|
||||
@@ -243,7 +246,8 @@ class NWIndex():
|
||||
return True
|
||||
|
||||
def indexTitle(self, tHandle, isNovel, aLine, nLine, itemLayout):
|
||||
"""Save information about the title and its location in the file.
|
||||
"""Save information about the title and its location in the
|
||||
file.
|
||||
"""
|
||||
|
||||
if aLine.startswith("# "):
|
||||
@@ -272,7 +276,8 @@ class NWIndex():
|
||||
return True
|
||||
|
||||
def indexNoteRef(self, tHandle, aLine, nLine, nTitle):
|
||||
"""Validate and save the information about a reference to a tag in another file.
|
||||
"""Validate and save the information about a reference to a tag
|
||||
in another file.
|
||||
"""
|
||||
|
||||
isValid, theBits, thePos = self.scanThis(aLine)
|
||||
@@ -303,8 +308,9 @@ class NWIndex():
|
||||
##
|
||||
|
||||
def scanThis(self, aLine):
|
||||
"""Scan a line starting with @ to check that it's valid and to split up its elements into
|
||||
an array and an array of positions. The latter is needed for the syntax highlighter.
|
||||
"""Scan a line starting with @ to check that it's valid and to
|
||||
split up its elements into an array and an array of positions.
|
||||
The latter is needed for the syntax highlighter.
|
||||
"""
|
||||
|
||||
theBits = []
|
||||
@@ -343,8 +349,8 @@ class NWIndex():
|
||||
return True, theBits, thePos
|
||||
|
||||
def checkThese(self, theBits, tItem):
|
||||
"""Check the tags against the index to see if they are valid tags. This is needed for syntax
|
||||
highlighting.
|
||||
"""Check the tags against the index to see if they are valid
|
||||
tags. This is needed for syntax highlighting.
|
||||
"""
|
||||
|
||||
nBits = len(theBits)
|
||||
@@ -357,7 +363,8 @@ class NWIndex():
|
||||
if not isGood[0] or nBits == 1:
|
||||
return isGood
|
||||
|
||||
# If we have a tag, only the first value is accepted, the rest is ignored
|
||||
# If we have a tag, only the first value is accepted, the rest
|
||||
# is ignored
|
||||
if theBits[0] == nwKeyWords.TAG_KEY and nBits > 1:
|
||||
isGood[0] = True
|
||||
if theBits[1] in self.tagIndex.keys():
|
||||
@@ -396,7 +403,8 @@ class NWIndex():
|
||||
return True
|
||||
|
||||
def buildReferenceList(self, tHandle):
|
||||
"""Build a list of files referring back to our file, specified by tHandle.
|
||||
"""Build a list of files referring back to our file, specified
|
||||
by tHandle.
|
||||
"""
|
||||
|
||||
theRefs = {}
|
||||
@@ -429,8 +437,9 @@ class NWIndex():
|
||||
return None, 0
|
||||
|
||||
def buildTagNovelMap(self, theTags, theFilters=None):
|
||||
"""Build a two-dimensional map of all titles of the novel and which tags they link to from
|
||||
the various meta tags. This map is used to display the timeline view.
|
||||
"""Build a two-dimensional map of all titles of the novel and
|
||||
which tags they link to from the various meta tags. This map is
|
||||
used to display the timeline view.
|
||||
"""
|
||||
|
||||
tagMap = {}
|
||||
|
||||
+22
-11
@@ -85,17 +85,28 @@ class NWItem():
|
||||
|
||||
def setFromTag(self, tagName, tagValue):
|
||||
logger.verbose("Setting tag '%s' to value '%s'" % (tagName, str(tagValue)))
|
||||
if tagName == "name": self.setName(tagValue)
|
||||
elif tagName == "order": self.setOrder(tagValue)
|
||||
elif tagName == "type": self.setType(tagValue)
|
||||
elif tagName == "class": self.setClass(tagValue)
|
||||
elif tagName == "layout": self.setLayout(tagValue)
|
||||
elif tagName == "status": self.setStatus(tagValue)
|
||||
elif tagName == "expanded": self.setExpanded(tagValue)
|
||||
elif tagName == "charCount": self.setCharCount(tagValue)
|
||||
elif tagName == "wordCount": self.setWordCount(tagValue)
|
||||
elif tagName == "paraCount": self.setParaCount(tagValue)
|
||||
elif tagName == "cursorPos": self.setCursorPos(tagValue)
|
||||
if tagName == "name":
|
||||
self.setName(tagValue)
|
||||
elif tagName == "order":
|
||||
self.setOrder(tagValue)
|
||||
elif tagName == "type":
|
||||
self.setType(tagValue)
|
||||
elif tagName == "class":
|
||||
self.setClass(tagValue)
|
||||
elif tagName == "layout":
|
||||
self.setLayout(tagValue)
|
||||
elif tagName == "status":
|
||||
self.setStatus(tagValue)
|
||||
elif tagName == "expanded":
|
||||
self.setExpanded(tagValue)
|
||||
elif tagName == "charCount":
|
||||
self.setCharCount(tagValue)
|
||||
elif tagName == "wordCount":
|
||||
self.setWordCount(tagValue)
|
||||
elif tagName == "paraCount":
|
||||
self.setParaCount(tagValue)
|
||||
elif tagName == "cursorPos":
|
||||
self.setCursorPos(tagValue)
|
||||
else:
|
||||
logger.error("Unknown tag '%s'" % tagName)
|
||||
return
|
||||
|
||||
+29
-18
@@ -37,7 +37,7 @@ class NWProject():
|
||||
self.mainConf = self.theParent.mainConf
|
||||
self.projOpened = None # The time stamp of when the project file was opened
|
||||
self.projChanged = None # The project has unsaved changes
|
||||
self.projAltered = None # The project has been altered this session (used to trigger backup)
|
||||
self.projAltered = None # The project has been altered this session
|
||||
|
||||
# Debug
|
||||
self.handleSeed = None
|
||||
@@ -224,7 +224,8 @@ class NWProject():
|
||||
if xChild.tag == "project":
|
||||
logger.debug("Found project meta")
|
||||
for xItem in xChild:
|
||||
if xItem.text is None: continue
|
||||
if xItem.text is None:
|
||||
continue
|
||||
if xItem.tag == "name":
|
||||
logger.verbose("Working Title: '%s'" % xItem.text)
|
||||
self.projName = xItem.text
|
||||
@@ -239,7 +240,8 @@ class NWProject():
|
||||
elif xChild.tag == "settings":
|
||||
logger.debug("Found project settings")
|
||||
for xItem in xChild:
|
||||
if xItem.text is None: continue
|
||||
if xItem.text is None:
|
||||
continue
|
||||
if xItem.tag == "spellCheck":
|
||||
self.spellCheck = checkBool(xItem.text,False)
|
||||
elif xItem.tag == "lastEdited":
|
||||
@@ -493,8 +495,9 @@ class NWProject():
|
||||
return None
|
||||
|
||||
def getRootItem(self, tHandle):
|
||||
"""Iterate upwards in the tree until we find the item with parent None, the root item.
|
||||
We do this with a for loop with a maximum depth of 200 to make infinite loops impossible.
|
||||
"""Iterate upwards in the tree until we find the item with
|
||||
parent None, the root item. We do this with a for loop with a
|
||||
maximum depth of 200 to make infinite loops impossible.
|
||||
"""
|
||||
tItem = self.getItem(tHandle)
|
||||
if tItem is not None:
|
||||
@@ -506,9 +509,10 @@ class NWProject():
|
||||
return None
|
||||
|
||||
def getProjectItems(self):
|
||||
"""This function is called from the tree view when building the tree. Each item in the
|
||||
project is returned in the order saved in the project file, but first it checks that it has
|
||||
a parent item already sent to the tree.
|
||||
"""This function is called from the tree view when building the
|
||||
tree. Each item in the project is returned in the order saved in
|
||||
the project file, but first it checks that it has a parent item
|
||||
already sent to the tree.
|
||||
"""
|
||||
sentItems = []
|
||||
iterItems = self.treeOrder.copy()
|
||||
@@ -521,10 +525,12 @@ class NWProject():
|
||||
if n > 10000:
|
||||
return # Just in case
|
||||
if tItem is None:
|
||||
# Technically a bug since treeOrder is built from the same data as projTree
|
||||
# Technically a bug since treeOrder is built from the
|
||||
# same data as projTree
|
||||
continue
|
||||
elif tItem.parHandle is None:
|
||||
# Item is a root, or already been identified as an orphaned item
|
||||
# Item is a root, or already been identified as an
|
||||
# orphaned item
|
||||
sentItems.append(tHandle)
|
||||
yield tItem
|
||||
elif tItem.parHandle in sentItems:
|
||||
@@ -532,7 +538,8 @@ class NWProject():
|
||||
sentItems.append(tHandle)
|
||||
yield tItem
|
||||
elif tItem.parHandle in iterItems:
|
||||
# Item's parent exists, but hasn't been sent yet, so add it again to the end
|
||||
# Item's parent exists, but hasn't been sent yet, so add
|
||||
# it again to the end
|
||||
logger.warning("Item %s found before its parent" % tHandle)
|
||||
iterItems.append(tHandle)
|
||||
nMax = len(iterItems)
|
||||
@@ -547,7 +554,8 @@ class NWProject():
|
||||
##
|
||||
|
||||
def deleteItem(self, tHandle):
|
||||
"""This only removes the item from the order list, but not from the project tree.
|
||||
"""This only removes the item from the order list, but not from
|
||||
the project tree.
|
||||
"""
|
||||
self.treeOrder.remove(tHandle)
|
||||
self.setProjectChanged(True)
|
||||
@@ -560,8 +568,8 @@ class NWProject():
|
||||
return None
|
||||
|
||||
def checkRootUnique(self, theClass):
|
||||
"""Checks if there already is a root entry of class 'theClass' in the
|
||||
root of the project tree.
|
||||
"""Checks if there already is a root entry of class 'theClass'
|
||||
in the root of the project tree.
|
||||
"""
|
||||
if theClass == nwItemClass.CUSTOM:
|
||||
return True
|
||||
@@ -689,7 +697,9 @@ class NWProject():
|
||||
if self.projMeta is None:
|
||||
return False
|
||||
|
||||
with open(path.join(self.projMeta, nwFiles.SESS_INFO),mode="a+",encoding="utf8") as outFile:
|
||||
sessionFile = path.join(self.projMeta, nwFiles.SESS_INFO)
|
||||
|
||||
with open(sessionFile,mode="a+",encoding="utf8") as outFile:
|
||||
print((
|
||||
"Start: {opened:s} "
|
||||
"End: {closed:s} "
|
||||
@@ -717,9 +727,10 @@ class NWProject():
|
||||
return itemHandle
|
||||
|
||||
def _maintainPrevious(self):
|
||||
"""This function will take the current project file and copy it into the project cache
|
||||
folder with an incremental file extension added. These serve as a backup in case the xml
|
||||
file gets corrupted.
|
||||
"""This function will take the current project file and copy it
|
||||
into the project cache folder with an incremental file extension
|
||||
added. These serve as a backup in case the xml file gets
|
||||
corrupted.
|
||||
"""
|
||||
|
||||
countFile = path.join(self.projCache, nwFiles.PROJ_COUNT)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import logging
|
||||
import nw
|
||||
|
||||
from lxml import etree
|
||||
from lxml import etree
|
||||
|
||||
from nw.enum import nwItemClass
|
||||
from nw.common import checkInt
|
||||
|
||||
Reference in New Issue
Block a user