Most columns now available in outline
This commit is contained in:
+117
-51
@@ -20,35 +20,53 @@ from PyQt5.QtWidgets import (
|
|||||||
QWidget, QVBoxLayout, QTreeWidget, QTreeWidgetItem
|
QWidget, QVBoxLayout, QTreeWidget, QTreeWidgetItem
|
||||||
)
|
)
|
||||||
|
|
||||||
from nw.constants import nwItemLayout
|
from nw.constants import nwItemLayout, nwKeyWords, nwLabels
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class GuiProjectOutline(QWidget):
|
class GuiProjectOutline(QWidget):
|
||||||
|
|
||||||
I_TITLE = 0
|
I_TITLE = 0
|
||||||
I_LEVEL = 1
|
I_LEVEL = 1
|
||||||
I_LABEL = 2
|
I_LABEL = 2
|
||||||
I_LINE = 3
|
I_LINE = 3
|
||||||
I_WORDS = 4
|
I_WCOUNT = 4
|
||||||
I_CHARS = 5
|
I_CCOUNT = 5
|
||||||
I_PARAS = 6
|
I_PCOUNT = 6
|
||||||
I_SYNOP = 7
|
I_SYNOP = 7
|
||||||
|
I_POV = 8
|
||||||
|
I_CHAR = 9
|
||||||
|
I_PLOT = 10
|
||||||
|
I_TIME = 11
|
||||||
|
I_WORLD = 12
|
||||||
|
I_OBJECT = 13
|
||||||
|
I_ENTITY = 14
|
||||||
|
I_CUSTOM = 15
|
||||||
|
|
||||||
COL_ORDER = [
|
COL_ORDER = [
|
||||||
I_TITLE, I_LEVEL, I_LABEL, I_LINE,
|
I_TITLE, I_LEVEL, I_LABEL, I_LINE,
|
||||||
I_WORDS, I_CHARS, I_PARAS, I_SYNOP,
|
I_WCOUNT, I_CCOUNT, I_PCOUNT, I_SYNOP,
|
||||||
|
I_POV, I_CHAR, I_PLOT, I_TIME,
|
||||||
|
I_WORLD, I_OBJECT, I_ENTITY, I_CUSTOM,
|
||||||
]
|
]
|
||||||
|
|
||||||
COL_LABELS = {
|
COL_LABELS = {
|
||||||
I_TITLE : "Title",
|
I_TITLE : "Title",
|
||||||
I_LEVEL : "Level",
|
I_LEVEL : "Level",
|
||||||
I_LABEL : "Document",
|
I_LABEL : "Document",
|
||||||
I_LINE : "Line",
|
I_LINE : "Line",
|
||||||
I_WORDS : "Words",
|
I_WCOUNT : "Words",
|
||||||
I_CHARS : "Chars",
|
I_CCOUNT : "Chars",
|
||||||
I_PARAS : "Pars",
|
I_PCOUNT : "Pars",
|
||||||
I_SYNOP : "Synopsis",
|
I_SYNOP : "Synopsis",
|
||||||
|
I_POV : nwLabels.KEY_NAME[nwKeyWords.POV_KEY],
|
||||||
|
I_CHAR : nwLabels.KEY_NAME[nwKeyWords.CHAR_KEY],
|
||||||
|
I_PLOT : nwLabels.KEY_NAME[nwKeyWords.PLOT_KEY],
|
||||||
|
I_TIME : nwLabels.KEY_NAME[nwKeyWords.TIME_KEY],
|
||||||
|
I_WORLD : nwLabels.KEY_NAME[nwKeyWords.WORLD_KEY],
|
||||||
|
I_OBJECT : nwLabels.KEY_NAME[nwKeyWords.OBJECT_KEY],
|
||||||
|
I_ENTITY : nwLabels.KEY_NAME[nwKeyWords.ENTITY_KEY],
|
||||||
|
I_CUSTOM : nwLabels.KEY_NAME[nwKeyWords.CUSTOM_KEY],
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, theParent, theProject):
|
def __init__(self, theParent, theProject):
|
||||||
@@ -87,9 +105,9 @@ class GuiProjectOutline(QWidget):
|
|||||||
self.mainTree.setHeaderLabels(theLabels)
|
self.mainTree.setHeaderLabels(theLabels)
|
||||||
|
|
||||||
treeHead = self.mainTree.headerItem()
|
treeHead = self.mainTree.headerItem()
|
||||||
treeHead.setTextAlignment(self.I_CHARS,Qt.AlignRight)
|
treeHead.setTextAlignment(self.I_CCOUNT,Qt.AlignRight)
|
||||||
treeHead.setTextAlignment(self.I_WORDS,Qt.AlignRight)
|
treeHead.setTextAlignment(self.I_WCOUNT,Qt.AlignRight)
|
||||||
treeHead.setTextAlignment(self.I_PARAS,Qt.AlignRight)
|
treeHead.setTextAlignment(self.I_PCOUNT,Qt.AlignRight)
|
||||||
|
|
||||||
currTitle = None
|
currTitle = None
|
||||||
currChapter = None
|
currChapter = None
|
||||||
@@ -106,54 +124,102 @@ class GuiProjectOutline(QWidget):
|
|||||||
|
|
||||||
for tEntry in self.theIndex.novelIndex[tHandle]:
|
for tEntry in self.theIndex.novelIndex[tHandle]:
|
||||||
|
|
||||||
theLine = str(tEntry[0])
|
nTitle = str(tEntry[0])
|
||||||
|
tTitle = tEntry[2]
|
||||||
newItem = QTreeWidgetItem([""]*4)
|
tLevel = str(tEntry[1])
|
||||||
newItem.setText(self.I_TITLE, tEntry[2])
|
tLabel = nwItem.itemName
|
||||||
newItem.setText(self.I_LEVEL, str(tEntry[1]))
|
tItem = self._createTreeItem(tHandle, nTitle, tTitle, tLevel, tLabel)
|
||||||
newItem.setText(self.I_LABEL, nwItem.itemName)
|
|
||||||
newItem.setText(self.I_LINE, theLine)
|
|
||||||
|
|
||||||
cC, wC, pC = self.theIndex.getCounts(tHandle, theLine)
|
|
||||||
newItem.setText(self.I_CHARS, str(cC))
|
|
||||||
newItem.setText(self.I_WORDS, str(wC))
|
|
||||||
newItem.setText(self.I_PARAS, str(pC))
|
|
||||||
newItem.setTextAlignment(self.I_CHARS,Qt.AlignRight)
|
|
||||||
newItem.setTextAlignment(self.I_WORDS,Qt.AlignRight)
|
|
||||||
newItem.setTextAlignment(self.I_PARAS,Qt.AlignRight)
|
|
||||||
|
|
||||||
if tEntry[1] == 1:
|
if tEntry[1] == 1:
|
||||||
currTitle = newItem
|
currTitle = tItem
|
||||||
self.mainTree.addTopLevelItem(newItem)
|
self.mainTree.addTopLevelItem(tItem)
|
||||||
elif tEntry[1] == 2:
|
elif tEntry[1] == 2:
|
||||||
if currTitle is None:
|
if currTitle is None:
|
||||||
self.mainTree.addTopLevelItem(newItem)
|
self.mainTree.addTopLevelItem(tItem)
|
||||||
else:
|
else:
|
||||||
currTitle.addChild(newItem)
|
currTitle.addChild(tItem)
|
||||||
currChapter = newItem
|
currChapter = tItem
|
||||||
elif tEntry[1] == 3:
|
elif tEntry[1] == 3:
|
||||||
if currChapter is None:
|
if currChapter is None:
|
||||||
if currTitle is None:
|
if currTitle is None:
|
||||||
self.mainTree.addTopLevelItem(newItem)
|
self.mainTree.addTopLevelItem(tItem)
|
||||||
else:
|
else:
|
||||||
currTitle.addChild(newItem)
|
currTitle.addChild(tItem)
|
||||||
else:
|
else:
|
||||||
currChapter.addChild(newItem)
|
currChapter.addChild(tItem)
|
||||||
currScene = newItem
|
currScene = tItem
|
||||||
elif tEntry[1] == 4:
|
elif tEntry[1] == 4:
|
||||||
if currScene is None:
|
if currScene is None:
|
||||||
if currChapter is None:
|
if currChapter is None:
|
||||||
if currTitle is None:
|
if currTitle is None:
|
||||||
self.mainTree.addTopLevelItem(newItem)
|
self.mainTree.addTopLevelItem(tItem)
|
||||||
else:
|
else:
|
||||||
currTitle.addChild(newItem)
|
currTitle.addChild(tItem)
|
||||||
else:
|
else:
|
||||||
currChapter.addChild(newItem)
|
currChapter.addChild(tItem)
|
||||||
else:
|
else:
|
||||||
currScene.addChild(newItem)
|
currScene.addChild(tItem)
|
||||||
|
|
||||||
newItem.setExpanded(True)
|
tItem.setExpanded(True)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
##
|
||||||
|
# Internal Functions
|
||||||
|
##
|
||||||
|
|
||||||
|
def _createTreeItem(self, tHandle, nTitle, tTitle, tLevel, tLabel):
|
||||||
|
|
||||||
|
newItem = QTreeWidgetItem()
|
||||||
|
newItem.setText(self.I_TITLE, tTitle)
|
||||||
|
newItem.setText(self.I_LEVEL, tLevel)
|
||||||
|
newItem.setText(self.I_LABEL, tLabel)
|
||||||
|
newItem.setText(self.I_LINE, nTitle)
|
||||||
|
|
||||||
|
cC, wC, pC = self.theIndex.getCounts(tHandle, nTitle)
|
||||||
|
newItem.setText(self.I_CCOUNT, str(cC))
|
||||||
|
newItem.setText(self.I_WCOUNT, str(wC))
|
||||||
|
newItem.setText(self.I_PCOUNT, str(pC))
|
||||||
|
newItem.setTextAlignment(self.I_CCOUNT,Qt.AlignRight)
|
||||||
|
newItem.setTextAlignment(self.I_WCOUNT,Qt.AlignRight)
|
||||||
|
newItem.setTextAlignment(self.I_PCOUNT,Qt.AlignRight)
|
||||||
|
|
||||||
|
povList = []
|
||||||
|
charList = []
|
||||||
|
plotList = []
|
||||||
|
timeList = []
|
||||||
|
worldList = []
|
||||||
|
objectList = []
|
||||||
|
entityList = []
|
||||||
|
customList = []
|
||||||
|
for tKey, tTag in self.theIndex.getReferences(tHandle, nTitle):
|
||||||
|
if tKey == nwKeyWords.POV_KEY:
|
||||||
|
povList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.CHAR_KEY:
|
||||||
|
charList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.PLOT_KEY:
|
||||||
|
plotList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.TIME_KEY:
|
||||||
|
timeList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.WORLD_KEY:
|
||||||
|
worldList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.OBJECT_KEY:
|
||||||
|
objectList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.ENTITY_KEY:
|
||||||
|
entityList.append(tTag)
|
||||||
|
elif tKey == nwKeyWords.CUSTOM_KEY:
|
||||||
|
customList.append(tTag)
|
||||||
|
|
||||||
|
newItem.setText(self.I_POV, ", ".join(povList))
|
||||||
|
newItem.setText(self.I_CHAR, ", ".join(charList))
|
||||||
|
newItem.setText(self.I_PLOT, ", ".join(plotList))
|
||||||
|
newItem.setText(self.I_TIME, ", ".join(timeList))
|
||||||
|
newItem.setText(self.I_WORLD, ", ".join(worldList))
|
||||||
|
newItem.setText(self.I_OBJECT, ", ".join(objectList))
|
||||||
|
newItem.setText(self.I_ENTITY, ", ".join(entityList))
|
||||||
|
newItem.setText(self.I_CUSTOM, ", ".join(customList))
|
||||||
|
|
||||||
|
return newItem
|
||||||
|
|
||||||
|
|
||||||
# END Class GuiProjectOutline
|
# END Class GuiProjectOutline
|
||||||
|
|||||||
+22
-7
@@ -475,29 +475,44 @@ class NWIndex():
|
|||||||
# Extract Data
|
# Extract Data
|
||||||
##
|
##
|
||||||
|
|
||||||
def getCounts(self, tHandle, tLine=None):
|
def getCounts(self, tHandle, nTitle=None):
|
||||||
"""Returns the counts for a file, or a section of a file
|
"""Returns the counts for a file, or a section of a file
|
||||||
starting at line tLine.
|
starting at title nTitle.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cC = 0
|
cC = 0
|
||||||
wC = 0
|
wC = 0
|
||||||
pC = 0
|
pC = 0
|
||||||
|
|
||||||
if tLine is None:
|
if nTitle is None:
|
||||||
if tHandle in self.fileCounts:
|
if tHandle in self.fileCounts:
|
||||||
cC = self.fileCounts[tHandle][0]
|
cC = self.fileCounts[tHandle][0]
|
||||||
wC = self.fileCounts[tHandle][1]
|
wC = self.fileCounts[tHandle][1]
|
||||||
pC = self.fileCounts[tHandle][2]
|
pC = self.fileCounts[tHandle][2]
|
||||||
else:
|
else:
|
||||||
if tHandle in self.textCounts:
|
if tHandle in self.textCounts:
|
||||||
if tLine in self.textCounts[tHandle]:
|
if nTitle in self.textCounts[tHandle]:
|
||||||
cC = self.textCounts[tHandle][tLine][0]
|
cC = self.textCounts[tHandle][nTitle][0]
|
||||||
wC = self.textCounts[tHandle][tLine][1]
|
wC = self.textCounts[tHandle][nTitle][1]
|
||||||
pC = self.textCounts[tHandle][tLine][2]
|
pC = self.textCounts[tHandle][nTitle][2]
|
||||||
|
|
||||||
return cC, wC, pC
|
return cC, wC, pC
|
||||||
|
|
||||||
|
def getReferences(self, tHandle, tTitle=None):
|
||||||
|
"""Extract all references made in a file, and optionally title
|
||||||
|
section. tTitle must be a string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
theRefs = []
|
||||||
|
if tHandle not in self.refIndex:
|
||||||
|
return theRefs
|
||||||
|
|
||||||
|
for nLine, tKey, tTag, nTitle in self.refIndex[tHandle]:
|
||||||
|
if tTitle is None or tTitle == str(nTitle):
|
||||||
|
theRefs.append((tKey, tTag))
|
||||||
|
|
||||||
|
return theRefs
|
||||||
|
|
||||||
def buildNovelList(self):
|
def buildNovelList(self):
|
||||||
"""Build a list of the content of the novel.
|
"""Build a list of the content of the novel.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user