diff --git a/nw/common.py b/nw/common.py index d5563d16..47e86ff6 100644 --- a/nw/common.py +++ b/nw/common.py @@ -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 diff --git a/nw/constants/constants.py b/nw/constants/constants.py index 0a23e369..e237b662 100644 --- a/nw/constants/constants.py +++ b/nw/constants/constants.py @@ -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" diff --git a/nw/core/tokenizer.py b/nw/core/tokenizer.py index c7b23208..7870493c 100644 --- a/nw/core/tokenizer.py +++ b/nw/core/tokenizer.py @@ -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 ) diff --git a/nw/core/tree.py b/nw/core/tree.py index fc908745..2973d462 100644 --- a/nw/core/tree.py +++ b/nw/core/tree.py @@ -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: diff --git a/nw/gui/build.py b/nw/gui/build.py index fde18f9e..bc820f16 100644 --- a/nw/gui/build.py +++ b/nw/gui/build.py @@ -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: diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index f45e569d..85a3f75d 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -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: diff --git a/nw/gui/docsplit.py b/nw/gui/docsplit.py index 1a5e9491..48ea3e9e 100644 --- a/nw/gui/docsplit.py +++ b/nw/gui/docsplit.py @@ -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. " diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 89e41374..f0d0bca9 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -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 diff --git a/nw/gui/writingstats.py b/nw/gui/writingstats.py index fb10f7a4..b796bbce 100644 --- a/nw/gui/writingstats.py +++ b/nw/gui/writingstats.py @@ -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)