def print_(self): printer = QPrinter() dlg = QPrintDialog(printer, self) dlg.setWindowTitle(app.caption(_("Print"))) options = (QAbstractPrintDialog.PrintToFile | QAbstractPrintDialog.PrintShowPageSize | QAbstractPrintDialog.PrintPageRange) if self.browser.textCursor().hasSelection(): options |= QAbstractPrintDialog.PrintSelection dlg.setOptions(options) if dlg.exec_(): self.browser.print_(printer)
def printBrowser(self, browser=None): """ Public slot called to print the displayed page. @param browser reference to the browser to be printed (WebBrowserView) """ if browser is None: browser = self.currentBrowser() printer = QPrinter(mode=QPrinter.HighResolution) if Preferences.getPrinter("ColorMode"): printer.setColorMode(QPrinter.Color) else: printer.setColorMode(QPrinter.GrayScale) if Preferences.getPrinter("FirstPageFirst"): printer.setPageOrder(QPrinter.FirstPageFirst) else: printer.setPageOrder(QPrinter.LastPageFirst) printer.setPageMargins( Preferences.getPrinter("LeftMargin") * 10, Preferences.getPrinter("TopMargin") * 10, Preferences.getPrinter("RightMargin") * 10, Preferences.getPrinter("BottomMargin") * 10, QPrinter.Millimeter) printerName = Preferences.getPrinter("PrinterName") if printerName: printer.setPrinterName(printerName) printer.setResolution(Preferences.getPrinter("Resolution")) documentName = WebBrowserTools.getFileNameFromUrl(browser.url()) printer.setDocName(documentName) printDialog = QPrintDialog(printer, self) printDialog.setOptions(QAbstractPrintDialog.PrintToFile | QAbstractPrintDialog.PrintShowPageSize) if not Globals.isWindowsPlatform(): if isCupsAvailable(): printDialog.setOption(QAbstractPrintDialog.PrintCollateCopies) printDialog.setOption(QAbstractPrintDialog.PrintPageRange) if printDialog.exec_() == QDialog.Accepted: browser.page().execPrintPage(printer, 10 * 1000)
def printSource(self): cursor = self.textCursor() try: printer = self._sourcePrinter except AttributeError: printer = self._sourcePrinter = QPrinter() else: printer.setCopyCount(1) dlg = QPrintDialog(printer, self) dlg.setWindowTitle(app.caption(_("dialog title", "Print Source"))) options = QAbstractPrintDialog.PrintToFile | QAbstractPrintDialog.PrintShowPageSize if cursor.hasSelection(): options |= QAbstractPrintDialog.PrintSelection dlg.setOptions(options) if dlg.exec_(): if dlg.printRange() != QAbstractPrintDialog.Selection: cursor.clearSelection() number_lines = QSettings().value("source_export/number_lines", False, bool) doc = highlighter.html_copy(cursor, 'printer', number_lines) doc.setMetaInformation(QTextDocument.DocumentTitle, self.currentDocument().url().toString()) font = doc.defaultFont() font.setPointSizeF(font.pointSizeF() * 0.8) doc.setDefaultFont(font) doc.print_(printer)
def printSource(self): cursor = self.textCursor() try: printer = self._sourcePrinter except AttributeError: printer = self._sourcePrinter = QPrinter() else: printer.setCopyCount(1) dlg = QPrintDialog(printer, self) dlg.setWindowTitle(app.caption(_("dialog title", "Print Source"))) options = QAbstractPrintDialog.PrintToFile | QAbstractPrintDialog.PrintShowPageSize if cursor.hasSelection(): options |= QAbstractPrintDialog.PrintSelection dlg.setOptions(options) if dlg.exec_(): if dlg.printRange() != QAbstractPrintDialog.Selection: cursor.clearSelection() number_lines = QSettings().value("source_export/number_lines", False, bool) doc = highlighter.html_copy(cursor, 'printer', number_lines) doc.setMetaInformation(QTextDocument.DocumentTitle, self.currentDocument().url().toString()) font = doc.defaultFont() font.setPointSizeF(font.pointSizeF() * 0.8) doc.setDefaultFont(font) doc.print_(printer)