Clean up variables and formatting

This commit is contained in:
Veronica Berglyd Olsen
2024-01-28 00:28:01 +01:00
parent 97b791511f
commit 8e4e6903b1
41 changed files with 1241 additions and 1248 deletions
+3 -3
View File
@@ -256,9 +256,9 @@ class GuiDocHighlighter(QSyntaxHighlighter):
nBlocks = qDoc.blockCount()
tStart = time()
for i in range(nBlocks):
theBlock = qDoc.findBlockByNumber(i)
if theBlock.userState() & cType > 0:
self.rehighlightBlock(theBlock)
block = qDoc.findBlockByNumber(i)
if block.userState() & cType > 0:
self.rehighlightBlock(block)
logger.debug("Document highlighted in %.3f ms" % (1000*(time() - tStart)))
return
+4 -4
View File
@@ -229,7 +229,7 @@ class GuiDocViewer(QTextBrowser):
self.setDocumentTitle(tHandle)
# Replace tabs before setting the HTML, and then put them back in
self.setHtml(aDoc.theResult.replace("\t", "!!tab!!"))
self.setHtml(aDoc.result.replace("\t", "!!tab!!"))
while self.find("!!tab!!"):
self.textCursor().insertText("\t")
@@ -367,9 +367,9 @@ class GuiDocViewer(QTextBrowser):
link = url.url()
logger.debug("Clicked link: '%s'", link)
if len(link) > 0:
theBits = link.split("=")
if len(theBits) == 2:
self.loadDocumentTagRequest.emit(theBits[1], nwDocMode.VIEW)
bits = link.split("=")
if len(bits) == 2:
self.loadDocumentTagRequest.emit(bits[1], nwDocMode.VIEW)
return
@pyqtSlot("QPoint")
+7 -7
View File
@@ -239,9 +239,9 @@ class GuiItemDetails(QWidget):
# Label
# =====
theLabel = nwItem.itemName
if len(theLabel) > 100:
theLabel = theLabel[:96].rstrip()+" ..."
label = nwItem.itemName
if len(label) > 100:
label = label[:96].rstrip()+" ..."
if nwItem.isFileType():
if nwItem.isActive:
@@ -251,14 +251,14 @@ class GuiItemDetails(QWidget):
else:
self.labelIcon.setPixmap(SHARED.theme.getPixmap("noncheckable", (iPx, iPx)))
self.labelData.setText(theLabel)
self.labelData.setText(label)
# Status
# ======
theStatus, theIcon = nwItem.getImportStatus(incIcon=True)
self.statusIcon.setPixmap(theIcon.pixmap(iPx, iPx))
self.statusData.setText(theStatus)
status, icon = nwItem.getImportStatus(incIcon=True)
self.statusIcon.setPixmap(icon.pixmap(iPx, iPx))
self.statusData.setText(status)
# Class
# =====
+4 -4
View File
@@ -726,17 +726,17 @@ class GuiNovelTree(QTreeWidget):
refData = []
refName = ""
theRefs = SHARED.project.index.getReferences(tHandle, sTitle)
refs = SHARED.project.index.getReferences(tHandle, sTitle)
if self._lastCol == NovelTreeColumn.POV:
refData = theRefs[nwKeyWords.POV_KEY]
refData = refs[nwKeyWords.POV_KEY]
refName = self._povLabel
elif self._lastCol == NovelTreeColumn.FOCUS:
refData = theRefs[nwKeyWords.FOCUS_KEY]
refData = refs[nwKeyWords.FOCUS_KEY]
refName = self._focLabel
elif self._lastCol == NovelTreeColumn.PLOT:
refData = theRefs[nwKeyWords.PLOT_KEY]
refData = refs[nwKeyWords.PLOT_KEY]
refName = self._pltLabel
if refData:
+13 -13
View File
@@ -625,12 +625,12 @@ class GuiOutlineTree(QTreeWidget):
self.clear()
if self._firstView:
theLabels = []
labels = []
for i, hItem in enumerate(self._treeOrder):
theLabels.append(trConst(nwLabels.OUTLINE_COLS[hItem]))
labels.append(trConst(nwLabels.OUTLINE_COLS[hItem]))
self._colIdx[hItem] = i
self.setHeaderLabels(theLabels)
self.setHeaderLabels(labels)
for hItem in self._treeOrder:
self.setColumnWidth(self._colIdx[hItem], self._colWidth[hItem])
self.setColumnHidden(self._colIdx[hItem], self._colHidden[hItem])
@@ -990,7 +990,7 @@ class GuiOutlineDetails(QScrollArea):
pIndex = SHARED.project.index
nwItem = SHARED.project.tree[tHandle]
novIdx = pIndex.getItemHeader(tHandle, sTitle)
theRefs = pIndex.getReferences(tHandle, sTitle)
novRefs = pIndex.getReferences(tHandle, sTitle)
if nwItem is None or novIdx is None:
return False
@@ -1015,15 +1015,15 @@ class GuiOutlineDetails(QScrollArea):
self.synopValue.setText(novIdx.synopsis)
self.povKeyValue.setText(self._formatTags(theRefs, nwKeyWords.POV_KEY))
self.focKeyValue.setText(self._formatTags(theRefs, nwKeyWords.FOCUS_KEY))
self.chrKeyValue.setText(self._formatTags(theRefs, nwKeyWords.CHAR_KEY))
self.pltKeyValue.setText(self._formatTags(theRefs, nwKeyWords.PLOT_KEY))
self.timKeyValue.setText(self._formatTags(theRefs, nwKeyWords.TIME_KEY))
self.wldKeyValue.setText(self._formatTags(theRefs, nwKeyWords.WORLD_KEY))
self.objKeyValue.setText(self._formatTags(theRefs, nwKeyWords.OBJECT_KEY))
self.entKeyValue.setText(self._formatTags(theRefs, nwKeyWords.ENTITY_KEY))
self.cstKeyValue.setText(self._formatTags(theRefs, nwKeyWords.CUSTOM_KEY))
self.povKeyValue.setText(self._formatTags(novRefs, nwKeyWords.POV_KEY))
self.focKeyValue.setText(self._formatTags(novRefs, nwKeyWords.FOCUS_KEY))
self.chrKeyValue.setText(self._formatTags(novRefs, nwKeyWords.CHAR_KEY))
self.pltKeyValue.setText(self._formatTags(novRefs, nwKeyWords.PLOT_KEY))
self.timKeyValue.setText(self._formatTags(novRefs, nwKeyWords.TIME_KEY))
self.wldKeyValue.setText(self._formatTags(novRefs, nwKeyWords.WORLD_KEY))
self.objKeyValue.setText(self._formatTags(novRefs, nwKeyWords.OBJECT_KEY))
self.entKeyValue.setText(self._formatTags(novRefs, nwKeyWords.ENTITY_KEY))
self.cstKeyValue.setText(self._formatTags(novRefs, nwKeyWords.CUSTOM_KEY))
return True
+12 -12
View File
@@ -785,24 +785,24 @@ class GuiProjectTree(QTreeWidget):
project structure, and must be called before any code that
depends on this order to be up to date.
"""
theList = []
items = []
for i in range(self.topLevelItemCount()):
item = self.topLevelItem(i)
if isinstance(item, QTreeWidgetItem):
theList = self._scanChildren(theList, item, i)
items = self._scanChildren(items, item, i)
logger.debug("Saving project tree item order")
SHARED.project.setTreeOrder(theList)
SHARED.project.setTreeOrder(items)
return
def getTreeFromHandle(self, tHandle: str) -> list[str]:
"""Recursively return all the child items starting from a given
item handle.
"""
theList = []
theItem = self._getTreeItem(tHandle)
if theItem is not None:
theList = self._scanChildren(theList, theItem, 0)
return theList
result = []
tIten = self._getTreeItem(tHandle)
if tIten is not None:
result = self._scanChildren(result, tIten, 0)
return result
def requestDeleteItem(self, tHandle: str | None = None) -> bool:
"""Request an item deleted from the project tree. This function
@@ -857,11 +857,11 @@ class GuiProjectTree(QTreeWidget):
SHARED.info(self.tr("There is currently no Trash folder in this project."))
return False
theTrash = self.getTreeFromHandle(trashHandle)
if trashHandle in theTrash:
theTrash.remove(trashHandle)
trashItems = self.getTreeFromHandle(trashHandle)
if trashHandle in trashItems:
trashItems.remove(trashHandle)
nTrash = len(theTrash)
nTrash = len(trashItems)
if nTrash == 0:
SHARED.info(self.tr("The Trash folder is already empty."))
return False
+9 -9
View File
@@ -368,22 +368,22 @@ class GuiTheme:
def _setGuiFont(self) -> None:
"""Update the GUI's font style from settings."""
theFont = QFont()
font = QFont()
fontDB = QFontDatabase()
if CONFIG.guiFont not in fontDB.families():
if CONFIG.osWindows and "Arial" in fontDB.families():
# On Windows we default to Arial if possible
theFont.setFamily("Arial")
theFont.setPointSize(10)
font.setFamily("Arial")
font.setPointSize(10)
else:
theFont = fontDB.systemFont(QFontDatabase.GeneralFont)
CONFIG.guiFont = theFont.family()
CONFIG.guiFontSize = theFont.pointSize()
font = fontDB.systemFont(QFontDatabase.GeneralFont)
CONFIG.guiFont = font.family()
CONFIG.guiFontSize = font.pointSize()
else:
theFont.setFamily(CONFIG.guiFont)
theFont.setPointSize(CONFIG.guiFontSize)
font.setFamily(CONFIG.guiFont)
font.setPointSize(CONFIG.guiFontSize)
qApp.setFont(theFont)
qApp.setFont(font)
return