All constants should be upper case

This commit is contained in:
Veronica K. B. Olsen
2020-10-27 20:36:04 +01:00
parent 8e95728e20
commit e2ab9ed6cf
9 changed files with 27 additions and 27 deletions
+2 -2
View File
@@ -165,9 +165,9 @@ def formatTimeStamp(theTime, fileSafe=False):
it to a timestamp string.
"""
if fileSafe:
return datetime.fromtimestamp(theTime).strftime(nwConst.fStampFmt)
return datetime.fromtimestamp(theTime).strftime(nwConst.FMT_FSTAMP)
else:
return datetime.fromtimestamp(theTime).strftime(nwConst.tStampFmt)
return datetime.fromtimestamp(theTime).strftime(nwConst.FMT_TSTAMP)
def formatTime(tS):
"""Format a time in seconds in HH:MM:SS format or d-HH:MM:SS format
+6 -6
View File
@@ -30,14 +30,14 @@ from nw.constants.enum import nwItemClass, nwItemLayout, nwOutline
class nwConst():
# Date and Time Formats
tStampFmt = "%Y-%m-%d %H:%M:%S" # Default format
fStampFmt = "%Y-%m-%d %H.%M.%S" # FileName safe format
dStampFmt = "%Y-%m-%d" # Date only format
FMT_TSTAMP = "%Y-%m-%d %H:%M:%S" # Default format
FMT_FSTAMP = "%Y-%m-%d %H.%M.%S" # FileName safe format
FMT_DSTAMP = "%Y-%m-%d" # Date only format
# Various Hard Limits
maxDepth = 30 # Maximum folder depth of a project
maxDocSize = 5000000 # Maxium size of a single document
maxBuildSize = 10000000 # Maxium size of a project build
MAX_DEPTH = 30 # Maximum folder depth of a project
MAX_DOCSIZE = 5000000 # Maxium size of a single document
MAX_BUILDSIZE = 10000000 # Maxium size of a project build
# Spell Check Providers
SP_INTERNAL = "internal"
+1 -1
View File
@@ -216,7 +216,7 @@ class Tokenizer():
self.theText = theDocument.openDocument(theHandle)
docSize = len(self.theText)
if docSize > nwConst.maxDocSize:
if docSize > nwConst.MAX_DOCSIZE:
errVal = "Document '%s' is too big (%.2f MB). Skipping." % (
self.theItem.itemName, docSize/1.0e6
)
+2 -2
View File
@@ -260,7 +260,7 @@ class NWTree():
"""
tItem = self.__getitem__(tHandle)
if tItem is not None:
for i in range(nwConst.maxDepth + 1):
for i in range(nwConst.MAX_DEPTH + 1):
if tItem.itemParent is None:
return tItem
else:
@@ -278,7 +278,7 @@ class NWTree():
tItem = self.__getitem__(tHandle)
if tItem is not None:
tTree.append(tHandle)
for i in range(nwConst.maxDepth + 1):
for i in range(nwConst.MAX_DEPTH + 1):
if tItem.itemParent is None:
return tTree
else:
+2 -2
View File
@@ -515,7 +515,7 @@ class GuiBuildNovel(QDialog):
self.docView.setStyleSheet(self.htmlStyle)
htmlSize = sum([len(x) for x in self.htmlText])
if htmlSize < nwConst.maxBuildSize:
if htmlSize < nwConst.MAX_BUILDSIZE:
qApp.processEvents()
self.docView.setContent(self.htmlText, self.buildTime)
else:
@@ -656,7 +656,7 @@ class GuiBuildNovel(QDialog):
else:
self.docView.setStyleSheet(self.htmlStyle)
if htmlSize < nwConst.maxBuildSize:
if htmlSize < nwConst.MAX_BUILDSIZE:
self.docView.setContent(self.htmlText, self.buildTime)
self._enableQtSave(True)
else:
+6 -6
View File
@@ -284,12 +284,12 @@ class GuiDocEditor(QTextEdit):
return False
docSize = len(theDoc)
if docSize > nwConst.maxDocSize:
if docSize > nwConst.MAX_DOCSIZE:
self.theParent.makeAlert((
"The document you are trying to open is too big. "
"The document size is %.2f\u202fMB. "
"The maximum size allowed is %.2f\u202fMB."
) % (docSize/1.0e6, nwConst.maxDocSize/1.0e6), nwAlert.ERROR)
) % (docSize/1.0e6, nwConst.MAX_DOCSIZE/1.0e6), nwAlert.ERROR)
self.clearEditor()
return False
@@ -361,12 +361,12 @@ class GuiDocEditor(QTextEdit):
text. This also clears undo history.
"""
docSize = len(theText)
if docSize > nwConst.maxDocSize:
if docSize > nwConst.MAX_DOCSIZE:
self.theParent.makeAlert((
"The text you are trying to add is too big. "
"The text size is %.2f\u202fMB. "
"The maximum size allowed is %.2f\u202fMB."
) % (docSize/1.0e6, nwConst.maxDocSize/1.0e6), nwAlert.ERROR)
) % (docSize/1.0e6, nwConst.MAX_DOCSIZE/1.0e6), nwAlert.ERROR)
return False
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
@@ -859,11 +859,11 @@ class GuiDocEditor(QTextEdit):
"""
self.lastEdit = time()
self.lastFind = None
if self.qDocument.characterCount() > nwConst.maxDocSize:
if self.qDocument.characterCount() > nwConst.MAX_DOCSIZE:
self.theParent.makeAlert((
"The document has grown too big and you cannot add more text to it. "
"The maximum size of a single novelWriter document is %.2f\u202fMB."
) % (nwConst.maxDocSize/1.0e6), nwAlert.ERROR)
) % (nwConst.MAX_DOCSIZE/1.0e6), nwAlert.ERROR)
self.undo()
return
if not self.docChanged:
+1 -1
View File
@@ -155,7 +155,7 @@ class GuiDocSplit(QDialog):
# Check that another folder can be created
parTree = self.theProject.projTree.getItemPath(srcItem.itemParent)
if len(parTree) >= nwConst.maxDepth - 1:
if len(parTree) >= nwConst.MAX_DEPTH - 1:
self.theParent.makeAlert((
"Cannot add new folder for the document split. "
"Maximum folder depth has been reached. "
+3 -3
View File
@@ -243,8 +243,8 @@ class GuiProjectTree(QTreeWidget):
tHandle = self.theProject.newFile("New File", itemClass, pHandle)
elif itemType == nwItemType.FOLDER:
if len(parTree) >= nwConst.maxDepth - 1:
# Folders cannot be deeper than maxDepth - 1, leaving room
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((
"Cannot add new folder to this item. "
@@ -579,7 +579,7 @@ class GuiProjectTree(QTreeWidget):
pCount += int(pItem.child(i).data(self.C_COUNT, Qt.UserRole))
pHandle = pItem.data(self.C_NAME, Qt.UserRole)
if not nDepth > nwConst.maxDepth + 1 and pHandle != "":
if not nDepth > nwConst.MAX_DEPTH + 1 and pHandle != "":
self.propagateCount(pHandle, pCount, nDepth+1)
return
+4 -4
View File
@@ -428,10 +428,10 @@ class GuiWritingStats(QDialog):
continue
dStart = datetime.strptime(
"%s %s" % (inData[0], inData[1]), nwConst.tStampFmt
"%s %s" % (inData[0], inData[1]), nwConst.FMT_TSTAMP
)
dEnd = datetime.strptime(
"%s %s" % (inData[2], inData[3]), nwConst.tStampFmt
"%s %s" % (inData[2], inData[3]), nwConst.FMT_TSTAMP
)
tDiff = dEnd - dStart
@@ -528,9 +528,9 @@ class GuiWritingStats(QDialog):
isFirst = False
if groupByDay:
sStart = dStart.strftime(nwConst.dStampFmt)
sStart = dStart.strftime(nwConst.FMT_DSTAMP)
else:
sStart = dStart.strftime(nwConst.tStampFmt)
sStart = dStart.strftime(nwConst.FMT_TSTAMP)
self.filterData.append((dStart, sStart, sDiff, dwTotal, wcNovel, wcNotes))
listMax = min(max(listMax, dwTotal), histMax)