Add Chapters tab to Project Details tool
This commit is contained in:
@@ -91,6 +91,11 @@ class OptionState():
|
|||||||
"GuiProjectDetails": {
|
"GuiProjectDetails": {
|
||||||
"winWidth",
|
"winWidth",
|
||||||
"winHeight",
|
"winHeight",
|
||||||
|
"widthCol0",
|
||||||
|
"widthCol1",
|
||||||
|
"widthCol2",
|
||||||
|
"widthCol3",
|
||||||
|
"widthCol4",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+152
-3
@@ -27,8 +27,12 @@
|
|||||||
|
|
||||||
import nw
|
import nw
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QDialogButtonBox
|
from PyQt5.QtCore import Qt, QSize
|
||||||
|
from PyQt5.QtWidgets import (
|
||||||
|
QWidget, QDialogButtonBox, QVBoxLayout, QTreeWidget, QTreeWidgetItem
|
||||||
|
)
|
||||||
|
|
||||||
from nw.gui.custom import PagedDialog
|
from nw.gui.custom import PagedDialog
|
||||||
|
|
||||||
@@ -59,9 +63,11 @@ class GuiProjectDetails(PagedDialog):
|
|||||||
self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "winHeight", wH))
|
self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "winHeight", wH))
|
||||||
)
|
)
|
||||||
|
|
||||||
# self.tabMain = GuiProjectEditMain(self.theParent, self.theProject)
|
self.tabMain = GuiProjectDetailsMain(self.theParent, self.theProject)
|
||||||
|
self.tabChapters = GuiProjectDetailsChapters(self.theParent, self.theProject)
|
||||||
|
|
||||||
# self.addTab(self.tabMain, "Settings")
|
self.addTab(self.tabMain, "Overview")
|
||||||
|
self.addTab(self.tabChapters, "Chapters")
|
||||||
|
|
||||||
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Close)
|
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
self.buttonBox.rejected.connect(self._doClose)
|
self.buttonBox.rejected.connect(self._doClose)
|
||||||
@@ -92,9 +98,152 @@ class GuiProjectDetails(PagedDialog):
|
|||||||
winWidth = self.mainConf.rpxInt(self.width())
|
winWidth = self.mainConf.rpxInt(self.width())
|
||||||
winHeight = self.mainConf.rpxInt(self.height())
|
winHeight = self.mainConf.rpxInt(self.height())
|
||||||
|
|
||||||
|
chColWidth = self.tabChapters.getColumnSizes()
|
||||||
|
widthCol0 = self.mainConf.rpxInt(chColWidth[0])
|
||||||
|
widthCol1 = self.mainConf.rpxInt(chColWidth[1])
|
||||||
|
widthCol2 = self.mainConf.rpxInt(chColWidth[2])
|
||||||
|
widthCol3 = self.mainConf.rpxInt(chColWidth[3])
|
||||||
|
widthCol4 = self.mainConf.rpxInt(chColWidth[4])
|
||||||
|
|
||||||
self.optState.setValue("GuiProjectDetails", "winWidth", winWidth)
|
self.optState.setValue("GuiProjectDetails", "winWidth", winWidth)
|
||||||
self.optState.setValue("GuiProjectDetails", "winHeight", winHeight)
|
self.optState.setValue("GuiProjectDetails", "winHeight", winHeight)
|
||||||
|
self.optState.setValue("GuiProjectDetails", "widthCol0", widthCol0)
|
||||||
|
self.optState.setValue("GuiProjectDetails", "widthCol1", widthCol1)
|
||||||
|
self.optState.setValue("GuiProjectDetails", "widthCol2", widthCol2)
|
||||||
|
self.optState.setValue("GuiProjectDetails", "widthCol3", widthCol3)
|
||||||
|
self.optState.setValue("GuiProjectDetails", "widthCol4", widthCol4)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# END Class GuiProjectDetails
|
# END Class GuiProjectDetails
|
||||||
|
|
||||||
|
class GuiProjectDetailsMain(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, theParent, theProject):
|
||||||
|
QWidget.__init__(self, theParent)
|
||||||
|
|
||||||
|
self.mainConf = nw.CONFIG
|
||||||
|
self.theParent = theParent
|
||||||
|
self.theProject = theProject
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
# END Class GuiProjectDetailsMain
|
||||||
|
|
||||||
|
class GuiProjectDetailsChapters(QWidget):
|
||||||
|
|
||||||
|
C_TITLE = 0
|
||||||
|
C_WORDS = 1
|
||||||
|
C_PAGES = 2
|
||||||
|
C_PAGE = 3
|
||||||
|
C_PROG = 4
|
||||||
|
|
||||||
|
def __init__(self, theParent, theProject):
|
||||||
|
QWidget.__init__(self, theParent)
|
||||||
|
|
||||||
|
self.mainConf = nw.CONFIG
|
||||||
|
self.theParent = theParent
|
||||||
|
self.theProject = theProject
|
||||||
|
self.theTheme = theParent.theTheme
|
||||||
|
self.theIndex = theParent.theIndex
|
||||||
|
self.optState = theProject.optState
|
||||||
|
|
||||||
|
iPx = self.theTheme.baseIconSize
|
||||||
|
|
||||||
|
self.chTree = QTreeWidget()
|
||||||
|
self.chTree.setIconSize(QSize(iPx, iPx))
|
||||||
|
self.chTree.setIndentation(0)
|
||||||
|
self.chTree.setColumnCount(6)
|
||||||
|
self.chTree.setHeaderLabels(["Title", "Words", "Pages", "Page", "Progress", ""])
|
||||||
|
|
||||||
|
treeHeadItem = self.chTree.headerItem()
|
||||||
|
treeHeadItem.setTextAlignment(self.C_WORDS, Qt.AlignRight)
|
||||||
|
treeHeadItem.setTextAlignment(self.C_PAGES, Qt.AlignRight)
|
||||||
|
treeHeadItem.setTextAlignment(self.C_PAGE, Qt.AlignRight)
|
||||||
|
treeHeadItem.setTextAlignment(self.C_PROG, Qt.AlignRight)
|
||||||
|
|
||||||
|
treeHeader = self.chTree.header()
|
||||||
|
treeHeader.setStretchLastSection(True)
|
||||||
|
treeHeader.setMinimumSectionSize(iPx + 6)
|
||||||
|
|
||||||
|
# Get user's column width preferences
|
||||||
|
wCol0 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol0", 200))
|
||||||
|
wCol1 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol1", 60))
|
||||||
|
wCol2 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol2", 60))
|
||||||
|
wCol3 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol3", 60))
|
||||||
|
wCol4 = self.mainConf.pxInt(self.optState.getInt("GuiProjectDetails", "widthCol4", 90))
|
||||||
|
self.chTree.setColumnWidth(0, wCol0)
|
||||||
|
self.chTree.setColumnWidth(1, wCol1)
|
||||||
|
self.chTree.setColumnWidth(2, wCol2)
|
||||||
|
self.chTree.setColumnWidth(3, wCol3)
|
||||||
|
self.chTree.setColumnWidth(4, wCol4)
|
||||||
|
self.chTree.setColumnWidth(5, 0)
|
||||||
|
|
||||||
|
self.outerBox = QVBoxLayout()
|
||||||
|
self.outerBox.addWidget(self.chTree)
|
||||||
|
|
||||||
|
self.setLayout(self.outerBox)
|
||||||
|
|
||||||
|
self._populateTree()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def getColumnSizes(self):
|
||||||
|
"""Return the column widths for the tree columns.
|
||||||
|
"""
|
||||||
|
retVals = [
|
||||||
|
self.chTree.columnWidth(0),
|
||||||
|
self.chTree.columnWidth(1),
|
||||||
|
self.chTree.columnWidth(2),
|
||||||
|
self.chTree.columnWidth(3),
|
||||||
|
self.chTree.columnWidth(4),
|
||||||
|
]
|
||||||
|
return retVals
|
||||||
|
|
||||||
|
##
|
||||||
|
# Internal Functions
|
||||||
|
##
|
||||||
|
|
||||||
|
def _populateTree(self):
|
||||||
|
"""Set the content of the chapter/page tree.
|
||||||
|
"""
|
||||||
|
self.chTree.clear()
|
||||||
|
|
||||||
|
dblPages = True
|
||||||
|
wpPage = 100
|
||||||
|
tPages = 1
|
||||||
|
|
||||||
|
theToC = self.theIndex.getTableOfContents(2)
|
||||||
|
theToC.append(("", "H0", "END", 0))
|
||||||
|
|
||||||
|
theList = []
|
||||||
|
pTotal = 0
|
||||||
|
for tKey, tLevel, tTitle, wCount in theToC:
|
||||||
|
pCount = math.ceil(wCount/wpPage)
|
||||||
|
if dblPages:
|
||||||
|
pCount += pCount%2
|
||||||
|
pTotal += pCount
|
||||||
|
theList.append((tLevel, tTitle, wCount, pCount))
|
||||||
|
|
||||||
|
for tLevel, tTitle, wCount, pCount in theList:
|
||||||
|
newItem = QTreeWidgetItem()
|
||||||
|
|
||||||
|
newItem.setIcon(self.C_TITLE, self.theTheme.getIcon("doc_%s" % tLevel.lower()))
|
||||||
|
newItem.setText(self.C_TITLE, tTitle)
|
||||||
|
newItem.setText(self.C_WORDS, f"{wCount:n}")
|
||||||
|
newItem.setText(self.C_PAGES, f"{pCount:n}")
|
||||||
|
newItem.setText(self.C_PAGE, f"{tPages:n}")
|
||||||
|
newItem.setText(self.C_PROG, f"{100*(tPages-1)/pTotal:.2f}%")
|
||||||
|
|
||||||
|
newItem.setTextAlignment(self.C_WORDS, Qt.AlignRight)
|
||||||
|
newItem.setTextAlignment(self.C_PAGES, Qt.AlignRight)
|
||||||
|
newItem.setTextAlignment(self.C_PAGE, Qt.AlignRight)
|
||||||
|
newItem.setTextAlignment(self.C_PROG, Qt.AlignRight)
|
||||||
|
|
||||||
|
tPages += pCount
|
||||||
|
|
||||||
|
self.chTree.addTopLevelItem(newItem)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
# END Class GuiProjectDetailsChapters
|
||||||
|
|||||||
Reference in New Issue
Block a user