Add a switch to enable/disable showing page breaks in the manuscript tool
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"Objects": "Objects",
|
"Objects": "Objects",
|
||||||
"Entities": "Entities",
|
"Entities": "Entities",
|
||||||
"Custom": "Custom",
|
"Custom": "Custom",
|
||||||
|
"New Page": "New Page",
|
||||||
"0": "Zero",
|
"0": "Zero",
|
||||||
"1": "One",
|
"1": "One",
|
||||||
"2": "Two",
|
"2": "Two",
|
||||||
|
|||||||
@@ -87,15 +87,6 @@ class NWBuildDocument:
|
|||||||
"""
|
"""
|
||||||
return self._cache
|
return self._cache
|
||||||
|
|
||||||
##
|
|
||||||
# Setters
|
|
||||||
##
|
|
||||||
|
|
||||||
def setBuildOutline(self, state: bool) -> None:
|
|
||||||
"""Turn on/off outline for builds."""
|
|
||||||
self._outline = state
|
|
||||||
return
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Special Methods
|
# Special Methods
|
||||||
##
|
##
|
||||||
@@ -122,11 +113,12 @@ class NWBuildDocument:
|
|||||||
self._queue.append(item.itemHandle)
|
self._queue.append(item.itemHandle)
|
||||||
return
|
return
|
||||||
|
|
||||||
def iterBuildPreview(self) -> Iterable[tuple[int, bool]]:
|
def iterBuildPreview(self, newPage: bool) -> Iterable[tuple[int, bool]]:
|
||||||
"""Build a preview QTextDocument."""
|
"""Build a preview QTextDocument."""
|
||||||
makeObj = ToQTextDocument(self._project)
|
makeObj = ToQTextDocument(self._project)
|
||||||
filtered = self._setupBuild(makeObj)
|
filtered = self._setupBuild(makeObj)
|
||||||
makeObj.initDocument()
|
makeObj.initDocument()
|
||||||
|
makeObj.setShowNewPage(newPage)
|
||||||
self._outline = True
|
self._outline = True
|
||||||
yield from self._iterBuild(makeObj, filtered)
|
yield from self._iterBuild(makeObj, filtered)
|
||||||
makeObj.closeDocument()
|
makeObj.closeDocument()
|
||||||
@@ -352,14 +344,17 @@ class NWBuildDocument:
|
|||||||
tItem = self._project.tree[tHandle]
|
tItem = self._project.tree[tHandle]
|
||||||
if isinstance(tItem, NWItem):
|
if isinstance(tItem, NWItem):
|
||||||
try:
|
try:
|
||||||
if tItem.isRootType() and not tItem.isNovelLike():
|
if tItem.isRootType():
|
||||||
bldObj.addRootHeading(tHandle)
|
if tItem.isNovelLike():
|
||||||
if convert:
|
bldObj.setBreakNext()
|
||||||
bldObj.doConvert()
|
else:
|
||||||
if self._count:
|
bldObj.addRootHeading(tHandle)
|
||||||
bldObj.countStats()
|
if convert:
|
||||||
if self._outline:
|
bldObj.doConvert()
|
||||||
bldObj.buildOutline()
|
if self._count:
|
||||||
|
bldObj.countStats()
|
||||||
|
if self._outline:
|
||||||
|
bldObj.buildOutline()
|
||||||
elif tItem.isFileType():
|
elif tItem.isFileType():
|
||||||
bldObj.setText(tHandle)
|
bldObj.setText(tHandle)
|
||||||
bldObj.doPreProcessing()
|
bldObj.doPreProcessing()
|
||||||
@@ -370,8 +365,6 @@ class NWBuildDocument:
|
|||||||
bldObj.buildOutline()
|
bldObj.buildOutline()
|
||||||
if convert:
|
if convert:
|
||||||
bldObj.doConvert()
|
bldObj.doConvert()
|
||||||
else:
|
|
||||||
logger.info(f"Build: Skipping '{tHandle}'")
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self._error = f"Build: Failed to build '{tHandle}'"
|
self._error = f"Build: Failed to build '{tHandle}'"
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ VALID_MAP: dict[str, set[str]] = {
|
|||||||
},
|
},
|
||||||
"GuiManuscript": {
|
"GuiManuscript": {
|
||||||
"winWidth", "winHeight", "optsWidth", "viewWidth", "listHeight",
|
"winWidth", "winHeight", "optsWidth", "viewWidth", "listHeight",
|
||||||
"detailsHeight", "detailsWidth", "detailsExpanded",
|
"detailsHeight", "detailsWidth", "detailsExpanded", "showNewPage",
|
||||||
},
|
},
|
||||||
"GuiManuscriptBuild": {
|
"GuiManuscriptBuild": {
|
||||||
"winWidth", "winHeight", "fmtWidth", "sumWidth",
|
"winWidth", "winHeight", "fmtWidth", "sumWidth",
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ from novelwriter.core.buildsettings import BuildCollection, BuildSettings
|
|||||||
from novelwriter.core.docbuild import NWBuildDocument
|
from novelwriter.core.docbuild import NWBuildDocument
|
||||||
from novelwriter.extensions.modified import NIconToggleButton, NIconToolButton, NToolDialog
|
from novelwriter.extensions.modified import NIconToggleButton, NIconToolButton, NToolDialog
|
||||||
from novelwriter.extensions.progressbars import NProgressCircle
|
from novelwriter.extensions.progressbars import NProgressCircle
|
||||||
|
from novelwriter.extensions.switch import NSwitch
|
||||||
from novelwriter.formats.tokenizer import HeadingFormatter
|
from novelwriter.formats.tokenizer import HeadingFormatter
|
||||||
from novelwriter.formats.toqdoc import ToQTextDocument
|
from novelwriter.formats.toqdoc import ToQTextDocument
|
||||||
from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON
|
from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON
|
||||||
@@ -87,6 +88,7 @@ class GuiManuscript(NToolDialog):
|
|||||||
self.setMinimumWidth(CONFIG.pxInt(600))
|
self.setMinimumWidth(CONFIG.pxInt(600))
|
||||||
self.setMinimumHeight(CONFIG.pxInt(500))
|
self.setMinimumHeight(CONFIG.pxInt(500))
|
||||||
|
|
||||||
|
iPx = SHARED.theme.baseIconHeight
|
||||||
iSz = SHARED.theme.baseIconSize
|
iSz = SHARED.theme.baseIconSize
|
||||||
wWin = CONFIG.pxInt(900)
|
wWin = CONFIG.pxInt(900)
|
||||||
hWin = CONFIG.pxInt(600)
|
hWin = CONFIG.pxInt(600)
|
||||||
@@ -191,15 +193,31 @@ class GuiManuscript(NToolDialog):
|
|||||||
self.processBox.addWidget(self.btnBuild, 1, 0)
|
self.processBox.addWidget(self.btnBuild, 1, 0)
|
||||||
self.processBox.addWidget(self.btnClose, 1, 1)
|
self.processBox.addWidget(self.btnClose, 1, 1)
|
||||||
|
|
||||||
|
# Preview Options
|
||||||
|
# ===============
|
||||||
|
|
||||||
|
self.swtNewPage = NSwitch(self, height=iPx)
|
||||||
|
self.swtNewPage.setChecked(pOptions.getBool("GuiManuscript", "showNewPage", True))
|
||||||
|
self.swtNewPage.clicked.connect(self._generatePreview)
|
||||||
|
|
||||||
|
self.lblNewPage = QLabel(self.tr("Show Page Breaks"), self)
|
||||||
|
self.lblNewPage.setBuddy(self.swtNewPage)
|
||||||
|
|
||||||
# Assemble GUI
|
# Assemble GUI
|
||||||
# ============
|
# ============
|
||||||
|
|
||||||
self.docPreview = _PreviewWidget(self)
|
self.docPreview = _PreviewWidget(self)
|
||||||
self.docStats = _StatsWidget(self)
|
self.docStats = _StatsWidget(self)
|
||||||
|
|
||||||
|
self.docBar = QHBoxLayout()
|
||||||
|
self.docBar.addWidget(self.docStats, 1, QtAlignTop)
|
||||||
|
self.docBar.addWidget(self.lblNewPage, 0, QtAlignTop)
|
||||||
|
self.docBar.addWidget(self.swtNewPage, 0, QtAlignTop)
|
||||||
|
self.docBar.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
self.docBox = QVBoxLayout()
|
self.docBox = QVBoxLayout()
|
||||||
self.docBox.addWidget(self.docPreview, 1)
|
self.docBox.addWidget(self.docPreview, 1)
|
||||||
self.docBox.addWidget(self.docStats, 0)
|
self.docBox.addLayout(self.docBar, 0)
|
||||||
self.docBox.setContentsMargins(0, 0, 0, 0)
|
self.docBox.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
self.docWdiget = QWidget(self)
|
self.docWdiget = QWidget(self)
|
||||||
@@ -344,6 +362,7 @@ class GuiManuscript(NToolDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
start = time()
|
start = time()
|
||||||
|
showNewPage = self.swtNewPage.isChecked()
|
||||||
|
|
||||||
# Make sure editor content is saved before we start
|
# Make sure editor content is saved before we start
|
||||||
SHARED.saveEditor()
|
SHARED.saveEditor()
|
||||||
@@ -352,7 +371,7 @@ class GuiManuscript(NToolDialog):
|
|||||||
docBuild.queueAll()
|
docBuild.queueAll()
|
||||||
|
|
||||||
self.docPreview.beginNewBuild(len(docBuild))
|
self.docPreview.beginNewBuild(len(docBuild))
|
||||||
for step, _ in docBuild.iterBuildPreview():
|
for step, _ in docBuild.iterBuildPreview(showNewPage):
|
||||||
self.docPreview.buildStep(step + 1)
|
self.docPreview.buildStep(step + 1)
|
||||||
QApplication.processEvents()
|
QApplication.processEvents()
|
||||||
|
|
||||||
@@ -434,6 +453,7 @@ class GuiManuscript(NToolDialog):
|
|||||||
detailsHeight = CONFIG.rpxInt(buildSplit[1])
|
detailsHeight = CONFIG.rpxInt(buildSplit[1])
|
||||||
detailsWidth = CONFIG.rpxInt(self.buildDetails.getColumnWidth())
|
detailsWidth = CONFIG.rpxInt(self.buildDetails.getColumnWidth())
|
||||||
detailsExpanded = self.buildDetails.getExpandedState()
|
detailsExpanded = self.buildDetails.getExpandedState()
|
||||||
|
showNewPage = self.swtNewPage.isChecked()
|
||||||
|
|
||||||
logger.debug("Saving State: GuiManuscript")
|
logger.debug("Saving State: GuiManuscript")
|
||||||
pOptions = SHARED.project.options
|
pOptions = SHARED.project.options
|
||||||
@@ -445,6 +465,7 @@ class GuiManuscript(NToolDialog):
|
|||||||
pOptions.setValue("GuiManuscript", "detailsHeight", detailsHeight)
|
pOptions.setValue("GuiManuscript", "detailsHeight", detailsHeight)
|
||||||
pOptions.setValue("GuiManuscript", "detailsWidth", detailsWidth)
|
pOptions.setValue("GuiManuscript", "detailsWidth", detailsWidth)
|
||||||
pOptions.setValue("GuiManuscript", "detailsExpanded", detailsExpanded)
|
pOptions.setValue("GuiManuscript", "detailsExpanded", detailsExpanded)
|
||||||
|
pOptions.setValue("GuiManuscript", "showNewPage", showNewPage)
|
||||||
pOptions.saveSettings()
|
pOptions.saveSettings()
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -945,7 +966,7 @@ class _StatsWidget(QWidget):
|
|||||||
self.toggleButton = NIconToggleButton(self, SHARED.theme.baseIconSize, "unfold")
|
self.toggleButton = NIconToggleButton(self, SHARED.theme.baseIconSize, "unfold")
|
||||||
self.toggleButton.toggled.connect(self._toggleView)
|
self.toggleButton.toggled.connect(self._toggleView)
|
||||||
|
|
||||||
self._buildStatsPanel()
|
self._buildBottomPanel()
|
||||||
|
|
||||||
self.mainStack = QStackedWidget(self)
|
self.mainStack = QStackedWidget(self)
|
||||||
self.mainStack.addWidget(self.minWidget)
|
self.mainStack.addWidget(self.minWidget)
|
||||||
@@ -1010,8 +1031,8 @@ class _StatsWidget(QWidget):
|
|||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
def _buildStatsPanel(self) -> None:
|
def _buildBottomPanel(self) -> None:
|
||||||
"""Build the minimal stats page."""
|
"""Build the bottom page."""
|
||||||
mPx = CONFIG.pxInt(8)
|
mPx = CONFIG.pxInt(8)
|
||||||
hPx = CONFIG.pxInt(12)
|
hPx = CONFIG.pxInt(12)
|
||||||
vPx = CONFIG.pxInt(4)
|
vPx = CONFIG.pxInt(4)
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ def testCoreDocBuild_OpenDocument(monkeypatch, mockGUI, prjLipsum, fncPath, tstP
|
|||||||
build.unpack(BUILD_CONF)
|
build.unpack(BUILD_CONF)
|
||||||
|
|
||||||
docBuild = NWBuildDocument(project, build)
|
docBuild = NWBuildDocument(project, build)
|
||||||
docBuild.setBuildOutline(True)
|
docBuild._outline = True
|
||||||
docBuild.queueAll()
|
docBuild.queueAll()
|
||||||
|
|
||||||
assert docBuild._outline is True
|
assert docBuild._outline is True
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ def testToolManuscript_Init(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
|
|||||||
buildTestProject(nwGUI, projPath)
|
buildTestProject(nwGUI, projPath)
|
||||||
nwGUI.openProject(projPath)
|
nwGUI.openProject(projPath)
|
||||||
SHARED.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi")
|
SHARED.project.storage.getDocument(C.hChapterDoc).writeDocument("## A Chapter\n\n\t\tHi")
|
||||||
allText = "New Novel\nBy Jane Doe\nA Chapter\n\t\tHi"
|
allText = "New Novel\nBy Jane Doe\n\nNew Page\nA Chapter\n\t\tHi"
|
||||||
|
|
||||||
nwGUI.mainMenu.aBuildManuscript.activate(QAction.ActionEvent.Trigger)
|
nwGUI.mainMenu.aBuildManuscript.activate(QAction.ActionEvent.Trigger)
|
||||||
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiManuscript) is not None, timeout=1000)
|
qtbot.waitUntil(lambda: SHARED.findTopLevelWidget(GuiManuscript) is not None, timeout=1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user