Add back print functionality to manuscript tool
This commit is contained in:
@@ -44,7 +44,7 @@ from novelwriter.core.docbuild import NWBuildDocument
|
|||||||
from novelwriter.core.buildsettings import BuildSettings
|
from novelwriter.core.buildsettings import BuildSettings
|
||||||
from novelwriter.extensions.simpleprogress import NProgressSimple
|
from novelwriter.extensions.simpleprogress import NProgressSimple
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING: # pragma: no cover
|
||||||
from novelwriter.guimain import GuiMain
|
from novelwriter.guimain import GuiMain
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ from datetime import datetime
|
|||||||
|
|
||||||
from PyQt5.QtGui import QColor, QCursor, QFont, QPalette, QResizeEvent
|
from PyQt5.QtGui import QColor, QCursor, QFont, QPalette, QResizeEvent
|
||||||
from PyQt5.QtCore import QSize, QTimer, Qt, pyqtSlot
|
from PyQt5.QtCore import QSize, QTimer, Qt, pyqtSlot
|
||||||
|
from PyQt5.QtPrintSupport import QPrintPreviewDialog, QPrinter
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QDialog, QHBoxLayout, QLabel, QListWidget, QListWidgetItem, QMenu,
|
QDialog, QGridLayout, QHBoxLayout, QLabel, QListWidget, QListWidgetItem, QPushButton,
|
||||||
QPushButton, QSplitter, QTextBrowser, QToolButton, QVBoxLayout, QWidget,
|
QSplitter, QTextBrowser, QToolButton, QVBoxLayout, QWidget, qApp
|
||||||
qApp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG
|
from novelwriter import CONFIG
|
||||||
@@ -75,7 +75,7 @@ class GuiManuscript(QDialog):
|
|||||||
self.theProject = mainGui.theProject
|
self.theProject = mainGui.theProject
|
||||||
|
|
||||||
self._builds = BuildCollection(self.theProject)
|
self._builds = BuildCollection(self.theProject)
|
||||||
self._buildMap = {}
|
self._buildMap: dict[str, QListWidgetItem] = {}
|
||||||
|
|
||||||
self.setWindowTitle(self.tr("Build Manuscript"))
|
self.setWindowTitle(self.tr("Build Manuscript"))
|
||||||
self.setMinimumWidth(CONFIG.pxInt(600))
|
self.setMinimumWidth(CONFIG.pxInt(600))
|
||||||
@@ -144,30 +144,23 @@ class GuiManuscript(QDialog):
|
|||||||
# Process Controls
|
# Process Controls
|
||||||
# ================
|
# ================
|
||||||
|
|
||||||
self.btnPreview = QPushButton(self.tr("Build Preview"))
|
self.btnPreview = QPushButton(self.tr("Preview"))
|
||||||
self.btnPreview.clicked.connect(self._generatePreview)
|
self.btnPreview.clicked.connect(self._generatePreview)
|
||||||
|
|
||||||
|
self.btnPrint = QPushButton(self.tr("Print"))
|
||||||
|
self.btnPrint.clicked.connect(self._printDocument)
|
||||||
|
|
||||||
self.btnBuild = QPushButton(self.tr("Build"))
|
self.btnBuild = QPushButton(self.tr("Build"))
|
||||||
self.btnBuild.clicked.connect(self._buildManuscript)
|
self.btnBuild.clicked.connect(self._buildManuscript)
|
||||||
|
|
||||||
self.menuPrint = QMenu(self)
|
|
||||||
self.aPrintSend = self.menuPrint.addAction(self.tr("Print Preview"))
|
|
||||||
self.aPrintFile = self.menuPrint.addAction(self.tr("Print to PDF"))
|
|
||||||
|
|
||||||
self.btnPrint = QPushButton(self.tr("Print"))
|
|
||||||
self.btnPrint.setMenu(self.menuPrint)
|
|
||||||
|
|
||||||
self.btnClose = QPushButton(self.tr("Close"))
|
self.btnClose = QPushButton(self.tr("Close"))
|
||||||
self.btnClose.clicked.connect(self._doClose)
|
self.btnClose.clicked.connect(self._doClose)
|
||||||
|
|
||||||
self.buildBox = QHBoxLayout()
|
self.processBox = QGridLayout()
|
||||||
self.buildBox.addWidget(self.btnBuild, 0)
|
self.processBox.addWidget(self.btnPreview, 0, 0)
|
||||||
self.buildBox.addWidget(self.btnPrint, 0)
|
self.processBox.addWidget(self.btnPrint, 0, 1)
|
||||||
self.buildBox.addWidget(self.btnClose, 0)
|
self.processBox.addWidget(self.btnBuild, 1, 0)
|
||||||
|
self.processBox.addWidget(self.btnClose, 1, 1)
|
||||||
self.processBox = QVBoxLayout()
|
|
||||||
self.processBox.addWidget(self.btnPreview)
|
|
||||||
self.processBox.addLayout(self.buildBox)
|
|
||||||
|
|
||||||
# Assemble GUI
|
# Assemble GUI
|
||||||
# ============
|
# ============
|
||||||
@@ -333,6 +326,14 @@ class GuiManuscript(QDialog):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def _printDocument(self):
|
||||||
|
"""Open the print preview dialog."""
|
||||||
|
thePreview = QPrintPreviewDialog(self)
|
||||||
|
thePreview.paintRequested.connect(self.docPreview.printPreview)
|
||||||
|
thePreview.exec_()
|
||||||
|
return
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _doClose(self):
|
def _doClose(self):
|
||||||
"""Forward the close button to the default close method."""
|
"""Forward the close button to the default close method."""
|
||||||
@@ -354,6 +355,8 @@ class GuiManuscript(QDialog):
|
|||||||
self.docPreview.setJustify(
|
self.docPreview.setJustify(
|
||||||
build.getBool("format.justifyText")
|
build.getBool("format.justifyText")
|
||||||
)
|
)
|
||||||
|
if build.buildID and build.buildID in self._buildMap:
|
||||||
|
self._buildMap[build.buildID].setSelected(True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _getSelectedBuild(self) -> BuildSettings | None:
|
def _getSelectedBuild(self) -> BuildSettings | None:
|
||||||
@@ -365,10 +368,6 @@ class GuiManuscript(QDialog):
|
|||||||
return build
|
return build
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _saveManuscript(self, outFormat: int):
|
|
||||||
"""Save the manuscript file or files."""
|
|
||||||
return
|
|
||||||
|
|
||||||
def _saveSettings(self):
|
def _saveSettings(self):
|
||||||
"""Save the user GUI settings."""
|
"""Save the user GUI settings."""
|
||||||
logger.debug("Saving GuiManuscript settings")
|
logger.debug("Saving GuiManuscript settings")
|
||||||
@@ -591,6 +590,18 @@ class _PreviewWidget(QTextBrowser):
|
|||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
|
# Public Slots
|
||||||
|
##
|
||||||
|
|
||||||
|
@pyqtSlot("QPrinter*")
|
||||||
|
def printPreview(self, printer: QPrinter):
|
||||||
|
"""Connect the print preview painter to the document viewer."""
|
||||||
|
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||||
|
printer.setOrientation(QPrinter.Portrait)
|
||||||
|
self.document().print(printer)
|
||||||
|
qApp.restoreOverrideCursor()
|
||||||
|
return
|
||||||
|
##
|
||||||
# Private Slots
|
# Private Slots
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user