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