From: Agnibho Mondal Date: Sat, 9 Sep 2023 16:29:00 +0000 (+0530) Subject: Added Printer Support X-Git-Tag: v0.3~31 X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=8f050a3800f410937fef018015c0be1387dcab6c;p=medscript.git Added Printer Support --- diff --git a/renderbox.py b/renderbox.py index f929b39..d2d136f 100644 --- a/renderbox.py +++ b/renderbox.py @@ -5,22 +5,27 @@ # MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with MedScript. If not, see . -from PyQt6.QtWidgets import QMainWindow, QToolBar, QFileDialog +from PyQt6.QtWidgets import QWidget, QMainWindow, QToolBar, QFileDialog, QComboBox, QSizePolicy from PyQt6.QtWebEngineWidgets import QWebEngineView -from PyQt6.QtGui import QAction, QIcon -from PyQt6.QtCore import QUrl -import os, webbrowser +from PyQt6.QtGui import QAction, QIcon, QPageLayout, QPageSize +from PyQt6.QtCore import QUrl, QMarginsF +from PyQt6.QtPrintSupport import QPrinter, QPrintDialog +import os +from config import config class RenderBox(QMainWindow): file="" - def cmd_browse(self): - webbrowser.open(self.file) + def cmd_pdf(self): + file=QFileDialog.getSaveFileName(self, "Save PDF", os.path.abspath(os.path.join(config["document_directory"], ".pdf")), "PDF (*.pdf);; All Files (*)") + page=QPageSize(QPageSize.PageSizeId[self.input_size.currentText()]) + self.webview.printToPdf(file[0], QPageLayout(page, QPageLayout.Orientation.Portrait, QMarginsF())) def cmd_print(self): - file=QFileDialog.getSaveFileName() - self.webview.printToPdf(file[0]) + dialog=QPrintDialog(self.printer) + if(dialog.exec()): + self.webview.print(self.printer) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -28,13 +33,25 @@ class RenderBox(QMainWindow): self.setWindowTitle("MedScript") self.setGeometry(100, 100, 600, 400) - action_browse=QAction("Open in Browser", self) - action_browse.triggered.connect(self.cmd_browse) - action_print=QAction("Print to PDF", self) + self.printer=QPrinter(QPrinter.PrinterMode.HighResolution) + + action_pdf=QAction("Create PDF", self) + action_pdf.triggered.connect(self.cmd_pdf) + action_print=QAction("Print Document", self) action_print.triggered.connect(self.cmd_print) + page_size=[] + for size in QPageSize.PageSizeId: + page_size.append(size.name) + self.input_size=QComboBox(self) + self.input_size.addItems(page_size) + toolbar=QToolBar("View Toolbar", floatable=False, movable=False) - toolbar.addAction(action_browse) + toolbar.addWidget(self.input_size) + toolbar.addAction(action_pdf) + spacer=QWidget(self) + spacer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) + toolbar.addWidget(spacer) toolbar.addAction(action_print) self.addToolBar(toolbar)