Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to the build tool #1846

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions novelwriter/tools/manusbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
from novelwriter.enum import nwBuildFmt
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.extensions.simpleprogress import NProgressSimple
from novelwriter.types import (
QtAlignCenter, QtDialogClose, QtRoleAction, QtRoleReject, QtUserRole
)
from novelwriter.types import QtAlignCenter, QtDialogClose, QtRoleAction, QtRoleReject, QtUserRole

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -328,6 +326,9 @@ def _runBuild(self) -> bool:
):
return False

# Make sure editor content is saved before we start
SHARED.mainGui.saveDocument()

docBuild = NWBuildDocument(SHARED.project, self._build)
docBuild.queueAll()

Expand Down
14 changes: 9 additions & 5 deletions novelwriter/tools/manuscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ def _generatePreview(self) -> None:
if not (build := self._getSelectedBuild()):
return

# Make sure editor content is saved before we start
SHARED.mainGui.saveDocument()

docBuild = NWBuildDocument(SHARED.project, build)
docBuild.setPreviewMode(True)
docBuild.queueAll()
Expand Down Expand Up @@ -749,6 +752,7 @@ def __init__(self, parent: QWidget) -> None:

self._docTime = 0
self._buildName = ""
self._scrollPos = 0

# Document Setup
dPalette = self.palette()
Expand Down Expand Up @@ -845,6 +849,7 @@ def beginNewBuild(self, length: int) -> None:
self.buildProgress.setValue(0)
self.buildProgress.setCentreText(None)
self.buildProgress.setVisible(True)
self._scrollPos = self.verticalScrollBar().value()
self.setPlaceholderText("")
self.clear()
return
Expand All @@ -857,7 +862,6 @@ def buildStep(self, value: int) -> None:

def setContent(self, data: dict) -> None:
"""Set the content of the preview widget."""
sPos = self.verticalScrollBar().value()
QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor))

self.buildProgress.setCentreText(self.tr("Processing ..."))
Expand All @@ -874,7 +878,6 @@ def setContent(self, data: dict) -> None:
cursor = self.textCursor()
cursor.insertText("\t")

self.verticalScrollBar().setValue(sPos)
self._docTime = checkInt(data.get("time"), 0)
self._updateBuildAge()

Expand All @@ -885,7 +888,7 @@ def setContent(self, data: dict) -> None:
self.buildProgress.setCentreText(self.tr("Done"))
QApplication.restoreOverrideCursor()
QApplication.processEvents()
QTimer.singleShot(300, self._hideProgress)
QTimer.singleShot(300, self._postUpdate)

return

Expand Down Expand Up @@ -940,9 +943,10 @@ def _updateBuildAge(self) -> None:
return

@pyqtSlot()
def _hideProgress(self) -> None:
"""Clean up the build progress bar."""
def _postUpdate(self) -> None:
"""Run tasks after content update."""
self.buildProgress.setVisible(False)
self.verticalScrollBar().setValue(self._scrollPos)
return

##
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tools/test_tools_manuscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def testManuscript_Features(monkeypatch, qtbot, nwGUI, projPath, mockRnd):
assert manus.docPreview.document().defaultTextOption().alignment() == QtAlignAbsolute

# Tests are too fast to trigger this one, so we trigger it manually to ensure it isn't failing
manus.docPreview._hideProgress()
manus.docPreview._postUpdate()

# Builds
# ======
Expand Down