* Update instructions and readmes
* Cleanup in base files
* Cleanup in core files
* Cleanup in gui files
* Cleanup in dialog files
* Cleanup in tools files
* Cleanup in test files
This commit is contained in:
Veronica Berglyd Olsen
2021-07-04 17:57:54 +02:00
committed by GitHub
parent 1881b3d32c
commit 6d7ca2bb86
51 changed files with 583 additions and 580 deletions
+15 -12
View File
@@ -311,13 +311,13 @@ class QSwitch(QAbstractButton):
if self.isChecked():
trackBrush = qPalette.highlight()
thumbBrush = qPalette.highlightedText()
textColor = qPalette.highlight().color()
thumbText = nwUnicode.U_CHECK
textColor = qPalette.highlight().color()
thumbText = nwUnicode.U_CHECK
else:
trackBrush = qPalette.dark()
thumbBrush = qPalette.light()
textColor = qPalette.dark().color()
thumbText = nwUnicode.U_CROSS
textColor = qPalette.dark().color()
thumbText = nwUnicode.U_CROSS
if self.isEnabled():
trackOpacity = 1.0
@@ -325,7 +325,7 @@ class QSwitch(QAbstractButton):
trackOpacity = 0.6
trackBrush = qPalette.shadow()
thumbBrush = qPalette.mid()
textColor = qPalette.shadow().color()
textColor = qPalette.shadow().color()
qPaint.setBrush(trackBrush)
qPaint.setOpacity(trackOpacity)
@@ -379,18 +379,18 @@ class PagedDialog(QDialog):
def __init__(self, theParent=None):
QDialog.__init__(self, parent=theParent)
self._outerBox = QVBoxLayout()
self._buttonBox = QHBoxLayout()
self._tabBox = QTabWidget()
self._tabBar = VerticalTabBar(self)
self._tabBox.setTabBar(self._tabBar)
self._tabBox.setTabPosition(QTabWidget.West)
self._tabBar.setExpanding(False)
self._tabBox = QTabWidget()
self._tabBox.setTabBar(self._tabBar)
self._tabBox.setTabPosition(QTabWidget.West)
self._buttonBox = QHBoxLayout()
self._outerBox = QVBoxLayout()
self._outerBox.addWidget(self._tabBox)
self._outerBox.addLayout(self._buttonBox)
self.setLayout(self._outerBox)
# Default Margins
qM = self._outerBox.contentsMargins()
@@ -399,11 +399,14 @@ class PagedDialog(QDialog):
mT = qM.top()
mB = qM.bottom()
# Set Margins
self.setContentsMargins(0, 0, 0, 0)
self._outerBox.setContentsMargins(0, 0, 0, mB)
self._buttonBox.setContentsMargins(mL, 0, mR, 0)
self._outerBox.setSpacing(mT)
self.setLayout(self._outerBox)
return
def addTab(self, tabWidget, tabLabel):
+35 -33
View File
@@ -1090,7 +1090,7 @@ class GuiDocEditor(QTextEdit):
# Spell Checking
# ==============
posCursor = self.cursorForPosition(thePos)
posCursor = self.cursorForPosition(thePos)
spellCheck = self._spellCheck
if posCursor.block().text().startswith("@"):
@@ -1272,7 +1272,7 @@ class GuiDocEditor(QTextEdit):
findOpt |= QTextDocument.FindWholeWords
searchFor = self.docSearch.getSearchObject()
wasFound = self.find(searchFor, findOpt)
wasFound = self.find(searchFor, findOpt)
if not wasFound:
if self.docSearch.doNextFile and not goBack:
self.theParent.openNextDocument(
@@ -1330,7 +1330,7 @@ class GuiDocEditor(QTextEdit):
return
searchFor = self.docSearch.getSearchText()
replWith = self.docSearch.getReplaceText()
replWith = self.docSearch.getReplaceText()
if self.docSearch.doMatchCap:
replWith = transferCase(theCursor.selectedText(), replWith)
@@ -1376,7 +1376,7 @@ class GuiDocEditor(QTextEdit):
theCursor = self.textCursor()
theBlock = theCursor.block()
theText = theBlock.text()
theText = theBlock.text()
if len(theText) == 0:
return False
@@ -1413,16 +1413,16 @@ class GuiDocEditor(QTextEdit):
if not theBlock.isValid():
return
theText = theBlock.text()
theText = theBlock.text()
theCursor = self.textCursor()
thePos = theCursor.positionInBlock()
theLen = len(theText)
thePos = theCursor.positionInBlock()
theLen = len(theText)
if theLen < 1 or thePos-1 > theLen:
return
theOne = theText[thePos-1:thePos]
theTwo = theText[thePos-2:thePos]
theOne = theText[thePos-1:thePos]
theTwo = theText[thePos-2:thePos]
theThree = theText[thePos-3:thePos]
if not theOne: # Makes Neo sad
@@ -2028,7 +2028,7 @@ class GuiDocEditSearch(QFrame):
self.searchOpt.setToolButtonStyle(Qt.ToolButtonIconOnly)
self.searchOpt.setIconSize(QSize(tPx, tPx))
self.searchOpt.setContentsMargins(0, 0, 0, 0)
self.searchOpt.setStyleSheet(r"QToolBar {padding: 0;}")
self.searchOpt.setStyleSheet("QToolBar {padding: 0;}")
self.searchLabel = QLabel(self.tr("Search"))
self.searchLabel.setFont(boxFont)
@@ -2100,7 +2100,7 @@ class GuiDocEditSearch(QFrame):
self.showReplace.setArrowType(Qt.RightArrow)
self.showReplace.setCheckable(True)
self.showReplace.setToolTip(self.tr("Show/hide the replace text box"))
self.showReplace.setStyleSheet(r"QToolButton {border: none; background: transparent;}")
self.showReplace.setStyleSheet("QToolButton {border: none; background: transparent;}")
self.showReplace.toggled.connect(self._doToggleReplace)
self.searchButton = QPushButton(self.theTheme.getIcon("search"), "")
@@ -2139,9 +2139,9 @@ class GuiDocEditSearch(QFrame):
# Construct Box Colours
qPalette = self.searchBox.palette()
baseCol = qPalette.base().color()
rCol = baseCol.redF() + 0.1
rCol = baseCol.redF() + 0.1
gCol = baseCol.greenF() - 0.1
bCol = baseCol.blueF() - 0.1
bCol = baseCol.blueF() - 0.1
mCol = max(rCol, gCol, bCol, 1.0)
errCol = QColor()
@@ -2161,10 +2161,10 @@ class GuiDocEditSearch(QFrame):
def closeSearch(self):
"""Close the search box.
"""
self.mainConf.searchCase = self.isCaseSense
self.mainConf.searchWord = self.isWholeWord
self.mainConf.searchRegEx = self.isRegEx
self.mainConf.searchLoop = self.doLoop
self.mainConf.searchCase = self.isCaseSense
self.mainConf.searchWord = self.isWholeWord
self.mainConf.searchRegEx = self.isRegEx
self.mainConf.searchLoop = self.doLoop
self.mainConf.searchNextFile = self.doNextFile
self.mainConf.searchMatchCap = self.doMatchCap
@@ -2367,7 +2367,8 @@ class GuiDocEditHeader(QWidget):
self.theParent = docEditor.theParent
self.theProject = docEditor.theProject
self.theTheme = docEditor.theTheme
self._docHandle = None
self._docHandle = None
fPx = int(0.9*self.theTheme.fontPixelSize)
hSp = self.mainConf.pxInt(6)
@@ -2591,8 +2592,9 @@ class GuiDocEditFooter(QWidget):
self.theProject = docEditor.theProject
self.theTheme = docEditor.theTheme
self.optState = docEditor.theProject.optState
self._docHandle = None
self.theItem = None
self._theItem = None
self._docHandle = None
self.sPx = int(round(0.9*self.theTheme.baseIconSize))
fPx = int(0.9*self.theTheme.fontPixelSize)
@@ -2708,9 +2710,9 @@ class GuiDocEditFooter(QWidget):
self._docHandle = tHandle
if self._docHandle is None:
logger.verbose("No handle set, so clearing the editor footer")
self.theItem = None
self._theItem = None
else:
self.theItem = self.theProject.projTree[self._docHandle]
self._theItem = self.theProject.projTree[self._docHandle]
self.updateInfo()
self.updateCounts()
@@ -2720,12 +2722,12 @@ class GuiDocEditFooter(QWidget):
def updateInfo(self):
"""Update the content of text labels.
"""
if self.theItem is None:
if self._theItem is None:
sIcon = QPixmap()
sText = ""
else:
iStatus = self.theItem.itemStatus
if self.theItem.itemClass == nwItemClass.NOVEL:
iStatus = self._theItem.itemStatus
if self._theItem.itemClass == nwItemClass.NOVEL:
iStatus = self.theProject.statusItems.checkEntry(iStatus)
theIcon = self.theParent.statusIcons[iStatus]
else:
@@ -2733,9 +2735,9 @@ class GuiDocEditFooter(QWidget):
theIcon = self.theParent.importIcons[iStatus]
sIcon = theIcon.pixmap(self.sPx, self.sPx)
sClass = trConst(nwLabels.CLASS_NAME[self.theItem.itemClass])
sLayout = trConst(nwLabels.LAYOUT_NAME[self.theItem.itemLayout])
sText = f"{self.theItem.itemStatus} / {sClass} / {sLayout}"
sClass = trConst(nwLabels.CLASS_NAME[self._theItem.itemClass])
sLayout = trConst(nwLabels.LAYOUT_NAME[self._theItem.itemLayout])
sText = f"{self._theItem.itemStatus} / {sClass} / {sLayout}"
self.statusIcon.setPixmap(sIcon)
self.statusText.setText(sText)
@@ -2745,7 +2747,7 @@ class GuiDocEditFooter(QWidget):
def updateLineCount(self):
"""Update the word count.
"""
if self.theItem is None:
if self._theItem is None:
iLine = 0
iDist = 0
else:
@@ -2762,12 +2764,12 @@ class GuiDocEditFooter(QWidget):
def updateCounts(self):
"""Update the word count.
"""
if self.theItem is None:
if self._theItem is None:
wCount = 0
wDiff = 0
wDiff = 0
else:
wCount = self.theItem.wordCount
wDiff = wCount - self.theItem.initCount
wCount = self._theItem.wordCount
wDiff = wCount - self._theItem.initCount
self.wordsText.setText(
self.tr("Words: {0} ({1})").format(f"{wCount:n}", f"{wDiff:+n}")
+2 -6
View File
@@ -60,7 +60,7 @@ class GuiDocViewer(QTextBrowser):
self.theProject = theParent.theProject
# Internal Variables
self._docHandle = None
self._docHandle = None
self._qDocument = self.document()
# Settings
@@ -312,9 +312,7 @@ class GuiDocViewer(QTextBrowser):
return
def updateDocMargins(self):
"""Automatically adjust the margins so the text is centred if
Config.textFixedW is enabled or we're in Focus Mode. Otherwise,
just ensure the margins are set correctly.
"""Automatically adjust the margins so the text is centred.
"""
vBar = self.verticalScrollBar()
sW = vBar.width() if vBar.isVisible() else 0
@@ -1152,7 +1150,6 @@ class GuiDocViewDetails(QScrollArea):
self.theParent = theParent
self.theProject = theParent.theProject
self.theTheme = theParent.theTheme
self.currHandle = None
self.refList = QLabel("")
self.refList.setWordWrap(True)
@@ -1185,7 +1182,6 @@ class GuiDocViewDetails(QScrollArea):
"""Update the current list of document references from the
project index.
"""
self.currHandle = tHandle
if self.theParent.docViewer.stickyRef:
return
+16 -18
View File
@@ -47,7 +47,7 @@ class GuiMainMenu(QMenuBar):
self.theProject = theParent.theProject
# Internals
self.assistProc = None
self._assistProc = None
# Build Menu
self._buildProjectMenu()
@@ -92,19 +92,19 @@ class GuiMainMenu(QMenuBar):
def closeHelp(self):
"""Close the process used for the Qt Assistant, if it is open.
"""
if self.assistProc is None:
if self._assistProc is None:
return
if self.assistProc.state() == QProcess.Starting:
if self.assistProc.waitForStarted(10000):
self.assistProc.terminate()
if self._assistProc.state() == QProcess.Starting:
if self._assistProc.waitForStarted(10000):
self._assistProc.terminate()
else:
self.assistProc.kill()
self._assistProc.kill()
elif self.assistProc.state() == QProcess.Running:
self.assistProc.terminate()
if not self.assistProc.waitForFinished(10000):
self.assistProc.kill()
elif self._assistProc.state() == QProcess.Running:
self._assistProc.terminate()
if not self._assistProc.waitForFinished(10000):
self._assistProc.kill()
return
@@ -134,7 +134,7 @@ class GuiMainMenu(QMenuBar):
# Slots
##
def _toggleSpellCheck(self, isChecked=False):
def _toggleSpellCheck(self):
"""Toggle spell checking. The active status of the spell check
flag is handled by the document editor class, so we make no
decision, just pass a None to the function and let it decide.
@@ -155,10 +155,10 @@ class GuiMainMenu(QMenuBar):
self._openWebsite(nw.__docurl__)
return False
self.assistProc = QProcess(self)
self.assistProc.start("assistant", ["-collectionFile", self.mainConf.helpPath])
self._assistProc = QProcess(self)
self._assistProc.start("assistant", ["-collectionFile", self.mainConf.helpPath])
if not self.assistProc.waitForStarted(10000):
if not self._assistProc.waitForStarted(10000):
self._openWebsite(nw.__docurl__)
return False
@@ -239,11 +239,9 @@ class GuiMainMenu(QMenuBar):
self.rootItems[nwItemClass.ENTITY] = QAction(self.tr("Entity Root"), self.rootMenu)
self.rootItems[nwItemClass.CUSTOM] = QAction(self.tr("Custom Root"), self.rootMenu)
self.rootItems[nwItemClass.ARCHIVE] = QAction(self.tr("Outtakes Root"), self.rootMenu)
nCount = 0
for itemClass in self.rootItems.keys():
nCount += 1 # This forces the lambdas to be unique
for n, itemClass in enumerate(self.rootItems.keys()):
self.rootItems[itemClass].triggered.connect(
lambda nCount, itemClass=itemClass: self._newTreeItem(nwItemType.ROOT, itemClass)
lambda n, itemClass=itemClass: self._newTreeItem(nwItemType.ROOT, itemClass)
)
self.rootMenu.addAction(self.rootItems[itemClass])
+5 -5
View File
@@ -247,9 +247,9 @@ class GuiNovelTree(QTreeWidget):
"""
self.clearTree()
currTitle = None
currTitle = None
currChapter = None
currScene = None
currScene = None
for tKey, tHandle, sTitle, novIdx in self.theIndex.novelStructure(skipExcluded=True):
@@ -259,9 +259,9 @@ class GuiNovelTree(QTreeWidget):
tLevel = novIdx["level"]
if tLevel == "H1":
self.addTopLevelItem(tItem)
currTitle = tItem
currTitle = tItem
currChapter = None
currScene = None
currScene = None
elif tLevel == "H2":
if currTitle is None:
@@ -269,7 +269,7 @@ class GuiNovelTree(QTreeWidget):
else:
currTitle.addChild(tItem)
currChapter = tItem
currScene = None
currScene = None
elif tLevel == "H3":
if currChapter is None:
+88 -86
View File
@@ -28,7 +28,7 @@ import logging
from time import time
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtCore import Qt, QSize, pyqtSlot
from PyQt5.QtWidgets import (
QTreeWidget, QTreeWidgetItem, QMenu, QAction, QAbstractItemView
)
@@ -94,9 +94,6 @@ class GuiOutline(QTreeWidget):
self.optState = theParent.theProject.optState
self.headerMenu = GuiOutlineHeaderMenu(self)
self.firstView = True
self.lastBuild = 0
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSelectionMode(QAbstractItemView.SingleSelection)
self.setExpandsOnDoubleClick(False)
@@ -113,16 +110,18 @@ class GuiOutline(QTreeWidget):
self.treeHead.customContextMenuRequested.connect(self._headerRightClick)
self.treeHead.sectionMoved.connect(self._columnMoved)
self.treeMap = {}
self.treeOrder = []
self.colWidth = {}
self.colHidden = {}
self.colIndex = {}
self.treeNCols = 0
# Internals
self._treeOrder = []
self._colWidth = {}
self._colHidden = {}
self._colIdx = {}
self._treeNCols = 0
self._firstView = True
self._lastBuild = 0
self.initOutline()
self.clearOutline()
self.headerMenu.setHiddenState(self.colHidden)
self.headerMenu.setHiddenState(self._colHidden)
logger.debug("GuiOutline initialisation complete")
@@ -152,18 +151,18 @@ class GuiOutline(QTreeWidget):
self.setColumnCount(1)
self.setHeaderLabel(trConst(nwLabels.OUTLINE_COLS[nwOutline.TITLE]))
self.treeOrder = []
self.colWidth = {}
self.colHidden = {}
self.colIndex = {}
self.treeNCols = 0
self._treeOrder = []
self._colWidth = {}
self._colHidden = {}
self._colIdx = {}
self._treeNCols = 0
for i, hItem in enumerate(nwOutline):
self.treeOrder.append(hItem)
self.colWidth[hItem] = self.DEF_WIDTH[hItem]
self.colHidden[hItem] = self.DEF_HIDDEN[hItem]
for hItem in nwOutline:
self._treeOrder.append(hItem)
self._colWidth[hItem] = self.DEF_WIDTH[hItem]
self._colHidden[hItem] = self.DEF_HIDDEN[hItem]
self.treeNCols = len(self.treeOrder)
self._treeNCols = len(self._treeOrder)
return
@@ -173,15 +172,15 @@ class GuiOutline(QTreeWidget):
tree.
"""
# If it's the first time, we always build
if self.firstView or self.firstView and overRide:
if self._firstView or self._firstView and overRide:
self._loadHeaderState()
self._populateTree()
self.firstView = False
self._firstView = False
return
# If the novel index or novel tree has changed since the tree
# was last built, we rebuild the tree from the updated index.
indexChanged = self.theIndex.novelChangedSince(self.lastBuild)
indexChanged = self.theIndex.novelChangedSince(self._lastBuild)
doBuild = (novelChanged or indexChanged) and self.theProject.autoOutline
if doBuild or overRide:
logger.debug("Rebuilding Project Outline")
@@ -194,21 +193,22 @@ class GuiOutline(QTreeWidget):
"""
self._saveHeaderState()
self.clearOutline()
self.firstView = True
self._firstView = True
return
##
# Slots
##
@pyqtSlot("QTreeWidgetItem*", int)
def _treeDoubleClick(self, tItem, tCol):
"""Extract the handle and line number of the title double-
clicked, and send it to the main gui class for opening in the
document editor.
"""
tHandle = tItem.data(self.colIndex[nwOutline.TITLE], Qt.UserRole)
tHandle = tItem.data(self._colIdx[nwOutline.TITLE], Qt.UserRole)
try:
tLine = int(tItem.text(self.colIndex[nwOutline.LINE]))
tLine = int(tItem.text(self._colIdx[nwOutline.LINE]))
except Exception:
tLine = 1
@@ -217,30 +217,33 @@ class GuiOutline(QTreeWidget):
return
@pyqtSlot()
def _itemSelected(self):
"""Extract the handle and line number of the currently selected
title, and send it to the details panel.
"""
selItems = self.selectedItems()
if selItems:
tHandle = selItems[0].data(self.colIndex[nwOutline.TITLE], Qt.UserRole)
sTitle = selItems[0].data(self.colIndex[nwOutline.LINE], Qt.UserRole)
tHandle = selItems[0].data(self._colIdx[nwOutline.TITLE], Qt.UserRole)
sTitle = selItems[0].data(self._colIdx[nwOutline.LINE], Qt.UserRole)
self.theParent.projMeta.showItem(tHandle, sTitle)
self.theParent.treeView.setSelectedHandle(tHandle)
return
@pyqtSlot("QPoint")
def _headerRightClick(self, clickPos):
"""Show the header column menu.
"""
self.headerMenu.exec_(self.mapToGlobal(clickPos))
return
@pyqtSlot(int, int, int)
def _columnMoved(self, logIdx, oldVisualIdx, newVisualIdx):
"""Make sure the order array is up to date with the actual order
of the columns.
"""
self.treeOrder.insert(newVisualIdx, self.treeOrder.pop(oldVisualIdx))
self._treeOrder.insert(newVisualIdx, self._treeOrder.pop(oldVisualIdx))
self._saveHeaderState()
return
@@ -249,8 +252,8 @@ class GuiOutline(QTreeWidget):
header context menu.
"""
logger.verbose("User toggled Outline column '%s'", theItem.name)
if theItem in self.colIndex:
self.setColumnHidden(self.colIndex[theItem], not isChecked)
if theItem in self._colIdx:
self.setColumnHidden(self._colIdx[theItem], not isChecked)
self._saveHeaderState()
return
@@ -281,29 +284,29 @@ class GuiOutline(QTreeWidget):
# Check that we now have a complete list, and only if so, save
# the order loaded from file. Otherwise, we keep the default.
if len(treeOrder) == self.treeNCols:
self.treeOrder = treeOrder
if len(treeOrder) == self._treeNCols:
self._treeOrder = treeOrder
else:
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
# the file, and leave the rest in their default state.
tmpWidth = self.optState.getValue("GuiOutline", "columnWidth", {})
for hName in tmpWidth:
try:
self.colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName])
self._colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName])
except Exception:
logger.warning("Ignored unknown outline column '%s'", str(hName))
tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {})
for hName in tmpHidden:
try:
self.colHidden[nwOutline[hName]] = tmpHidden[hName]
self._colHidden[nwOutline[hName]] = tmpHidden[hName]
except Exception:
logger.warning("Ignored unknown outline column '%s'", str(hName))
self.headerMenu.setHiddenState(self.colHidden)
self.headerMenu.setHiddenState(self._colHidden)
return
@@ -314,19 +317,19 @@ class GuiOutline(QTreeWidget):
the last known width in case they're unhidden again.
"""
# If we haven't built the tree, there is nothing to save.
if self.lastBuild == 0:
if self._lastBuild == 0:
return
treeOrder = []
colWidth = {}
colWidth = {}
colHidden = {}
for hItem in nwOutline:
colWidth[hItem.name] = self.mainConf.rpxInt(self.colWidth[hItem])
colHidden[hItem.name] = self.colHidden[hItem]
colWidth[hItem.name] = self.mainConf.rpxInt(self._colWidth[hItem])
colHidden[hItem.name] = self._colHidden[hItem]
for iCol in range(self.columnCount()):
hName = self.treeOrder[iCol].name
hName = self._treeOrder[iCol].name
treeOrder.append(hName)
iLog = self.treeHead.logicalIndex(iCol)
@@ -353,41 +356,40 @@ class GuiOutline(QTreeWidget):
"""
self.clear()
if self.firstView:
if self._firstView:
theLabels = []
for i, hItem in enumerate(self.treeOrder):
for i, hItem in enumerate(self._treeOrder):
theLabels.append(trConst(nwLabels.OUTLINE_COLS[hItem]))
self.colIndex[hItem] = i
self._colIdx[hItem] = i
self.setHeaderLabels(theLabels)
for hItem in self.treeOrder:
self.setColumnWidth(self.colIndex[hItem], self.colWidth[hItem])
self.setColumnHidden(self.colIndex[hItem], self.colHidden[hItem])
for hItem in self._treeOrder:
self.setColumnWidth(self._colIdx[hItem], self._colWidth[hItem])
self.setColumnHidden(self._colIdx[hItem], self._colHidden[hItem])
# Make sure title column is always visible,
# and handle column always hidden
self.setColumnHidden(self.colIndex[nwOutline.TITLE], False)
self.setColumnHidden(self._colIdx[nwOutline.TITLE], False)
headItem = self.headerItem()
headItem.setTextAlignment(self.colIndex[nwOutline.CCOUNT], Qt.AlignRight)
headItem.setTextAlignment(self.colIndex[nwOutline.WCOUNT], Qt.AlignRight)
headItem.setTextAlignment(self.colIndex[nwOutline.PCOUNT], Qt.AlignRight)
headItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignRight)
headItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
headItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
currTitle = None
currTitle = None
currChapter = None
currScene = None
currScene = None
for tKey, tHandle, sTitle, novIdx in self.theIndex.novelStructure(skipExcluded=True):
tItem = self._createTreeItem(tHandle, sTitle, novIdx)
self.treeMap[tKey] = tItem
tLevel = novIdx["level"]
if tLevel == "H1":
self.addTopLevelItem(tItem)
currTitle = tItem
currTitle = tItem
currChapter = None
currScene = None
currScene = None
elif tLevel == "H2":
if currTitle is None:
@@ -395,7 +397,7 @@ class GuiOutline(QTreeWidget):
else:
currTitle.addChild(tItem)
currChapter = tItem
currScene = None
currScene = None
elif tLevel == "H3":
if currChapter is None:
@@ -421,47 +423,47 @@ class GuiOutline(QTreeWidget):
tItem.setExpanded(True)
self.lastBuild = time()
self._lastBuild = time()
return
def _createTreeItem(self, tHandle, sTitle, novIdx):
"""Populate a tree item with all the column values.
"""
nwItem = self.theProject.projTree[tHandle]
nwItem = self.theProject.projTree[tHandle]
newItem = QTreeWidgetItem()
hIcon = "doc_%s" % novIdx["level"].lower()
hIcon = "doc_%s" % novIdx["level"].lower()
cC = int(novIdx["cCount"])
wC = int(novIdx["wCount"])
pC = int(novIdx["pCount"])
newItem.setText(self.colIndex[nwOutline.TITLE], novIdx["title"])
newItem.setData(self.colIndex[nwOutline.TITLE], Qt.UserRole, tHandle)
newItem.setIcon(self.colIndex[nwOutline.TITLE], self.theTheme.getIcon(hIcon))
newItem.setText(self.colIndex[nwOutline.LEVEL], novIdx["level"])
newItem.setText(self.colIndex[nwOutline.LABEL], nwItem.itemName)
newItem.setIcon(self.colIndex[nwOutline.LABEL], self.theTheme.getIcon("proj_document"))
newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:].lstrip("0"))
newItem.setData(self.colIndex[nwOutline.LINE], Qt.UserRole, sTitle)
newItem.setText(self.colIndex[nwOutline.SYNOP], novIdx["synopsis"])
newItem.setText(self.colIndex[nwOutline.CCOUNT], f"{cC:n}")
newItem.setText(self.colIndex[nwOutline.WCOUNT], f"{wC:n}")
newItem.setText(self.colIndex[nwOutline.PCOUNT], f"{pC:n}")
newItem.setTextAlignment(self.colIndex[nwOutline.CCOUNT], Qt.AlignRight)
newItem.setTextAlignment(self.colIndex[nwOutline.WCOUNT], Qt.AlignRight)
newItem.setTextAlignment(self.colIndex[nwOutline.PCOUNT], Qt.AlignRight)
newItem.setText(self._colIdx[nwOutline.TITLE], novIdx["title"])
newItem.setData(self._colIdx[nwOutline.TITLE], Qt.UserRole, tHandle)
newItem.setIcon(self._colIdx[nwOutline.TITLE], self.theTheme.getIcon(hIcon))
newItem.setText(self._colIdx[nwOutline.LEVEL], novIdx["level"])
newItem.setText(self._colIdx[nwOutline.LABEL], nwItem.itemName)
newItem.setIcon(self._colIdx[nwOutline.LABEL], self.theTheme.getIcon("proj_document"))
newItem.setText(self._colIdx[nwOutline.LINE], sTitle[1:].lstrip("0"))
newItem.setData(self._colIdx[nwOutline.LINE], Qt.UserRole, sTitle)
newItem.setText(self._colIdx[nwOutline.SYNOP], novIdx["synopsis"])
newItem.setText(self._colIdx[nwOutline.CCOUNT], f"{cC:n}")
newItem.setText(self._colIdx[nwOutline.WCOUNT], f"{wC:n}")
newItem.setText(self._colIdx[nwOutline.PCOUNT], f"{pC:n}")
newItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignRight)
newItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignRight)
newItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignRight)
theRefs = self.theIndex.getReferences(tHandle, sTitle)
newItem.setText(self.colIndex[nwOutline.POV], ", ".join(theRefs[nwKeyWords.POV_KEY]))
newItem.setText(self.colIndex[nwOutline.FOCUS], ", ".join(theRefs[nwKeyWords.FOCUS_KEY]))
newItem.setText(self.colIndex[nwOutline.CHAR], ", ".join(theRefs[nwKeyWords.CHAR_KEY]))
newItem.setText(self.colIndex[nwOutline.PLOT], ", ".join(theRefs[nwKeyWords.PLOT_KEY]))
newItem.setText(self.colIndex[nwOutline.TIME], ", ".join(theRefs[nwKeyWords.TIME_KEY]))
newItem.setText(self.colIndex[nwOutline.WORLD], ", ".join(theRefs[nwKeyWords.WORLD_KEY]))
newItem.setText(self.colIndex[nwOutline.OBJECT], ", ".join(theRefs[nwKeyWords.OBJECT_KEY]))
newItem.setText(self.colIndex[nwOutline.ENTITY], ", ".join(theRefs[nwKeyWords.ENTITY_KEY]))
newItem.setText(self.colIndex[nwOutline.CUSTOM], ", ".join(theRefs[nwKeyWords.CUSTOM_KEY]))
newItem.setText(self._colIdx[nwOutline.POV], ", ".join(theRefs[nwKeyWords.POV_KEY]))
newItem.setText(self._colIdx[nwOutline.FOCUS], ", ".join(theRefs[nwKeyWords.FOCUS_KEY]))
newItem.setText(self._colIdx[nwOutline.CHAR], ", ".join(theRefs[nwKeyWords.CHAR_KEY]))
newItem.setText(self._colIdx[nwOutline.PLOT], ", ".join(theRefs[nwKeyWords.PLOT_KEY]))
newItem.setText(self._colIdx[nwOutline.TIME], ", ".join(theRefs[nwKeyWords.TIME_KEY]))
newItem.setText(self._colIdx[nwOutline.WORLD], ", ".join(theRefs[nwKeyWords.WORLD_KEY]))
newItem.setText(self._colIdx[nwOutline.OBJECT], ", ".join(theRefs[nwKeyWords.OBJECT_KEY]))
newItem.setText(self._colIdx[nwOutline.ENTITY], ", ".join(theRefs[nwKeyWords.ENTITY_KEY]))
newItem.setText(self._colIdx[nwOutline.CUSTOM], ", ".join(theRefs[nwKeyWords.CUSTOM_KEY]))
return newItem
+3 -3
View File
@@ -191,7 +191,7 @@ class GuiOutlineDetails(QScrollArea):
# Selected Item Tags
self.tagsGroup = QGroupBox(self.tr("Reference Tags"), self)
self.tagsForm = QGridLayout()
self.tagsForm = QGridLayout()
self.tagsGroup.setLayout(self.tagsForm)
self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, Qt.AlignTop | Qt.AlignLeft)
@@ -279,8 +279,8 @@ class GuiOutlineDetails(QScrollArea):
"""Update the content of the tree with the given handle and line
number pointing to a header.
"""
nwItem = self.theProject.projTree[tHandle]
novIdx = self.theIndex.getNovelData(tHandle, sTitle)
nwItem = self.theProject.projTree[tHandle]
novIdx = self.theIndex.getNovelData(tHandle, sTitle)
theRefs = self.theIndex.getReferences(tHandle, sTitle)
if nwItem is None or novIdx is None:
return False
+5 -5
View File
@@ -24,8 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import nw
import logging
import math
import logging
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QFont
@@ -66,10 +66,10 @@ class GuiProjectDetails(PagedDialog):
self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "winHeight", wH))
)
self.tabMain = GuiProjectDetailsMain(self.theParent, self.theProject)
self.tabMain = GuiProjectDetailsMain(self.theParent, self.theProject)
self.tabContents = GuiProjectDetailsContents(self.theParent, self.theProject)
self.addTab(self.tabMain, self.tr("Overview"))
self.addTab(self.tabMain, self.tr("Overview"))
self.addTab(self.tabContents, self.tr("Contents"))
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Close)
@@ -413,8 +413,8 @@ class GuiProjectDetailsContents(QWidget):
"""Set the content of the chapter/page tree.
"""
dblPages = self.dblValue.isChecked()
wpPage = self.wpValue.value()
fstPage = self.poValue.value() - 1
wpPage = self.wpValue.value()
fstPage = self.poValue.value() - 1
pTotal = 0
tPages = 1
+2 -2
View File
@@ -132,7 +132,7 @@ class GuiProjectTree(QTreeWidget):
self.initTree()
# Internal Function Mapping
self.makeAlert = self.theParent.makeAlert
self.makeAlert = self.theParent.makeAlert
self.askQuestion = self.theParent.askQuestion
logger.debug("GuiProjectTree initialisation complete")
@@ -1167,7 +1167,7 @@ class GuiProjectTreeMenu(QMenu):
inTrash = theItem.itemParent == trashHandle and trashHandle is not None
isTrash = theItem.itemHandle == trashHandle and trashHandle is not None
isFile = theItem.itemType == nwItemType.FILE
isFile = theItem.itemType == nwItemType.FILE
allowNew = not (isTrash or inTrash)
+4 -4
View File
@@ -51,8 +51,8 @@ class GuiMainStatus(QStatusBar):
self.refTime = None
self.userIdle = False
colNone = QColor(*self.theTheme.statNone)
colTrue = QColor(*self.theTheme.statUnsaved)
colNone = QColor(*self.theTheme.statNone)
colTrue = QColor(*self.theTheme.statUnsaved)
colFalse = QColor(*self.theTheme.statSaved)
iPx = self.theTheme.baseIconSize
@@ -243,8 +243,8 @@ class StatusLED(QAbstractButton):
self._colNone = colNone
self._colGood = colGood
self._colBad = colBad
self._theCol = colNone
self._colBad = colBad
self._theCol = colNone
self.setFixedWidth(sW)
self.setFixedHeight(sH)
+9 -9
View File
@@ -25,9 +25,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import nw
import os
import logging
import configparser
import os
from math import ceil
from functools import partial
@@ -272,7 +272,7 @@ class GuiTheme:
cssData = ""
try:
if os.path.isfile(self.cssFile):
with open(self.cssFile, mode="r", encoding="utf8") as inFile:
with open(self.cssFile, mode="r", encoding="utf-8") as inFile:
cssData = inFile.read()
except Exception:
logger.error("Could not load theme css file")
@@ -282,7 +282,7 @@ class GuiTheme:
# Config File
confParser = configparser.ConfigParser()
try:
with open(self.confFile, mode="r", encoding="utf8") as inFile:
with open(self.confFile, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile)
except Exception:
logger.error("Could not load theme settings from: %s", self.confFile)
@@ -340,7 +340,7 @@ class GuiTheme:
confParser = configparser.ConfigParser()
try:
with open(self.syntaxFile, mode="r", encoding="utf8") as inFile:
with open(self.syntaxFile, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile)
except Exception:
logger.error("Could not load syntax colours from: %s", self.syntaxFile)
@@ -395,7 +395,7 @@ class GuiTheme:
)
logger.verbose("Checking theme config for '%s'", themeDir)
try:
with open(themeConf, mode="r", encoding="utf8") as inFile:
with open(themeConf, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile)
except Exception as e:
self.makeAlert([
@@ -421,14 +421,14 @@ class GuiTheme:
return self.syntaxList
confParser = configparser.ConfigParser()
syntaxDir = os.path.join(self.mainConf.themeRoot, self.syntaxPath)
syntaxDir = os.path.join(self.mainConf.themeRoot, self.syntaxPath)
for syntaxFile in os.listdir(syntaxDir):
syntaxPath = os.path.join(syntaxDir, syntaxFile)
if not os.path.isfile(syntaxPath):
continue
logger.verbose("Checking theme syntax for '%s'", syntaxFile)
try:
with open(syntaxPath, mode="r", encoding="utf8") as inFile:
with open(syntaxPath, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile)
except Exception as e:
self.makeAlert([
@@ -646,7 +646,7 @@ class GuiIcons:
# Config File
confParser = configparser.ConfigParser()
try:
with open(self.confFile, mode="r", encoding="utf8") as inFile:
with open(self.confFile, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile)
except Exception:
logger.error("Could not load icon theme settings from: %s", self.confFile)
@@ -744,7 +744,7 @@ class GuiIcons:
themeConf = os.path.join(themePath, self.confName)
logger.verbose("Checking icon theme config for '%s'", themeDir)
try:
with open(themeConf, mode="r", encoding="utf8") as inFile:
with open(themeConf, mode="r", encoding="utf-8") as inFile:
confParser.read_file(inFile)
except Exception as e:
self.makeAlert([