Logger messages (#818)

* Change the way logger messages are generated by using the printf-like method
* Use single quotes around log values that can be empty strings
* Fix bug in log message
This commit is contained in:
Veronica Berglyd Olsen
2021-07-02 10:22:00 +02:00
committed by GitHub
parent 671888b6ea
commit 1b89d0a4f0
20 changed files with 219 additions and 219 deletions
+1 -3
View File
@@ -209,9 +209,7 @@ def main(sysArgs=None):
pkgLogger.addHandler(cHandle) pkgLogger.addHandler(cHandle)
pkgLogger.setLevel(logLevel) pkgLogger.setLevel(logLevel)
logger.info("Starting novelWriter %s (%s) %s" % ( logger.info("Starting novelWriter %s (%s) %s", __version__, __hexversion__, __date__)
__version__, __hexversion__, __date__
))
# Check Packages and Versions # Check Packages and Versions
errorData = [] errorData = []
+11 -11
View File
@@ -272,7 +272,7 @@ class Config:
confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation) confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
self.confPath = os.path.join(os.path.abspath(confRoot), self.appHandle) self.confPath = os.path.join(os.path.abspath(confRoot), self.appHandle)
else: else:
logger.info("Setting config from alternative path: %s" % confPath) logger.info("Setting config from alternative path: %s", confPath)
self.confPath = confPath self.confPath = confPath
if dataPath is None: if dataPath is None:
@@ -282,11 +282,11 @@ class Config:
dataRoot = QStandardPaths.writableLocation(QStandardPaths.DataLocation) dataRoot = QStandardPaths.writableLocation(QStandardPaths.DataLocation)
self.dataPath = os.path.join(os.path.abspath(dataRoot), self.appHandle) self.dataPath = os.path.join(os.path.abspath(dataRoot), self.appHandle)
else: else:
logger.info("Setting data path from alternative path: %s" % dataPath) logger.info("Setting data path from alternative path: %s", dataPath)
self.dataPath = dataPath self.dataPath = dataPath
logger.verbose("Config path: %s" % self.confPath) logger.verbose("Config path: %s", self.confPath)
logger.verbose("Data path: %s" % self.dataPath) logger.verbose("Data path: %s", self.dataPath)
self.confFile = self.appHandle+".conf" self.confFile = self.appHandle+".conf"
self.lastPath = os.path.expanduser("~") self.lastPath = os.path.expanduser("~")
@@ -310,8 +310,8 @@ class Config:
# Internationalisation # Internationalisation
self.nwLangPath = os.path.join(self.assetPath, "i18n") self.nwLangPath = os.path.join(self.assetPath, "i18n")
logger.verbose("App path: %s" % self.appPath) logger.verbose("App path: %s", self.appPath)
logger.verbose("Last path: %s" % self.lastPath) logger.verbose("Last path: %s", self.lastPath)
# If config folder does not exist, create it. # If config folder does not exist, create it.
# This assumes that the os config folder itself exists. # This assumes that the os config folder itself exists.
@@ -319,7 +319,7 @@ class Config:
try: try:
os.mkdir(self.confPath) os.mkdir(self.confPath)
except Exception as e: except Exception as e:
logger.error("Could not create folder: %s" % self.confPath) logger.error("Could not create folder: %s", self.confPath)
logException() logException()
self.hasError = True self.hasError = True
self.errData.append("Could not create folder: %s" % self.confPath) self.errData.append("Could not create folder: %s" % self.confPath)
@@ -342,7 +342,7 @@ class Config:
try: try:
os.mkdir(self.dataPath) os.mkdir(self.dataPath)
except Exception as e: except Exception as e:
logger.error("Could not create folder: %s" % self.dataPath) logger.error("Could not create folder: %s", self.dataPath)
logException() logException()
self.hasError = True self.hasError = True
self.errData.append("Could not create folder: %s" % self.dataPath) self.errData.append("Could not create folder: %s" % self.dataPath)
@@ -392,7 +392,7 @@ class Config:
lngFile = "%s_%s" % (lngBase, lngCode.replace("-", "_")) lngFile = "%s_%s" % (lngBase, lngCode.replace("-", "_"))
if lngFile not in self.qtTrans: if lngFile not in self.qtTrans:
if qTrans.load(lngFile, lngPath): if qTrans.load(lngFile, lngPath):
logger.debug("Loaded: %s" % os.path.join(lngPath, lngFile)) logger.debug("Loaded: %s", os.path.join(lngPath, lngFile))
nwApp.installTranslator(qTrans) nwApp.installTranslator(qTrans)
self.qtTrans[lngFile] = qTrans self.qtTrans[lngFile] = qTrans
@@ -898,10 +898,10 @@ class Config:
""" """
if thePath in self.recentProj: if thePath in self.recentProj:
del self.recentProj[thePath] del self.recentProj[thePath]
logger.verbose("Removed recent: %s" % thePath) logger.verbose("Removed recent: %s", thePath)
self.saveRecentCache() self.saveRecentCache()
else: else:
logger.error("Unknown recent: %s" % thePath) logger.error("Unknown recent: %s", thePath)
return False return False
return True return True
+4 -4
View File
@@ -73,7 +73,7 @@ class NWDoc():
return None return None
docFile = self._docHandle+".nwd" docFile = self._docHandle+".nwd"
logger.debug("Opening document %s" % docFile) logger.debug("Opening document: %s", docFile)
docPath = os.path.join(self.theProject.projContent, docFile) docPath = os.path.join(self.theProject.projContent, docFile)
self._fileLoc = docPath self._fileLoc = docPath
@@ -120,7 +120,7 @@ class NWDoc():
self.theProject.ensureFolderStructure() self.theProject.ensureFolderStructure()
docFile = self._docHandle+".nwd" docFile = self._docHandle+".nwd"
logger.debug("Saving document %s" % docFile) logger.debug("Saving document: %s", docFile)
docPath = os.path.join(self.theProject.projContent, docFile) docPath = os.path.join(self.theProject.projContent, docFile)
docTemp = os.path.join(self.theProject.projContent, docFile+"~") docTemp = os.path.join(self.theProject.projContent, docFile+"~")
@@ -170,7 +170,7 @@ class NWDoc():
if os.path.isfile(chkFile): if os.path.isfile(chkFile):
try: try:
os.unlink(chkFile) os.unlink(chkFile)
logger.debug("Deleted: %s" % chkFile) logger.debug("Deleted: %s", chkFile)
except Exception as e: except Exception as e:
self._docError = str(e) self._docError = str(e)
return False return False
@@ -237,7 +237,7 @@ class NWDoc():
self._docMeta["layout"] = nwItemLayout[metaBits[1]] self._docMeta["layout"] = nwItemLayout[metaBits[1]]
else: else:
logger.debug("Ignoring meta data: '%s'" % metaLine.strip()) logger.debug("Ignoring meta data: '%s'", metaLine.strip())
return return
+12 -12
View File
@@ -85,7 +85,7 @@ class NWIndex():
def deleteHandle(self, tHandle): def deleteHandle(self, tHandle):
"""Delete all entries of a given document handle. """Delete all entries of a given document handle.
""" """
logger.debug("Removing item %s from the index" % tHandle) logger.debug("Removing item '%s' from the index", tHandle)
delTags = [] delTags = []
for tTag in self._tagIndex: for tTag in self._tagIndex:
@@ -107,7 +107,7 @@ class NWIndex():
moved from the archive or trash folders back into the active moved from the archive or trash folders back into the active
project. project.
""" """
logger.debug("Re-indexing item %s" % tHandle) logger.debug("Re-indexing item '%s'", tHandle)
tItem = self.theProject.projTree[tHandle] tItem = self.theProject.projTree[tHandle]
if tItem is None: if tItem is None:
@@ -217,7 +217,7 @@ class NWIndex():
self.indexBroken = True self.indexBroken = True
tEnd = time() tEnd = time()
logger.debug("Index check took %.3f ms" % ((tEnd - tStart)*1000)) logger.debug("Index check took %.3f ms", (tEnd - tStart)*1000)
logger.debug("Index check complete") logger.debug("Index check complete")
if self.indexBroken: if self.indexBroken:
@@ -239,16 +239,16 @@ class NWIndex():
theRoot = self.theProject.projTree.getRootItem(tHandle) theRoot = self.theProject.projTree.getRootItem(tHandle)
if theItem is None: if theItem is None:
logger.info("Not indexing unknown item %s" % tHandle) logger.info("Not indexing unknown item '%s'", tHandle)
return False return False
if theItem.itemType != nwItemType.FILE: if theItem.itemType != nwItemType.FILE:
logger.info("Not indexing non-file item %s" % tHandle) logger.info("Not indexing non-file item '%s'", tHandle)
return False return False
if theItem.itemLayout == nwItemLayout.NO_LAYOUT: if theItem.itemLayout == nwItemLayout.NO_LAYOUT:
logger.info("Not indexing no-layout item %s" % tHandle) logger.info("Not indexing no-layout item '%s'", tHandle)
return False return False
if theItem.itemParent is None: if theItem.itemParent is None:
logger.info("Not indexing orphaned item %s" % tHandle) logger.info("Not indexing orphaned item '%s'", tHandle)
return False return False
# Run word counter for the whole text # Run word counter for the whole text
@@ -257,16 +257,16 @@ class NWIndex():
# If the file is archived or trashed, we don't index the file itself # If the file is archived or trashed, we don't index the file itself
if self.theProject.projTree.isTrashRoot(theItem.itemParent): if self.theProject.projTree.isTrashRoot(theItem.itemParent):
logger.info("Not indexing trash item %s" % tHandle) logger.info("Not indexing trash item '%s'", tHandle)
return False return False
if theRoot.itemClass == nwItemClass.ARCHIVE: if theRoot.itemClass == nwItemClass.ARCHIVE:
logger.info("Not indexing archived item %s" % tHandle) logger.info("Not indexing archived item '%s'", tHandle)
return False return False
itemClass = theItem.itemClass itemClass = theItem.itemClass
itemLayout = theItem.itemLayout itemLayout = theItem.itemLayout
logger.debug("Indexing item with handle %s" % tHandle) logger.debug("Indexing item with handle '%s'", tHandle)
# Check file type, and reset its old index # Check file type, and reset its old index
# Also add a default entry T000000 in case the file has no title # Also add a default entry T000000 in case the file has no title
@@ -457,11 +457,11 @@ class NWIndex():
""" """
isValid, theBits, _ = self.scanThis(aLine) isValid, theBits, _ = self.scanThis(aLine)
if not isValid or len(theBits) < 2: if not isValid or len(theBits) < 2:
logger.warning("Skipping keyword with %d value(s) in %s" % (len(theBits), tHandle)) logger.warning("Skipping keyword with %d value(s) in '%s'", len(theBits), tHandle)
return return
if theBits[0] not in nwKeyWords.VALID_KEYS: if theBits[0] not in nwKeyWords.VALID_KEYS:
logger.warning("Skipping invalid keyword '%s' in %s" % (theBits[0], tHandle)) logger.warning("Skipping invalid keyword '%s' in '%s'", theBits[0], tHandle)
return return
sTitle = "T%06d" % nTitle sTitle = "T%06d" % nTitle
+4 -4
View File
@@ -133,7 +133,7 @@ class NWItem():
# Sliently skip as we may otherwise cause orphaned # Sliently skip as we may otherwise cause orphaned
# items if an otherwise valid file is opened by a # items if an otherwise valid file is opened by a
# version of novelWriter that doesn't know the tag. # version of novelWriter that doesn't know the tag.
logger.error("Unknown tag '%s'" % xValue.tag) logger.error("Unknown tag '%s'", xValue.tag)
return True return True
@@ -205,7 +205,7 @@ class NWItem():
elif isItemType(theType): elif isItemType(theType):
self.itemType = nwItemType[theType] self.itemType = nwItemType[theType]
else: else:
logger.error("Unrecognised item type '%s'" % theType) logger.error("Unrecognised item type '%s'", theType)
self.itemType = nwItemType.NO_TYPE self.itemType = nwItemType.NO_TYPE
return return
@@ -218,7 +218,7 @@ class NWItem():
elif isItemClass(theClass): elif isItemClass(theClass):
self.itemClass = nwItemClass[theClass] self.itemClass = nwItemClass[theClass]
else: else:
logger.error("Unrecognised item class '%s'" % theClass) logger.error("Unrecognised item class '%s'", theClass)
self.itemClass = nwItemClass.NO_CLASS self.itemClass = nwItemClass.NO_CLASS
return return
@@ -231,7 +231,7 @@ class NWItem():
elif isItemLayout(theLayout): elif isItemLayout(theLayout):
self.itemLayout = nwItemLayout[theLayout] self.itemLayout = nwItemLayout[theLayout]
else: else:
logger.error("Unrecognised item layout '%s'" % theLayout) logger.error("Unrecognised item layout '%s'", theLayout)
self.itemLayout = nwItemLayout.NO_LAYOUT self.itemLayout = nwItemLayout.NO_LAYOUT
return return
+2 -2
View File
@@ -174,11 +174,11 @@ class OptionState():
"""Saves a value, with a given group and name. """Saves a value, with a given group and name.
""" """
if setGroup not in self.validMap: if setGroup not in self.validMap:
logger.error("Unknown option group '%s'" % setGroup) logger.error("Unknown option group '%s'", setGroup)
return False return False
if setName not in self.validMap[setGroup]: if setName not in self.validMap[setGroup]:
logger.error("Unknown option name '%s'" % setName) logger.error("Unknown option name '%s'", setName)
return False return False
if setGroup not in self.theState: if setGroup not in self.theState:
+33 -33
View File
@@ -369,7 +369,7 @@ class NWProject():
self.clearProject() self.clearProject()
self.projPath = os.path.abspath(os.path.dirname(fileName)) self.projPath = os.path.abspath(os.path.dirname(fileName))
logger.debug("Opening project: %s" % self.projPath) logger.debug("Opening project: %s", self.projPath)
# Standard Folders and Files # Standard Folders and Files
# ========================== # ==========================
@@ -385,7 +385,7 @@ class NWProject():
legacyList = [] # Cleanup is done later legacyList = [] # Cleanup is done later
for projItem in os.listdir(self.projPath): for projItem in os.listdir(self.projPath):
logger.verbose("Project contains: %s" % projItem) logger.verbose("Project contains: %s", projItem)
if projItem.startswith("data_"): if projItem.startswith("data_"):
legacyList.append(projItem) legacyList.append(projItem)
@@ -442,8 +442,8 @@ class NWProject():
hexVersion = xRoot.attrib.get("hexVersion", "0x0") hexVersion = xRoot.attrib.get("hexVersion", "0x0")
fileVersion = xRoot.attrib.get("fileVersion", self.tr("Unknown")) fileVersion = xRoot.attrib.get("fileVersion", self.tr("Unknown"))
logger.verbose("XML root is %s" % nwxRoot) logger.verbose("XML root is '%s'", nwxRoot)
logger.verbose("File version is %s" % fileVersion) logger.verbose("File version is '%s'", fileVersion)
# Check File Type # Check File Type
# =============== # ===============
@@ -503,13 +503,13 @@ class NWProject():
if xItem.text is None: if xItem.text is None:
continue continue
if xItem.tag == "name": if xItem.tag == "name":
logger.verbose("Working Title: '%s'" % xItem.text) logger.verbose("Working Title: '%s'", xItem.text)
self.projName = xItem.text self.projName = xItem.text
elif xItem.tag == "title": elif xItem.tag == "title":
logger.verbose("Title is '%s'" % xItem.text) logger.verbose("Title is '%s'", xItem.text)
self.bookTitle = xItem.text self.bookTitle = xItem.text
elif xItem.tag == "author": elif xItem.tag == "author":
logger.verbose("Author: '%s'" % xItem.text) logger.verbose("Author: '%s'", xItem.text)
self.bookAuthors.append(xItem.text) self.bookAuthors.append(xItem.text)
elif xItem.tag == "saveCount": elif xItem.tag == "saveCount":
self.saveCount = checkInt(xItem.text, 0) self.saveCount = checkInt(xItem.text, 0)
@@ -610,7 +610,7 @@ class NWProject():
if not self.ensureFolderStructure(): if not self.ensureFolderStructure():
return False return False
logger.debug("Saving project: %s" % self.projPath) logger.debug("Saving project: %s", self.projPath)
if autoSave: if autoSave:
self.autoCount += 1 self.autoCount += 1
@@ -783,7 +783,7 @@ class NWProject():
if not os.path.isdir(baseDir): if not os.path.isdir(baseDir):
try: try:
os.mkdir(baseDir) os.mkdir(baseDir)
logger.debug("Created folder %s" % baseDir) logger.debug("Created folder: %s", baseDir)
except Exception as e: except Exception as e:
self.theParent.makeAlert([ self.theParent.makeAlert([
self.tr("Could not create backup folder."), str(e) self.tr("Could not create backup folder."), str(e)
@@ -805,7 +805,7 @@ class NWProject():
self._clearLockFile() self._clearLockFile()
shutil.make_archive(baseName, "zip", self.projPath, ".") shutil.make_archive(baseName, "zip", self.projPath, ".")
self._writeLockFile() self._writeLockFile()
logger.info("Backup written to: %s" % archName) logger.info("Backup written to: %s", archName)
if doNotify: if doNotify:
self.theParent.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
"Backup archive file written to: {0}" "Backup archive file written to: {0}"
@@ -904,7 +904,7 @@ class NWProject():
if not os.path.isdir(projPath): if not os.path.isdir(projPath):
try: try:
os.mkdir(projPath) os.mkdir(projPath)
logger.debug("Created folder %s" % projPath) logger.debug("Created folder: %s", projPath)
except Exception as e: except Exception as e:
self.theParent.makeAlert([ self.theParent.makeAlert([
self.tr("Could not create new project folder."), str(e) self.tr("Could not create new project folder."), str(e)
@@ -1162,12 +1162,12 @@ class NWProject():
# Item's parent exists, but hasn't been sent yet, so add # Item's parent exists, but hasn't been sent yet, so add
# it again to the end, but make sure this doesn't get # it again to the end, but make sure this doesn't get
# out hand, so we cap at 10000 items # out hand, so we cap at 10000 items
logger.warning("Item %s found before its parent" % tHandle) logger.warning("Item '%s' found before its parent", tHandle)
iterItems.append(tHandle) iterItems.append(tHandle)
nMax = min(len(iterItems), 10000) nMax = min(len(iterItems), 10000)
else: else:
# Item is orphaned # Item is orphaned
logger.error("Item %s has no parent in current tree" % tHandle) logger.error("Item '%s' has no parent in current tree", tHandle)
tItem.setParent(None) tItem.setParent(None)
yield tItem yield tItem
@@ -1221,7 +1221,7 @@ class NWProject():
try: try:
with open(loadFile, mode="r", encoding="utf8") as inFile: with open(loadFile, mode="r", encoding="utf8") as inFile:
self.langData = json.load(inFile) self.langData = json.load(inFile)
logger.debug("Loaded project language file: %s" % os.path.basename(loadFile)) logger.debug("Loaded project language file: %s", os.path.basename(loadFile))
except Exception: except Exception:
logger.error("Failed to project language file") logger.error("Failed to project language file")
@@ -1299,7 +1299,7 @@ class NWProject():
if not os.path.isdir(thePath): if not os.path.isdir(thePath):
try: try:
os.mkdir(thePath) os.mkdir(thePath)
logger.debug("Created folder %s" % thePath) logger.debug("Created folder: %s", thePath)
except Exception as e: except Exception as e:
self.makeAlert([ self.makeAlert([
self.tr("Could not create folder."), str(e) self.tr("Could not create folder."), str(e)
@@ -1343,19 +1343,19 @@ class NWProject():
orphanFiles = [] orphanFiles = []
for fileItem in os.listdir(self.projContent): for fileItem in os.listdir(self.projContent):
if not fileItem.endswith(".nwd"): if not fileItem.endswith(".nwd"):
logger.warning("Skipping file %s" % fileItem) logger.warning("Skipping file: %s", fileItem)
continue continue
if len(fileItem) != 17: if len(fileItem) != 17:
logger.warning("Skipping file %s" % fileItem) logger.warning("Skipping file: %s", fileItem)
continue continue
fHandle = fileItem[:13] fHandle = fileItem[:13]
if not isHandle(fHandle): if not isHandle(fHandle):
logger.warning("Skipping file %s" % fileItem) logger.warning("Skipping file: %s", fileItem)
continue continue
if fHandle in self.projTree: if fHandle in self.projTree:
logger.debug("Checking file %s, handle %s: OK" % (fileItem, fHandle)) logger.debug("Checking file %s, handle '%s': OK", fileItem, fHandle)
else: else:
logger.warning("Checking file %s, handle %s: Orphaned" % (fileItem, fHandle)) logger.warning("Checking file %s, handle '%s': Orphaned", fileItem, fHandle)
orphanFiles.append(fHandle) orphanFiles.append(fHandle)
# Report status # Report status
@@ -1436,7 +1436,7 @@ class NWProject():
sessDiff = self.getSessionWordCount() sessDiff = self.getSessionWordCount()
sessTime = nowTime - self.projOpened sessTime = nowTime - self.projOpened
logger.info("The session lasted %d sec and added %d words" % (int(sessTime), sessDiff)) logger.info("The session lasted %d sec and added %d words", int(sessTime), sessDiff)
if sessTime < 300 and sessDiff == 0: if sessTime < 300 and sessDiff == 0:
logger.info("Session too short, skipping log entry") logger.info("Session too short, skipping log entry")
return False return False
@@ -1478,7 +1478,7 @@ class NWProject():
errList.append(self.tr("Not a folder: {0}").format(theData)) errList.append(self.tr("Not a folder: {0}").format(theData))
return errList return errList
logger.info("Old data folder %s found" % theFolder) logger.info("Old data folder %s found", theFolder)
# Move Documents to Content # Move Documents to Content
# ========================= # =========================
@@ -1495,20 +1495,20 @@ class NWProject():
newPath = os.path.join(self.projContent, tHandle+".nwd") newPath = os.path.join(self.projContent, tHandle+".nwd")
try: try:
os.rename(theFile, newPath) os.rename(theFile, newPath)
logger.info("Moved file: %s" % theFile) logger.info("Moved file: %s", theFile)
logger.info("New location: %s" % newPath) logger.info("New location: %s", newPath)
except Exception: except Exception:
errList.append(self.tr("Could not move: {0}").format(theFile)) errList.append(self.tr("Could not move: {0}").format(theFile))
logger.error("Could not move: %s" % theFile) logger.error("Could not move: %s", theFile)
nw.logException() nw.logException()
elif len(dataItem) == 21 and dataItem.endswith("_main.bak"): elif len(dataItem) == 21 and dataItem.endswith("_main.bak"):
try: try:
os.unlink(theFile) os.unlink(theFile)
logger.info("Deleted file: %s" % theFile) logger.info("Deleted file: %s", theFile)
except Exception: except Exception:
errList.append(self.tr("Could not delete: {0}").format(theFile)) errList.append(self.tr("Could not delete: {0}").format(theFile))
logger.error("Could not delete: %s" % theFile) logger.error("Could not delete: %s", theFile)
nw.logException() nw.logException()
else: else:
@@ -1520,10 +1520,10 @@ class NWProject():
# ================== # ==================
try: try:
os.rmdir(theData) os.rmdir(theData)
logger.info("Deleted folder: %s" % theFolder) logger.info("Deleted folder: %s", theFolder)
except Exception: except Exception:
errList.append(self.tr("Could not delete: {0}").format(theFolder)) errList.append(self.tr("Could not delete: {0}").format(theFolder))
logger.error("Could not delete: %s" % theFolder) logger.error("Could not delete: %s", theFolder)
nw.logException() nw.logException()
return errList return errList
@@ -1541,9 +1541,9 @@ class NWProject():
try: try:
os.rename(theSrc, theDst) os.rename(theSrc, theDst)
logger.info("Moved to junk: %s" % theSrc) logger.info("Moved to junk: %s", theSrc)
except Exception: except Exception:
logger.error("Could not move item %s to junk." % theSrc) logger.error("Could not move item %s to junk", theSrc)
nw.logException() nw.logException()
return self.tr("Could not move item {0} to {1}.").format(theSrc, theJunk) return self.tr("Could not move item {0} to {1}.").format(theSrc, theJunk)
@@ -1574,11 +1574,11 @@ class NWProject():
for rmFile in rmList: for rmFile in rmList:
if os.path.isfile(rmFile): if os.path.isfile(rmFile):
logger.info("Deleting: %s" % rmFile) logger.info("Deleting: %s", rmFile)
try: try:
os.unlink(rmFile) os.unlink(rmFile)
except Exception: except Exception:
logger.error("Could not delete: %s" % rmFile) logger.error("Could not delete: %s", rmFile)
nw.logException() nw.logException()
return False return False
+7 -7
View File
@@ -71,7 +71,7 @@ class NWSpellCheck():
outFile.write("%s\n" % newWord) outFile.write("%s\n" % newWord)
self.projDict.append(newWord) self.projDict.append(newWord)
except Exception: except Exception:
logger.error("Failed to add word to project word list %s" % str(self.projectDict)) logger.error("Failed to add word to project word list %s", str(self.projectDict))
nw.logException() nw.logException()
return False return False
return True return True
@@ -111,7 +111,7 @@ class NWSpellCheck():
theLine = theLine.strip() theLine = theLine.strip()
if len(theLine) > 0 and theLine not in self.projDict: if len(theLine) > 0 and theLine not in self.projDict:
self.projDict.append(theLine) self.projDict.append(theLine)
logger.debug("Project word list contains %d words" % len(self.projDict)) logger.debug("Project word list contains %d words", len(self.projDict))
except Exception: except Exception:
logger.error("Failed to load project word list") logger.error("Failed to load project word list")
@@ -149,10 +149,10 @@ class NWSpellEnchant(NWSpellCheck):
self.theBroker = enchant.Broker() self.theBroker = enchant.Broker()
self.theDict = self.theBroker.request_dict(theLang) self.theDict = self.theBroker.request_dict(theLang)
self.spellLanguage = theLang self.spellLanguage = theLang
logger.debug("Enchant spell checking for language %s loaded" % theLang) logger.debug("Enchant spell checking for language '%s' loaded", theLang)
except Exception: except Exception:
logger.error("Failed to load enchant spell checking for language %s" % theLang) logger.error("Failed to load enchant spell checking for language '%s'", theLang)
self.theDict = FakeEnchant() self.theDict = FakeEnchant()
self.spellLanguage = None self.spellLanguage = None
@@ -259,12 +259,12 @@ class NWSpellSimple(NWSpellCheck):
continue continue
self.theWords.add(theLine.strip().lower()) self.theWords.add(theLine.strip().lower())
logger.debug("Spell check dictionary for language %s loaded" % theLang) logger.debug("Spell check dictionary for language '%s' loaded", theLang)
logger.debug("Dictionary contains %d words" % len(self.theWords)) logger.debug("Dictionary contains %d words", len(self.theWords))
self.spellLanguage = theLang self.spellLanguage = theLang
except Exception: except Exception:
logger.error("Failed to load spell check word list for language %s" % theLang) logger.error("Failed to load spell check word list for language '%s'", theLang)
nw.logException() nw.logException()
self.spellLanguage = None self.spellLanguage = None
+2 -2
View File
@@ -644,7 +644,7 @@ class ToOdt(Tokenizer):
""" """
refStyle = self._mainPara.get(parName, None) refStyle = self._mainPara.get(parName, None)
if refStyle is None: if refStyle is None:
logger.error("Unknown paragraph style '%s'" % parName) logger.error("Unknown paragraph style '%s'", parName)
return "Standard" return "Standard"
if not refStyle.checkNew(oStyle): if not refStyle.checkNew(oStyle):
@@ -1295,5 +1295,5 @@ def _mkTag(nsName, tagName):
theNS = XML_NS.get(nsName, "") theNS = XML_NS.get(nsName, "")
if theNS: if theNS:
return "{%s}%s" % (theNS, tagName) return "{%s}%s" % (theNS, tagName)
logger.warning("Missing xml namespace '%s'" % nsName) logger.warning("Missing xml namespace '%s'", nsName)
return tagName return tagName
+14 -13
View File
@@ -111,24 +111,24 @@ class NWTree():
tHandle = self._makeHandle() tHandle = self._makeHandle()
if tHandle in self._projTree: if tHandle in self._projTree:
logger.warning("Duplicate handle %s detected, skipping" % tHandle) logger.warning("Duplicate handle '%s' detected, skipping", tHandle)
return False return False
logger.verbose("Adding item %s with parent %s" % (str(tHandle), str(pHandle))) logger.verbose("Adding item '%s' with parent '%s'", str(tHandle), str(pHandle))
nwItem.setHandle(tHandle) nwItem.setHandle(tHandle)
nwItem.setParent(pHandle) nwItem.setParent(pHandle)
if nwItem.itemType == nwItemType.ROOT: if nwItem.itemType == nwItemType.ROOT:
logger.verbose("Item %s is a root item" % str(tHandle)) logger.verbose("Item '%s' is a root item", str(tHandle))
self._treeRoots.append(tHandle) self._treeRoots.append(tHandle)
if nwItem.itemClass == nwItemClass.ARCHIVE: if nwItem.itemClass == nwItemClass.ARCHIVE:
logger.verbose("Item %s is the archive folder" % str(tHandle)) logger.verbose("Item '%s' is the archive folder", str(tHandle))
self._archRoot = tHandle self._archRoot = tHandle
if nwItem.itemType == nwItemType.TRASH: if nwItem.itemType == nwItemType.TRASH:
if self._trashRoot is None: if self._trashRoot is None:
logger.verbose("Item %s is the trash folder" % str(tHandle)) logger.verbose("Item '%s' is the trash folder", str(tHandle))
self._trashRoot = tHandle self._trashRoot = tHandle
else: else:
logger.error("Only one trash folder allowed") logger.error("Only one trash folder allowed")
@@ -245,9 +245,10 @@ class NWTree():
if iLayout in LAYOUT_MAP: if iLayout in LAYOUT_MAP:
if hLevel in LAYOUT_MAP[iLayout]: if hLevel in LAYOUT_MAP[iLayout]:
tItem.itemLayout = LAYOUT_MAP[iLayout][hLevel] tItem.itemLayout = LAYOUT_MAP[iLayout][hLevel]
logger.debug("Changed layout for %s from %s to %s" % ( logger.debug(
"Changed layout for %s from %s to %s",
tHandle, iLayout.name, tItem.itemLayout.name tHandle, iLayout.name, tItem.itemLayout.name
)) )
return True return True
return False return False
@@ -357,13 +358,13 @@ class NWTree():
if tHandle in self._projTree: if tHandle in self._projTree:
tmpOrder.append(tHandle) tmpOrder.append(tHandle)
else: else:
logger.error("Handle %s in new tree order is not in project tree" % tHandle) logger.error("Handle '%s' in new tree order is not in project tree", tHandle)
# Do a reverse lookup to check for items that will be lost # Do a reverse lookup to check for items that will be lost
# This is mainly for debugging purposes # This is mainly for debugging purposes
for tHandle in self._treeOrder: for tHandle in self._treeOrder:
if tHandle not in tmpOrder: if tHandle not in tmpOrder:
logger.warning("Handle %s in old tree order is not in new tree order" % tHandle) logger.warning("Handle '%s' in old tree order is not in new tree order", tHandle)
# Save the temp list # Save the temp list
self._treeOrder = tmpOrder self._treeOrder = tmpOrder
@@ -387,7 +388,7 @@ class NWTree():
if tItem is None: if tItem is None:
return False return False
if tItem.itemType != nwItemType.FILE: if tItem.itemType != nwItemType.FILE:
logger.error("Item %s is not a file" % tHandle) logger.error("Item %s is not a file", tHandle)
return False return False
if not isinstance(itemLayout, nwItemLayout): if not isinstance(itemLayout, nwItemLayout):
return False return False
@@ -444,7 +445,7 @@ class NWTree():
""" """
if tHandle in self._projTree: if tHandle in self._projTree:
return self._projTree[tHandle] return self._projTree[tHandle]
logger.error("No tree item with handle %s" % str(tHandle)) logger.error("No tree item with handle '%s'", str(tHandle))
return None return None
def __delitem__(self, tHandle): def __delitem__(self, tHandle):
@@ -454,7 +455,7 @@ class NWTree():
self._treeOrder.remove(tHandle) self._treeOrder.remove(tHandle)
del self._projTree[tHandle] del self._projTree[tHandle]
else: else:
logger.warning("Failed to delete item %s: item not found" % tHandle) logger.warning("Failed to delete item '%s': item not found", tHandle)
return return
if tHandle in self._treeRoots: if tHandle in self._treeRoots:
@@ -523,7 +524,7 @@ class NWTree():
newSeed = str(self._handleSeed) newSeed = str(self._handleSeed)
self._handleSeed += 1 self._handleSeed += 1
logger.verbose("Generating handle with seed '%s'" % newSeed) logger.verbose("Generating handle with seed '%s'", newSeed)
itemHandle = sha256(newSeed.encode()).hexdigest()[0:13] itemHandle = sha256(newSeed.encode()).hexdigest()[0:13]
if itemHandle in self._projTree: if itemHandle in self._projTree:
logger.warning("Duplicate handle encountered! Retrying ...") logger.warning("Duplicate handle encountered! Retrying ...")
+1 -1
View File
@@ -191,7 +191,7 @@ class GuiDocSplit(QDialog):
srcItem.itemName, srcItem.itemClass, srcItem.itemParent srcItem.itemName, srcItem.itemClass, srcItem.itemParent
) )
self.theParent.treeView.revealNewTreeItem(fHandle) self.theParent.treeView.revealNewTreeItem(fHandle)
logger.verbose("Creating folder %s" % fHandle) logger.verbose("Creating folder '%s'", fHandle)
# Loop through, and create the files # Loop through, and create the files
for wTitle, iStart, iEnd in finalOrder: for wTitle, iStart, iEnd in finalOrder:
+2 -2
View File
@@ -43,7 +43,7 @@ def logException():
"""Log the content of an exception message. """Log the content of an exception message.
""" """
exType, exValue, _ = sys.exc_info() exType, exValue, _ = sys.exc_info()
logger.error("%s: %s" % (exType.__name__, str(exValue).strip("'"))) logger.error("%s: %s", exType.__name__, str(exValue).strip("'"))
# =============================================================================================== # # =============================================================================================== #
@@ -159,7 +159,7 @@ def exceptionHandler(exType, exValue, exTrace):
from traceback import print_tb from traceback import print_tb
from PyQt5.QtWidgets import qApp from PyQt5.QtWidgets import qApp
logger.critical("%s: %s" % (exType.__name__, str(exValue))) logger.critical("%s: %s", exType.__name__, str(exValue))
print_tb(exTrace) print_tb(exTrace)
try: try:
+25 -24
View File
@@ -343,7 +343,7 @@ class GuiDocEditor(QTextEdit):
self._allowAutoReplace(True) self._allowAutoReplace(True)
afTime = time() afTime = time()
logger.debug("Document highlighted in %.3f ms" % (1000*(afTime-bfTime))) logger.debug("Document highlighted in %.3f ms", 1000*(afTime-bfTime))
self._lastEdit = time() self._lastEdit = time()
self._lastActive = time() self._lastActive = time()
@@ -438,9 +438,9 @@ class GuiDocEditor(QTextEdit):
tHandle = self._nwItem.itemHandle tHandle = self._nwItem.itemHandle
if self._docHandle != tHandle: if self._docHandle != tHandle:
logger.error("Editor handle %s and item handle %s do not match" % ( logger.error(
self._docHandle, tHandle "Editor handle '%s' and item handle '%s' do not match", self._docHandle, tHandle
)) )
return False return False
docText = self.getText() docText = self.getText()
@@ -656,7 +656,7 @@ class GuiDocEditor(QTextEdit):
if theBlock: if theBlock:
self.setCursorPosition(theBlock.position()) self.setCursorPosition(theBlock.position())
self.docFooter.updateLineCount() self.docFooter.updateLineCount()
logger.verbose("Cursor moved to line %d" % theLine) logger.verbose("Cursor moved to line %d", theLine)
return True return True
@@ -703,7 +703,7 @@ class GuiDocEditor(QTextEdit):
if not self._bigDoc: if not self._bigDoc:
self.spellCheckDocument() self.spellCheckDocument()
logger.verbose("Spell check is set to %s" % str(theMode)) logger.verbose("Spell check is set to '%s'", str(theMode))
return True return True
@@ -723,7 +723,7 @@ class GuiDocEditor(QTextEdit):
self.hLight.rehighlight() self.hLight.rehighlight()
qApp.restoreOverrideCursor() qApp.restoreOverrideCursor()
afTime = time() afTime = time()
logger.debug("Document highlighted in %.3f ms" % (1000*(afTime-bfTime))) logger.debug("Document highlighted in %.3f ms", 1000*(afTime-bfTime))
self.theParent.statusBar.setStatus(self.tr("Spell check complete")) self.theParent.statusBar.setStatus(self.tr("Spell check complete"))
return True return True
@@ -739,7 +739,7 @@ class GuiDocEditor(QTextEdit):
passed to it without having to consider the internal logic of passed to it without having to consider the internal logic of
this class when calling these actions from other classes. this class when calling these actions from other classes.
""" """
logger.verbose("Requesting action: %s" % theAction.name) logger.verbose("Requesting action: '%s'", theAction.name)
if self._docHandle is None: if self._docHandle is None:
logger.error("No document open") logger.error("No document open")
return False return False
@@ -798,7 +798,7 @@ class GuiDocEditor(QTextEdit):
elif theAction == nwDocAction.INDENT_R: elif theAction == nwDocAction.INDENT_R:
self._formatBlock(nwDocAction.INDENT_R) self._formatBlock(nwDocAction.INDENT_R)
else: else:
logger.debug("Unknown or unsupported document action %s" % str(theAction)) logger.debug("Unknown or unsupported document action '%s'", str(theAction))
self._allowAutoReplace(True) self._allowAutoReplace(True)
return False return False
@@ -871,15 +871,15 @@ class GuiDocEditor(QTextEdit):
If the insert line is not blank, a new line is started. If the insert line is not blank, a new line is started.
""" """
if keyWord not in nwKeyWords.VALID_KEYS: if keyWord not in nwKeyWords.VALID_KEYS:
logger.error("Invalid keyword '%s'" % keyWord) logger.error("Invalid keyword '%s'", keyWord)
return False return False
logger.verbose("Inserting keyword '%s'" % keyWord) logger.verbose("Inserting keyword '%s'", keyWord)
theCursor = self.textCursor() theCursor = self.textCursor()
theBlock = theCursor.block() theBlock = theCursor.block()
if not theBlock.isValid(): if not theBlock.isValid():
logger.error("Failed to insert keyword '%s'" % keyWord) logger.error("Failed to insert keyword '%s'", keyWord)
return False return False
theCursor.beginEditBlock() theCursor.beginEditBlock()
@@ -1102,7 +1102,7 @@ class GuiDocEditor(QTextEdit):
spellCheck &= theWord != "" spellCheck &= theWord != ""
if spellCheck: if spellCheck:
logger.verbose("Looking up '%s' in the dictionary" % theWord) logger.verbose("Looking up '%s' in the dictionary", theWord)
spellCheck &= not self._theDict.checkWord(theWord) spellCheck &= not self._theDict.checkWord(theWord)
if spellCheck: if spellCheck:
@@ -1154,7 +1154,7 @@ class GuiDocEditor(QTextEdit):
wants to add a word to the project dictionary. wants to add a word to the project dictionary.
""" """
theWord = theCursor.selectedText().strip().strip(self._nonWord) theWord = theCursor.selectedText().strip().strip(self._nonWord)
logger.debug("Added '%s' to project dictionary" % theWord) logger.debug("Added '%s' to project dictionary", theWord)
self._theDict.addWord(theWord) self._theDict.addWord(theWord)
self.hLight.setDict(self._theDict) self.hLight.setDict(self._theDict)
self.hLight.rehighlightBlock(theCursor.block()) self.hLight.rehighlightBlock(theCursor.block())
@@ -1215,11 +1215,11 @@ class GuiDocEditor(QTextEdit):
QPointF(theSize.width(), theSize.height()), Qt.FuzzyHit QPointF(theSize.width(), theSize.height()), Qt.FuzzyHit
) )
if self._queuePos <= thePos: if self._queuePos <= thePos:
logger.verbose("Allowed cursor move to %d <= %d" % (self._queuePos, thePos)) logger.verbose("Allowed cursor move to %d <= %d", self._queuePos, thePos)
self.setCursorPosition(self._queuePos) self.setCursorPosition(self._queuePos)
self._queuePos = None self._queuePos = None
else: else:
logger.verbose("Denied cursor move to %d > %d" % (self._queuePos, thePos)) logger.verbose("Denied cursor move to %d > %d", self._queuePos, thePos)
return return
## ##
@@ -1350,9 +1350,10 @@ class GuiDocEditor(QTextEdit):
theCursor.endEditBlock() theCursor.endEditBlock()
theCursor.setPosition(theCursor.selectionEnd()) theCursor.setPosition(theCursor.selectionEnd())
self.setTextCursor(theCursor) self.setTextCursor(theCursor)
logger.verbose("Replaced occurrence of '%s' with '%s' on line %d" % ( logger.verbose(
"Replaced occurrence of '%s' with '%s' on line %d",
searchFor, replWith, theCursor.blockNumber() searchFor, replWith, theCursor.blockNumber()
)) )
else: else:
logger.error("The selected text is not a search result, skipping replace") logger.error("The selected text is not a search result, skipping replace")
@@ -1390,10 +1391,10 @@ class GuiDocEditor(QTextEdit):
return False return False
if loadTag: if loadTag:
logger.verbose("Attempting to follow tag '%s'" % theWord) logger.verbose("Attempting to follow tag '%s'", theWord)
self.theParent.docViewer.loadFromTag(theWord) self.theParent.docViewer.loadFromTag(theWord)
else: else:
logger.verbose("Potential tag '%s'" % theWord) logger.verbose("Potential tag '%s'", theWord)
return True return True
@@ -1713,12 +1714,12 @@ class GuiDocEditor(QTextEdit):
theCursor = self.textCursor() theCursor = self.textCursor()
theBlock = theCursor.block() theBlock = theCursor.block()
if not theBlock.isValid(): if not theBlock.isValid():
logger.debug("Invalid block selected for action %s" % str(docAction)) logger.debug("Invalid block selected for action '%s'", str(docAction))
return False return False
theText = theBlock.text() theText = theBlock.text()
if len(theText.strip()) == 0: if len(theText.strip()) == 0:
logger.debug("Empty block selected for action %s" % str(docAction)) logger.debug("Empty block selected for action '%s'", str(docAction))
return False return False
# Remove existing format first, if any # Remove existing format first, if any
@@ -1805,7 +1806,7 @@ class GuiDocEditor(QTextEdit):
elif docAction == nwDocAction.BLOCK_TXT: elif docAction == nwDocAction.BLOCK_TXT:
theText = newText theText = newText
else: else:
logger.error("Unknown or unsupported block format requested: %s" % str(docAction)) logger.error("Unknown or unsupported block format requested: '%s'", str(docAction))
return False return False
# Replace the block text # Replace the block text
@@ -2208,7 +2209,7 @@ class GuiDocEditSearch(QFrame):
self.searchBox.selectAll() self.searchBox.selectAll()
if self.isRegEx: if self.isRegEx:
self._alertSearchValid(True) self._alertSearchValid(True)
logger.verbose("Setting search text to '%s'" % theText) logger.verbose("Setting search text to '%s'", theText)
return True return True
def setReplaceText(self, theText): def setReplaceText(self, theText):
+12 -12
View File
@@ -167,7 +167,7 @@ class GuiDocViewer(QTextBrowser):
if tItem.itemType != nwItemType.FILE: if tItem.itemType != nwItemType.FILE:
return False return False
logger.debug("Generating preview for item %s" % tHandle) logger.debug("Generating preview for item '%s'", tHandle)
qApp.setOverrideCursor(QCursor(Qt.WaitCursor)) qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
sPos = self.verticalScrollBar().value() sPos = self.verticalScrollBar().value()
@@ -185,7 +185,7 @@ class GuiDocViewer(QTextBrowser):
aDoc.doConvert() aDoc.doConvert()
aDoc.doPostProcessing() aDoc.doPostProcessing()
except Exception: except Exception:
logger.error("Failed to generate preview for document with handle '%s'" % tHandle) logger.error("Failed to generate preview for document with handle '%s'", tHandle)
nw.logException() nw.logException()
self.setText(self.tr("An error occurred while generating the preview.")) self.setText(self.tr("An error occurred while generating the preview."))
@@ -243,7 +243,7 @@ class GuiDocViewer(QTextBrowser):
tag rather than a known handle. This function depends on the tag rather than a known handle. This function depends on the
index being up to date. index being up to date.
""" """
logger.debug("Loading document from tag '%s'" % theTag) logger.debug("Loading document from tag '%s'", theTag)
tHandle, _, sTitle = self.theParent.theIndex.getTagSource(theTag) tHandle, _, sTitle = self.theParent.theIndex.getTagSource(theTag)
if tHandle is None: if tHandle is None:
self.theParent.makeAlert(self.tr( self.theParent.makeAlert(self.tr(
@@ -258,7 +258,7 @@ class GuiDocViewer(QTextBrowser):
# Let the parent handle the opening as it also ensures that # Let the parent handle the opening as it also ensures that
# the doc view panel is visible in case this request comes # the doc view panel is visible in case this request comes
# from outside this class. # from outside this class.
logger.verbose("Tag points to %s#%s" % (tHandle, sTitle)) logger.verbose("Tag points to '%s#%s'", tHandle, sTitle)
self.theParent.viewDocument(tHandle, "#%s" % sTitle) self.theParent.viewDocument(tHandle, "#%s" % sTitle)
return True return True
@@ -266,7 +266,7 @@ class GuiDocViewer(QTextBrowser):
"""Wrapper function for various document actions on the current """Wrapper function for various document actions on the current
document. document.
""" """
logger.verbose("Requesting action: %s" % theAction.name) logger.verbose("Requesting action: '%s'", theAction.name)
if self._docHandle is None: if self._docHandle is None:
logger.error("No document open") logger.error("No document open")
return False return False
@@ -279,7 +279,7 @@ class GuiDocViewer(QTextBrowser):
elif theAction == nwDocAction.SEL_PARA: elif theAction == nwDocAction.SEL_PARA:
self._makeSelection(QTextCursor.BlockUnderCursor) self._makeSelection(QTextCursor.BlockUnderCursor)
else: else:
logger.debug("Unknown or unsupported document action %s" % str(theAction)) logger.debug("Unknown or unsupported document action '%s'", str(theAction))
return False return False
return True return True
@@ -289,7 +289,7 @@ class GuiDocViewer(QTextBrowser):
if not isinstance(tAnchor, str): if not isinstance(tAnchor, str):
return False return False
if tAnchor.startswith("#"): if tAnchor.startswith("#"):
logger.verbose("Moving to anchor %s" % tAnchor) logger.verbose("Moving to anchor '%s'", tAnchor)
self.setSource(QUrl(tAnchor)) self.setSource(QUrl(tAnchor))
return True return True
@@ -378,7 +378,7 @@ class GuiDocViewer(QTextBrowser):
theBlock = self._qDocument.findBlockByLineNumber(theLine) theBlock = self._qDocument.findBlockByLineNumber(theLine)
if theBlock: if theBlock:
self.setCursorPosition(theBlock.position()) self.setCursorPosition(theBlock.position())
logger.verbose("Cursor moved to line %d" % theLine) logger.verbose("Cursor moved to line %d", theLine)
return True return True
def setScrollPosition(self, thePos): def setScrollPosition(self, thePos):
@@ -410,7 +410,7 @@ class GuiDocViewer(QTextBrowser):
"""Slot for a link in the document being clicked. """Slot for a link in the document being clicked.
""" """
theLink = theURL.url() theLink = theURL.url()
logger.verbose("Clicked link: '%s'" % theLink) logger.verbose("Clicked link: '%s'", theLink)
if len(theLink) > 0: if len(theLink) > 0:
theBits = theLink.split("=") theBits = theLink.split("=")
if len(theBits) == 2: if len(theBits) == 2:
@@ -617,7 +617,7 @@ class GuiDocViewHistory():
self._dumpHistory() self._dumpHistory()
logger.verbose("Added %s to view history" % tHandle) logger.verbose("Added '%s' to view history", tHandle)
return True return True
@@ -1114,7 +1114,7 @@ class GuiDocViewFooter(QWidget):
def _doToggleSticky(self, theState): def _doToggleSticky(self, theState):
"""Toggle the sticky flag for the reference panel. """Toggle the sticky flag for the reference panel.
""" """
logger.verbose("Reference sticky is %s" % str(theState)) logger.verbose("Reference sticky is %s", str(theState))
self.docViewer.stickyRef = theState self.docViewer.stickyRef = theState
if not theState and self.docViewer.docHandle() is not None: if not theState and self.docViewer.docHandle() is not None:
self.viewMeta.refreshReferences(self.docViewer.docHandle()) self.viewMeta.refreshReferences(self.docViewer.docHandle())
@@ -1210,7 +1210,7 @@ class GuiDocViewDetails(QScrollArea):
"""Capture the link-click and forward it to the document viewer """Capture the link-click and forward it to the document viewer
class for handling. class for handling.
""" """
logger.verbose("Clicked link: '%s'" % theLink) logger.verbose("Clicked link: '%s'", theLink)
if len(theLink) == 21: if len(theLink) == 21:
tHandle = theLink[:13] tHandle = theLink[:13]
tAnchor = theLink[13:] tAnchor = theLink[13:]
+1 -1
View File
@@ -222,7 +222,7 @@ class GuiNovelTree(QTreeWidget):
tHandle = theData[0] tHandle = theData[0]
tLine = checkInt(theData[1], 1) tLine = checkInt(theData[1], 1)
logger.verbose("User selected entry with handle %s on line %s" % (tHandle, tLine)) logger.verbose("User selected entry with handle '%s' on line %s", tHandle, tLine)
self.theParent.openDocument(tHandle, tLine=tLine-1, doScroll=True) self.theParent.openDocument(tHandle, tLine=tLine-1, doScroll=True)
return return
+6 -6
View File
@@ -212,7 +212,7 @@ class GuiOutline(QTreeWidget):
except Exception: except Exception:
tLine = 1 tLine = 1
logger.verbose("User selected entry with handle %s on line %s" % (tHandle, tLine)) logger.verbose("User selected entry with handle '%s' on line %s", tHandle, tLine)
self.theParent.openDocument(tHandle, tLine=tLine-1, doScroll=True) self.theParent.openDocument(tHandle, tLine=tLine-1, doScroll=True)
return return
@@ -248,7 +248,7 @@ class GuiOutline(QTreeWidget):
"""Receive the changes to column visibility forwarded by the """Receive the changes to column visibility forwarded by the
header context menu. header context menu.
""" """
logger.verbose("User toggled Outline column '%s'" % theItem.name) logger.verbose("User toggled Outline column '%s'", theItem.name)
if theItem in self.colIndex: if theItem in self.colIndex:
self.setColumnHidden(self.colIndex[theItem], not isChecked) self.setColumnHidden(self.colIndex[theItem], not isChecked)
self._saveHeaderState() self._saveHeaderState()
@@ -272,7 +272,7 @@ class GuiOutline(QTreeWidget):
try: try:
treeOrder.append(nwOutline[hName]) treeOrder.append(nwOutline[hName])
except Exception: except Exception:
logger.warning("Ignored unknown outline column '%s'" % str(hName)) logger.warning("Ignored unknown outline column '%s'", str(hName))
# Add columns that was not in the file to the treeOrder array. # Add columns that was not in the file to the treeOrder array.
for hItem in nwOutline: for hItem in nwOutline:
@@ -285,7 +285,7 @@ class GuiOutline(QTreeWidget):
self.treeOrder = treeOrder self.treeOrder = treeOrder
else: else:
logger.error("Failed to extract outline column order from previous session") logger.error("Failed to extract outline column order from previous session")
logger.error("Column count doesn't match %d != %d" % (len(treeOrder), self.treeNCols)) logger.error("Column count doesn't match %d != %d", len(treeOrder), self.treeNCols)
# We load whatever column widths and hidden states we find in # We load whatever column widths and hidden states we find in
# the file, and leave the rest in their default state. # the file, and leave the rest in their default state.
@@ -294,14 +294,14 @@ class GuiOutline(QTreeWidget):
try: try:
self.colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName]) self.colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName])
except Exception: except Exception:
logger.warning("Ignored unknown outline column '%s'" % str(hName)) logger.warning("Ignored unknown outline column '%s'", str(hName))
tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {}) tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {})
for hName in tmpHidden: for hName in tmpHidden:
try: try:
self.colHidden[nwOutline[hName]] = tmpHidden[hName] self.colHidden[nwOutline[hName]] = tmpHidden[hName]
except Exception: except Exception:
logger.warning("Ignored unknown outline column '%s'" % str(hName)) logger.warning("Ignored unknown outline column '%s'", str(hName))
self.headerMenu.setHiddenState(self.colHidden) self.headerMenu.setHiddenState(self.colHidden)
+1 -1
View File
@@ -323,7 +323,7 @@ class GuiOutlineDetails(QScrollArea):
def _tagClicked(self, theLink): def _tagClicked(self, theLink):
"""Capture the click of a tag in the right-most column. """Capture the click of a tag in the right-most column.
""" """
logger.verbose("Clicked link: '%s'" % theLink) logger.verbose("Clicked link: '%s'", theLink)
if len(theLink) > 0: if len(theLink) > 0:
theBits = theLink.split("=") theBits = theLink.split("=")
if len(theBits) == 2: if len(theBits) == 2:
+19 -19
View File
@@ -207,8 +207,9 @@ class GuiProjectTree(QTreeWidget):
return False return False
# Everything is fine, we have what we need, so we proceed # Everything is fine, we have what we need, so we proceed
logger.verbose("Adding new item of type %s and class %s to handle %s" % ( logger.verbose(
itemType.name, itemClass.name, str(pHandle)) "Adding new item of type '%s' and class '%s' to handle '%s'",
itemType.name, itemClass.name, str(pHandle)
) )
if itemType == nwItemType.ROOT: if itemType == nwItemType.ROOT:
@@ -454,7 +455,7 @@ class GuiProjectTree(QTreeWidget):
if not msgYes: if not msgYes:
return False return False
logger.verbose("Deleting %d file(s) from Trash" % nTrash) logger.verbose("Deleting %d file(s) from Trash", nTrash)
for tHandle in self.getTreeFromHandle(trashHandle): for tHandle in self.getTreeFromHandle(trashHandle):
if tHandle == trashHandle: if tHandle == trashHandle:
continue continue
@@ -496,7 +497,7 @@ class GuiProjectTree(QTreeWidget):
wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole)) wCount = int(trItemS.data(self.C_COUNT, Qt.UserRole))
if nwItemS.itemType == nwItemType.FILE: if nwItemS.itemType == nwItemType.FILE:
logger.debug("User requested file %s deleted" % tHandle) logger.debug("User requested file '%s' deleted", tHandle)
trItemP = trItemS.parent() trItemP = trItemS.parent()
trItemT = self._addTrashRoot() trItemT = self._addTrashRoot()
if trItemP is None or trItemT is None: if trItemP is None or trItemT is None:
@@ -519,7 +520,7 @@ class GuiProjectTree(QTreeWidget):
doPermanent = True doPermanent = True
if doPermanent: if doPermanent:
logger.debug("Permanently deleting file with handle %s" % tHandle) logger.debug("Permanently deleting file with handle '%s'", tHandle)
self.propagateCount(tHandle, 0) self.propagateCount(tHandle, 0)
tIndex = trItemP.indexOfChild(trItemS) tIndex = trItemP.indexOfChild(trItemS)
@@ -551,7 +552,7 @@ class GuiProjectTree(QTreeWidget):
if pHandle is None: if pHandle is None:
logger.warning("File has no parent item") logger.warning("File has no parent item")
logger.debug("Moving file %s to trash" % tHandle) logger.debug("Moving file '%s' to trash", tHandle)
self.propagateCount(tHandle, 0) self.propagateCount(tHandle, 0)
tIndex = trItemP.indexOfChild(trItemS) tIndex = trItemP.indexOfChild(trItemS)
@@ -565,7 +566,7 @@ class GuiProjectTree(QTreeWidget):
self._setTreeChanged(True) self._setTreeChanged(True)
elif nwItemS.itemType == nwItemType.FOLDER: elif nwItemS.itemType == nwItemType.FOLDER:
logger.debug("User requested folder %s deleted" % tHandle) logger.debug("User requested folder '%s' deleted", tHandle)
trItemP = trItemS.parent() trItemP = trItemS.parent()
if trItemP is None: if trItemP is None:
logger.error("Could not delete folder") logger.error("Could not delete folder")
@@ -584,7 +585,7 @@ class GuiProjectTree(QTreeWidget):
return False return False
elif nwItemS.itemType == nwItemType.ROOT: elif nwItemS.itemType == nwItemType.ROOT:
logger.debug("User requested root folder %s deleted" % tHandle) logger.debug("User requested root folder '%s' deleted", tHandle)
tIndex = self.indexOfTopLevelItem(trItemS) tIndex = self.indexOfTopLevelItem(trItemS)
if trItemS.childCount() == 0: if trItemS.childCount() == 0:
self.takeTopLevelItem(tIndex) self.takeTopLevelItem(tIndex)
@@ -695,7 +696,7 @@ class GuiProjectTree(QTreeWidget):
iCount += 1 iCount += 1
self._addTreeItem(nwItem) self._addTreeItem(nwItem)
logger.debug("%d items added to the project tree" % iCount) logger.debug("%d item(s) added to the project tree", iCount)
return True return True
def undoLastMove(self): def undoLastMove(self):
@@ -724,9 +725,7 @@ class GuiProjectTree(QTreeWidget):
wCount = int(srcItem.data(self.C_COUNT, Qt.UserRole)) wCount = int(srcItem.data(self.C_COUNT, Qt.UserRole))
sHandle = srcItem.data(self.C_NAME, Qt.UserRole) sHandle = srcItem.data(self.C_NAME, Qt.UserRole)
dHandle = dstItem.data(self.C_NAME, Qt.UserRole) dHandle = dstItem.data(self.C_NAME, Qt.UserRole)
logger.debug("Moving item %s back to %s, index %d" % ( logger.debug("Moving item '%s' back to '%s', index %d", sHandle, dHandle, dstIndex)
sHandle, dHandle, dstIndex
))
self.propagateCount(sHandle, 0) self.propagateCount(sHandle, 0)
parItem = srcItem.parent() parItem = srcItem.parent()
@@ -882,7 +881,7 @@ class GuiProjectTree(QTreeWidget):
allowDrop &= not (self.dropIndicatorPosition() == QAbstractItemView.OnItem and onFile) allowDrop &= not (self.dropIndicatorPosition() == QAbstractItemView.OnItem and onFile)
if allowDrop and not isRoot: if allowDrop and not isRoot:
logger.debug("Drag'n'drop of item %s accepted" % sHandle) logger.debug("Drag'n'drop of item '%s' accepted", sHandle)
self.propagateCount(sHandle, 0) self.propagateCount(sHandle, 0)
QTreeWidget.dropEvent(self, theEvent) QTreeWidget.dropEvent(self, theEvent)
self._postItemMove(sHandle, snItem, dnItem, wCount) self._postItemMove(sHandle, snItem, dnItem, wCount)
@@ -890,7 +889,7 @@ class GuiProjectTree(QTreeWidget):
else: else:
theEvent.ignore() theEvent.ignore()
logger.debug("Drag'n'drop of item %s not accepted" % sHandle) logger.debug("Drag'n'drop of item '%s' not accepted", sHandle)
self.makeAlert(self.tr( self.makeAlert(self.tr(
"The item cannot be moved to that location." "The item cannot be moved to that location."
), nwAlert.ERROR) ), nwAlert.ERROR)
@@ -913,9 +912,10 @@ class GuiProjectTree(QTreeWidget):
# If the item does not have the same class as the target, # If the item does not have the same class as the target,
# and the target is not a free root folder, update its class # and the target is not a free root folder, update its class
if not (isSame or onFree): if not (isSame or onFree):
logger.debug("Item %s class has been changed from %s to %s" % ( logger.debug(
"Item '%s' class has been changed from '%s' to '%s'",
sHandle, snItem.itemClass.name, dnItem.itemClass.name sHandle, snItem.itemClass.name, dnItem.itemClass.name
)) )
snItem.setClass(dnItem.itemClass) snItem.setClass(dnItem.itemClass)
self.setTreeItemValues(sHandle) self.setTreeItemValues(sHandle)
@@ -1002,7 +1002,7 @@ class GuiProjectTree(QTreeWidget):
try: try:
byIndex = self._treeMap[pHandle].indexOfChild(self._treeMap[nHandle]) byIndex = self._treeMap[pHandle].indexOfChild(self._treeMap[nHandle])
except Exception: except Exception:
logger.error("Failed to get index of item with handle %s" % nHandle) logger.error("Failed to get index of item with handle '%s'", nHandle)
if byIndex >= 0: if byIndex >= 0:
self._treeMap[pHandle].insertChild(byIndex+1, newItem) self._treeMap[pHandle].insertChild(byIndex+1, newItem)
else: else:
@@ -1052,14 +1052,14 @@ class GuiProjectTree(QTreeWidget):
nwItemS = self.theProject.projTree[tHandle] nwItemS = self.theProject.projTree[tHandle]
trItemP = trItemS.parent() trItemP = trItemS.parent()
if trItemP is None: if trItemP is None:
logger.error("Failed to find new parent item of %s" % tHandle) logger.error("Failed to find new parent item of '%s'", tHandle)
return False return False
pHandle = trItemP.data(self.C_NAME, Qt.UserRole) pHandle = trItemP.data(self.C_NAME, Qt.UserRole)
nwItemS.setParent(pHandle) nwItemS.setParent(pHandle)
self.setTreeItemValues(tHandle) self.setTreeItemValues(tHandle)
logger.debug("The parent of item %s has been changed to %s" % (tHandle, pHandle)) logger.debug("The parent of item '%s' has been changed to '%s'", tHandle, pHandle)
return True return True
+40 -40
View File
@@ -134,8 +134,8 @@ class GuiTheme:
self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX() self.guiDPI = qApp.primaryScreen().logicalDotsPerInchX()
self.guiScale = qApp.primaryScreen().logicalDotsPerInchX()/96.0 self.guiScale = qApp.primaryScreen().logicalDotsPerInchX()/96.0
self.mainConf.guiScale = self.guiScale self.mainConf.guiScale = self.guiScale
logger.verbose("GUI DPI: %.1f" % self.guiDPI) logger.verbose("GUI DPI: %.1f", self.guiDPI)
logger.verbose("GUI Scale: %.2f" % self.guiScale) logger.verbose("GUI Scale: %.2f", self.guiScale)
# Fonts # Fonts
self.guiFont = qApp.font() self.guiFont = qApp.font()
@@ -152,12 +152,12 @@ class GuiTheme:
self.guiFontFixed.setPointSizeF(0.95*self.fontPointSize) self.guiFontFixed.setPointSizeF(0.95*self.fontPointSize)
self.guiFontFixed.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family()) self.guiFontFixed.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
logger.verbose("GUI Font Family: %s" % self.guiFont.family()) logger.verbose("GUI Font Family: %s", self.guiFont.family())
logger.verbose("GUI Font Point Size: %.2f" % self.fontPointSize) logger.verbose("GUI Font Point Size: %.2f", self.fontPointSize)
logger.verbose("GUI Font Pixel Size: %d" % self.fontPixelSize) logger.verbose("GUI Font Pixel Size: %d", self.fontPixelSize)
logger.verbose("GUI Base Icon Size: %d" % self.baseIconSize) logger.verbose("GUI Base Icon Size: %d", self.baseIconSize)
logger.verbose("Text 'N' Height: %d" % self.textNHeight) logger.verbose("Text 'N' Height: %d", self.textNHeight)
logger.verbose("Text 'N' Width: %d" % self.textNWidth) logger.verbose("Text 'N' Width: %d", self.textNWidth)
# Internal Mapping # Internal Mapping
self.makeAlert = self.theParent.makeAlert self.makeAlert = self.theParent.makeAlert
@@ -192,7 +192,7 @@ class GuiTheme:
for fontFam in os.listdir(fontAssets): for fontFam in os.listdir(fontAssets):
fontDir = os.path.join(fontAssets, fontFam) fontDir = os.path.join(fontAssets, fontFam)
if os.path.isdir(fontDir): if os.path.isdir(fontDir):
logger.verbose("Found font: %s" % fontFam) logger.verbose("Found font: %s", fontFam)
if fontFam not in self.guiFontDB.families(): if fontFam not in self.guiFontDB.families():
for fontFile in os.listdir(fontDir): for fontFile in os.listdir(fontDir):
ttfFile = os.path.join(fontDir, fontFile) ttfFile = os.path.join(fontDir, fontFile)
@@ -201,10 +201,10 @@ class GuiTheme:
for ttfFile in ttfList: for ttfFile in ttfList:
relPath = os.path.relpath(ttfFile, fontAssets) relPath = os.path.relpath(ttfFile, fontAssets)
logger.verbose("Adding font: %s" % relPath) logger.verbose("Adding font: %s", relPath)
fontID = self.guiFontDB.addApplicationFont(ttfFile) fontID = self.guiFontDB.addApplicationFont(ttfFile)
if fontID < 0: if fontID < 0:
logger.error("Failed to add font: %s" % relPath) logger.error("Failed to add font: %s", relPath)
return return
@@ -266,7 +266,7 @@ class GuiTheme:
"""Load the currently specified GUI theme. """Load the currently specified GUI theme.
""" """
logger.debug("Loading theme files") logger.debug("Loading theme files")
logger.debug("System icon theme is '%s'" % str(QIcon.themeName())) logger.debug("System icon theme is '%s'", str(QIcon.themeName()))
# CSS File # CSS File
cssData = "" cssData = ""
@@ -285,7 +285,7 @@ class GuiTheme:
with open(self.confFile, mode="r", encoding="utf8") as inFile: with open(self.confFile, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception: except Exception:
logger.error("Could not load theme settings from: %s" % self.confFile) logger.error("Could not load theme settings from: %s", self.confFile)
nw.logException() nw.logException()
return False return False
@@ -329,7 +329,7 @@ class GuiTheme:
qApp.setStyleSheet(cssData) qApp.setStyleSheet(cssData)
qApp.setPalette(self.guiPalette) qApp.setPalette(self.guiPalette)
logger.info("Loaded theme '%s'" % self.guiTheme) logger.info("Loaded theme '%s'", self.guiTheme)
return True return True
@@ -343,7 +343,7 @@ class GuiTheme:
with open(self.syntaxFile, mode="r", encoding="utf8") as inFile: with open(self.syntaxFile, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception: except Exception:
logger.error("Could not load syntax colours from: %s" % self.syntaxFile) logger.error("Could not load syntax colours from: %s", self.syntaxFile)
nw.logException() nw.logException()
return False return False
@@ -378,7 +378,7 @@ class GuiTheme:
self.colRepTag = self._loadColour(confParser, cnfSec, "replacetag") self.colRepTag = self._loadColour(confParser, cnfSec, "replacetag")
self.colMod = self._loadColour(confParser, cnfSec, "modifier") self.colMod = self._loadColour(confParser, cnfSec, "modifier")
logger.info("Loaded syntax theme '%s'" % self.guiSyntax) logger.info("Loaded syntax theme '%s'", self.guiSyntax)
return True return True
@@ -393,7 +393,7 @@ class GuiTheme:
themeConf = os.path.join( themeConf = os.path.join(
self.mainConf.themeRoot, self.guiPath, themeDir, self.confName self.mainConf.themeRoot, self.guiPath, themeDir, self.confName
) )
logger.verbose("Checking theme config for '%s'" % themeDir) logger.verbose("Checking theme config for '%s'", themeDir)
try: try:
with open(themeConf, mode="r", encoding="utf8") as inFile: with open(themeConf, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
@@ -406,7 +406,7 @@ class GuiTheme:
if confParser.has_section("Main"): if confParser.has_section("Main"):
if confParser.has_option("Main", "name"): if confParser.has_option("Main", "name"):
themeName = confParser.get("Main", "name") themeName = confParser.get("Main", "name")
logger.verbose("Theme name is '%s'" % themeName) logger.verbose("Theme name is '%s'", themeName)
if themeName != "": if themeName != "":
self.themeList.append((themeDir, themeName)) self.themeList.append((themeDir, themeName))
@@ -426,7 +426,7 @@ class GuiTheme:
syntaxPath = os.path.join(syntaxDir, syntaxFile) syntaxPath = os.path.join(syntaxDir, syntaxFile)
if not os.path.isfile(syntaxPath): if not os.path.isfile(syntaxPath):
continue continue
logger.verbose("Checking theme syntax for '%s'" % syntaxFile) logger.verbose("Checking theme syntax for '%s'", syntaxFile)
try: try:
with open(syntaxPath, mode="r", encoding="utf8") as inFile: with open(syntaxPath, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
@@ -441,7 +441,7 @@ class GuiTheme:
syntaxName = confParser.get("Main", "name") syntaxName = confParser.get("Main", "name")
if len(syntaxFile) > 5 and syntaxName != "": if len(syntaxFile) > 5 and syntaxName != "":
self.syntaxList.append((syntaxFile[:-5], syntaxName)) self.syntaxList.append((syntaxFile[:-5], syntaxName))
logger.verbose("Syntax name is '%s'" % syntaxName) logger.verbose("Syntax name is '%s'", syntaxName)
self.syntaxList = sorted(self.syntaxList, key=lambda x: x[1]) self.syntaxList = sorted(self.syntaxList, key=lambda x: x[1])
@@ -462,10 +462,10 @@ class GuiTheme:
outData.append(int(inData[1])) outData.append(int(inData[1]))
outData.append(int(inData[2])) outData.append(int(inData[2]))
except Exception: except Exception:
logger.error("Could not load theme colours for '%s' from config file" % cnfName) logger.error("Could not load theme colours for '%s' from config file", cnfName)
outData = [0, 0, 0] outData = [0, 0, 0]
else: else:
logger.warning("Could not find theme colours for '%s' in config file" % cnfName) logger.warning("Could not find theme colours for '%s' in config file", cnfName)
outData = [0, 0, 0] outData = [0, 0, 0]
return outData return outData
@@ -480,7 +480,7 @@ class GuiTheme:
readCol.append(int(inData[1])) readCol.append(int(inData[1]))
readCol.append(int(inData[2])) readCol.append(int(inData[2]))
except Exception: except Exception:
logger.error("Could not load theme colours for '%s' from config file" % cnfName) logger.error("Could not load theme colours for '%s' from config file", cnfName)
return return
if len(readCol) == 3: if len(readCol) == 3:
self.guiPalette.setColor(paletteVal, QColor(*readCol)) self.guiPalette.setColor(paletteVal, QColor(*readCol))
@@ -637,7 +637,7 @@ class GuiIcons:
self.themeMap = {} self.themeMap = {}
checkPath = os.path.join(self.mainConf.iconPath, self.mainConf.guiIcons) checkPath = os.path.join(self.mainConf.iconPath, self.mainConf.guiIcons)
if os.path.isdir(checkPath): if os.path.isdir(checkPath):
logger.debug("Loading icon theme '%s'" % self.mainConf.guiIcons) logger.debug("Loading icon theme '%s'", self.mainConf.guiIcons)
self.iconPath = checkPath self.iconPath = checkPath
self.confFile = os.path.join(checkPath, self.confName) self.confFile = os.path.join(checkPath, self.confName)
else: else:
@@ -649,7 +649,7 @@ class GuiIcons:
with open(self.confFile, mode="r", encoding="utf8") as inFile: with open(self.confFile, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
except Exception: except Exception:
logger.error("Could not load icon theme settings from: %s" % self.confFile) logger.error("Could not load icon theme settings from: %s", self.confFile)
nw.logException() nw.logException()
return False return False
@@ -669,16 +669,16 @@ class GuiIcons:
if confParser.has_section(cnfSec): if confParser.has_section(cnfSec):
for iconName, iconFile in confParser.items(cnfSec): for iconName, iconFile in confParser.items(cnfSec):
if iconName not in self.ICON_MAP: if iconName not in self.ICON_MAP:
logger.error("Unknown icon name '%s' in config file" % iconName) logger.error("Unknown icon name '%s' in config file", iconName)
else: else:
iconPath = os.path.join(self.iconPath, iconFile) iconPath = os.path.join(self.iconPath, iconFile)
if os.path.isfile(iconPath): if os.path.isfile(iconPath):
self.themeMap[iconName] = iconPath self.themeMap[iconName] = iconPath
logger.verbose("Icon slot '%s' using file '%s'" % (iconName, iconFile)) logger.verbose("Icon slot '%s' using file '%s'", iconName, iconFile)
else: else:
logger.error("Icon file '%s' not in theme folder" % iconFile) logger.error("Icon file '%s' not in theme folder", iconFile)
logger.info("Loaded icon theme '%s'" % self.mainConf.guiIcons) logger.info("Loaded icon theme '%s'", self.mainConf.guiIcons)
return True return True
@@ -691,14 +691,14 @@ class GuiIcons:
map. This function always returns a QSwgWidget. map. This function always returns a QSwgWidget.
""" """
if decoKey not in self.DECO_MAP: if decoKey not in self.DECO_MAP:
logger.error("Decoration with name '%s' does not exist" % decoKey) logger.error("Decoration with name '%s' does not exist", decoKey)
return QPixmap() return QPixmap()
imgPath = os.path.join( imgPath = os.path.join(
self.mainConf.assetPath, "images", self.DECO_MAP[decoKey] self.mainConf.assetPath, "images", self.DECO_MAP[decoKey]
) )
if not os.path.isfile(imgPath): if not os.path.isfile(imgPath):
logger.error("Decoration file '%s' not in assets folder" % self.DECO_MAP[decoKey]) logger.error("Decoration file '%s' not in assets folder", self.DECO_MAP[decoKey])
return QPixmap() return QPixmap()
theDeco = QPixmap(imgPath) theDeco = QPixmap(imgPath)
@@ -742,7 +742,7 @@ class GuiIcons:
if not os.path.isdir(themePath) or themeDir == self.fbackName: if not os.path.isdir(themePath) or themeDir == self.fbackName:
continue continue
themeConf = os.path.join(themePath, self.confName) themeConf = os.path.join(themePath, self.confName)
logger.verbose("Checking icon theme config for '%s'" % themeDir) logger.verbose("Checking icon theme config for '%s'", themeDir)
try: try:
with open(themeConf, mode="r", encoding="utf8") as inFile: with open(themeConf, mode="r", encoding="utf8") as inFile:
confParser.read_file(inFile) confParser.read_file(inFile)
@@ -755,7 +755,7 @@ class GuiIcons:
if confParser.has_section("Main"): if confParser.has_section("Main"):
if confParser.has_option("Main", "name"): if confParser.has_option("Main", "name"):
themeName = confParser.get("Main", "name") themeName = confParser.get("Main", "name")
logger.verbose("Theme name is '%s'" % themeName) logger.verbose("Theme name is '%s'", themeName)
if themeName != "": if themeName != "":
self.themeList.append((themeDir, themeName)) self.themeList.append((themeDir, themeName))
@@ -774,7 +774,7 @@ class GuiIcons:
a QIcon. a QIcon.
""" """
if iconKey not in self.ICON_MAP: if iconKey not in self.ICON_MAP:
logger.error("Requested unknown icon name '%s'" % iconKey) logger.error("Requested unknown icon name '%s'", iconKey)
return QIcon() return QIcon()
# If we just want the app icon, return it right away # If we just want the app icon, return it right away
@@ -785,17 +785,17 @@ class GuiIcons:
# First in the theme folder # First in the theme folder
if iconKey in self.themeMap: if iconKey in self.themeMap:
relPath = os.path.relpath(self.themeMap[iconKey], self.mainConf.iconPath) relPath = os.path.relpath(self.themeMap[iconKey], self.mainConf.iconPath)
logger.verbose("Loading: %s" % relPath) logger.verbose("Loading: %s", relPath)
return QIcon(self.themeMap[iconKey]) return QIcon(self.themeMap[iconKey])
# Next, we try to load the Qt style icons # Next, we try to load the Qt style icons
if self.ICON_MAP[iconKey][0] is not None: if self.ICON_MAP[iconKey][0] is not None:
logger.verbose("Loading icon '%s' from Qt QStyle.standardIcon" % iconKey) logger.verbose("Loading icon '%s' from Qt QStyle.standardIcon", iconKey)
return qApp.style().standardIcon(self.ICON_MAP[iconKey][0]) return qApp.style().standardIcon(self.ICON_MAP[iconKey][0])
# If we're still here, try to set from system theme # If we're still here, try to set from system theme
if self.ICON_MAP[iconKey][1] is not None: if self.ICON_MAP[iconKey][1] is not None:
logger.verbose("Loading icon '%s' from system theme" % iconKey) logger.verbose("Loading icon '%s' from system theme", iconKey)
if QIcon().hasThemeIcon(self.ICON_MAP[iconKey][1]): if QIcon().hasThemeIcon(self.ICON_MAP[iconKey][1]):
return QIcon().fromTheme(self.ICON_MAP[iconKey][1]) return QIcon().fromTheme(self.ICON_MAP[iconKey][1])
@@ -805,16 +805,16 @@ class GuiIcons:
self.mainConf.iconPath, self.fbackName, "%s-dark.svg" % iconKey self.mainConf.iconPath, self.fbackName, "%s-dark.svg" % iconKey
) )
if os.path.isfile(fbackIcon): if os.path.isfile(fbackIcon):
logger.verbose("Loading icon '%s' from fallback theme (dark mode)" % iconKey) logger.verbose("Loading icon '%s' from fallback theme (dark mode)", iconKey)
return QIcon(fbackIcon) return QIcon(fbackIcon)
fbackIcon = os.path.join(self.mainConf.iconPath, self.fbackName, "%s.svg" % iconKey) fbackIcon = os.path.join(self.mainConf.iconPath, self.fbackName, "%s.svg" % iconKey)
if os.path.isfile(fbackIcon): if os.path.isfile(fbackIcon):
logger.verbose("Loading icon '%s' from fallback theme (light mode)" % iconKey) logger.verbose("Loading icon '%s' from fallback theme (light mode)", iconKey)
return QIcon(fbackIcon) return QIcon(fbackIcon)
# Give up and return an empty icon # Give up and return an empty icon
logger.warning("Did not load an icon for '%s'" % iconKey) logger.warning("Did not load an icon for '%s'", iconKey)
return QIcon() return QIcon()
+22 -22
View File
@@ -68,19 +68,19 @@ class GuiMain(QMainWindow):
# System Info # System Info
# =========== # ===========
logger.info("OS: %s" % self.mainConf.osType) logger.info("OS: %s", self.mainConf.osType)
logger.info("Kernel: %s" % self.mainConf.kernelVer) logger.info("Kernel: %s", self.mainConf.kernelVer)
logger.info("Host: %s" % self.mainConf.hostName) logger.info("Host: %s", self.mainConf.hostName)
logger.info("Qt5 Version: %s (%d)" % ( logger.info(
self.mainConf.verQtString, self.mainConf.verQtValue) "Qt5 Version: %s (%d)", self.mainConf.verQtString, self.mainConf.verQtValue
) )
logger.info("PyQt5 Version: %s (%d)" % ( logger.info(
self.mainConf.verPyQtString, self.mainConf.verPyQtValue) "PyQt5 Version: %s (%d)", self.mainConf.verPyQtString, self.mainConf.verPyQtValue
) )
logger.info("Python Version: %s (0x%x)" % ( logger.info(
self.mainConf.verPyString, self.mainConf.verPyHexVal) "Python Version: %s (0x%x)", self.mainConf.verPyString, self.mainConf.verPyHexVal
) )
logger.info("GUI Language: %s" % self.mainConf.guiLang) logger.info("GUI Language: %s", self.mainConf.guiLang)
# Core Classes # Core Classes
# ============ # ============
@@ -680,7 +680,7 @@ class GuiMain(QMainWindow):
# Make sure main tab is in Editor view # Make sure main tab is in Editor view
self.mainTabs.setCurrentWidget(self.splitDocs) self.mainTabs.setCurrentWidget(self.splitDocs)
logger.debug("Viewing document with handle %s" % tHandle) logger.debug("Viewing document with handle '%s'", tHandle)
if self.docViewer.loadText(tHandle): if self.docViewer.loadText(tHandle):
if not self.splitView.isVisible(): if not self.splitView.isVisible():
bPos = self.splitMain.sizes() bPos = self.splitMain.sizes()
@@ -805,13 +805,13 @@ class GuiMain(QMainWindow):
logger.warning("No item selected") logger.warning("No item selected")
return False return False
logger.verbose("Opening item %s" % tHandle) logger.verbose("Opening item '%s'", tHandle)
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
if nwItem.itemType == nwItemType.FILE: if nwItem.itemType == nwItemType.FILE:
logger.verbose("Requested item %s is a file" % tHandle) logger.verbose("Requested item '%s' is a file", tHandle)
self.openDocument(tHandle, doScroll=False) self.openDocument(tHandle, doScroll=False)
else: else:
logger.verbose("Requested item %s is not a file" % tHandle) logger.verbose("Requested item '%s' is not a file", tHandle)
return True return True
@@ -838,7 +838,7 @@ class GuiMain(QMainWindow):
if tItem.itemType not in nwLists.REG_TYPES: if tItem.itemType not in nwLists.REG_TYPES:
return return
logger.verbose("Requesting change to item %s" % tHandle) logger.verbose("Requesting change to item '%s'", tHandle)
dlgProj = GuiItemEditor(self, tHandle) dlgProj = GuiItemEditor(self, tHandle)
dlgProj.exec_() dlgProj.exec_()
if dlgProj.result() == QDialog.Accepted: if dlgProj.result() == QDialog.Accepted:
@@ -888,7 +888,7 @@ class GuiMain(QMainWindow):
self.setStatus(self.tr("Indexing: '{0}'").format(self.tr("Unknown item"))) self.setStatus(self.tr("Indexing: '{0}'").format(self.tr("Unknown item")))
if tItem is not None and tItem.itemType == nwItemType.FILE: if tItem is not None and tItem.itemType == nwItemType.FILE:
logger.verbose("Scanning: %s" % tItem.itemName) logger.verbose("Scanning '%s'", tItem.itemName)
self.theIndex.reIndexHandle(tItem.itemHandle) self.theIndex.reIndexHandle(tItem.itemHandle)
# Get Word Counts # Get Word Counts
@@ -1513,15 +1513,15 @@ class GuiMain(QMainWindow):
we open it. Otherwise, we do nothing. we open it. Otherwise, we do nothing.
""" """
tHandle = tItem.data(self.treeView.C_NAME, Qt.UserRole) tHandle = tItem.data(self.treeView.C_NAME, Qt.UserRole)
logger.verbose("User double clicked tree item with handle %s" % tHandle) logger.verbose("User double clicked tree item with handle '%s'", tHandle)
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
if nwItem is not None: if nwItem is not None:
if nwItem.itemType == nwItemType.FILE: if nwItem.itemType == nwItemType.FILE:
logger.verbose("Requested item %s is a file" % tHandle) logger.verbose("Requested item '%s' is a file", tHandle)
self.openDocument(tHandle, changeFocus=False, doScroll=False) self.openDocument(tHandle, changeFocus=False, doScroll=False)
else: else:
logger.verbose("Requested item %s is a folder" % tHandle) logger.verbose("Requested item '%s' is a folder", tHandle)
return return
@@ -1545,15 +1545,15 @@ class GuiMain(QMainWindow):
not change focus to the editor as double click does. not change focus to the editor as double click does.
""" """
tHandle = self.treeView.getSelectedHandle() tHandle = self.treeView.getSelectedHandle()
logger.verbose("User pressed return on tree item with handle %s" % tHandle) logger.verbose("User pressed return on tree item with handle '%s'", tHandle)
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
if nwItem is not None: if nwItem is not None:
if nwItem.itemType == nwItemType.FILE: if nwItem.itemType == nwItemType.FILE:
logger.verbose("Requested item %s is a file" % tHandle) logger.verbose("Requested item '%s' is a file", tHandle)
self.openDocument(tHandle, changeFocus=False, doScroll=False) self.openDocument(tHandle, changeFocus=False, doScroll=False)
else: else:
logger.verbose("Requested item %s is a folder" % tHandle) logger.verbose("Requested item '%s' is a folder", tHandle)
return return