Example #1
0
 def _print_report(self):
     printer = QPrinter()
     print_dialog = QPrintDialog(printer, self)
     print_dialog.setWindowTitle("Print report")
     if print_dialog.exec_() != QDialog.Accepted:
         return
     self.report_view.print_(printer)
Example #2
0
 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)
Example #3
0
 def _print_report(self):
     printer = QPrinter()
     print_dialog = QPrintDialog(printer, self)
     print_dialog.setWindowTitle("Print report")
     if print_dialog.exec_() != QDialog.Accepted:
         return
     self.report_view.print_(printer)
 def printContents(self, printer=None):
     if not printer:
         printer = QPrinter()
     dialog = QPrintDialog(printer, self)
     dialog.setWindowTitle(QCoreApplication.translate("QPyShell", "Print Document"))
     if dialog.exec_() != QDialog.Accepted:
         return
     self.outputBrowser.document().print_(printer)
Example #5
0
 def printWindow(self, printer=None):
     if not printer:
         printer = QPrinter()
     dialog = QPrintDialog(printer, self)
     dialog.setWindowTitle(QCoreApplication.translate('LogWindow', 'Print Document'))
     if dialog.exec_() != QDialog.Accepted:
         return
     self.logView.TextArea.document().print_(printer)
Example #6
0
 def print_on_paper(self):
     """Print the document with a printer."""
     
     printer = Qsci.QsciPrinter()
     print_dialog = QPrintDialog(printer)
     print_dialog.setWindowTitle(self.tr("Print Document"))
     print_dialog.addEnabledOption(QPrintDialog.PrintSelection)
     if print_dialog.exec_() == QPrintDialog.Accepted:
         printer.printRange(self)
 def printWindow(self, printer=None):
     if not printer:
         printer = QPrinter()
     printer.setFullPage(True)
     printer.setPageSize(QPrinter.A4)
     dialog = QPrintDialog(printer, self)
     dialog.setWindowTitle(QCoreApplication.translate('QwtPlot', 'Print Document'))
     if dialog.exec_() != QDialog.Accepted:
         return
     self.plot.print_(printer, QwtPlotPrintFilter())
Example #8
0
 def print_webpage(self):
     """
     Callback for the print action.  Should show a print dialog and print the webpage to the printer.
     """
     printer = QPrinter()
     print_dialog = QPrintDialog(printer, self)
     print_dialog.setWindowTitle("Print Page")
     if print_dialog.exec_() == QDialog.Accepted:
         self.print_(printer)
     else:
         return False
Example #9
0
 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)
Example #10
0
 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 printWindow(self, printer=None):
     if not printer:
         printer = QPrinter()
     printer.setFullPage(True)
     printer.setPageSize(QPrinter.A4)
     dialog = QPrintDialog(printer, self)
     dialog.setWindowTitle(QCoreApplication.translate('Graphics', 'Print Document'))
     if dialog.exec_() != QDialog.Accepted:
         return
     # FIXME: on windows the resolutions seems to be very low, why?
     #printer.setResolution(600)
     painter = QPainter(printer)
     painter.setRenderHint(QPainter.Antialiasing)
     self.graphicsView.scene().render(painter)
    def savePrinter(self):
        """
        Save to printer
        """
        printer = QPrinter()
        dialog = QPrintDialog(printer, self)
        dialog.setWindowTitle("Print")

        if dialog.exec_() != QDialog.Accepted:
            return

        doc = QTextDocument()
        doc.setPlainText(self.txtEdit.text())
        doc.print_(printer)
Example #13
0
    def printdoc(self):
        """
        Prints the document in the view
        """
        printer = QPrinter()

        setup = QPageSetupDialog(printer)
        setup.setWindowTitle("Print - Page Settings")

        if setup.exec_() == QDialog.Accepted:
            dialog = QPrintDialog(printer, self)
            dialog.setWindowTitle("Print Document")

            if dialog.exec_() == QDialog.Accepted:
                self.ui.webviewResult.print_(printer)
    def savePrinter(self):
        """
        Save to printer
        """
        printer = QPrinter()
        dialog = QPrintDialog(printer, self)
        dialog.setWindowTitle("Print")

        if dialog.exec_() != QDialog.Accepted:
            return

        if QtHelper.IS_QT5:  # new in v18
            self.fileName = printer
            self.txtEdit.page().toHtml(self.__toPrinter)
        else:
            self.txtEdit.print_(printer)
    def savePrinter(self):
        """
        Save to printer
        """
        printer = QPrinter()
        dialog = QPrintDialog(printer, self)
        dialog.setWindowTitle("Print")

        if dialog.exec_() != QDialog.Accepted:
            return

        if QtHelper.IS_QT5: # new in v18
            self.fileName = printer
            self.txtEdit.page().toHtml(self.__toPrinter)
        else:
            frame = self.txtEdit.page().mainFrame()
        
            doc = QTextDocument()
            doc.setPlainText( frame.toPlainText() )
            doc.print_(printer)
Example #16
0
 def Printout(self):
     # Version utilisant QSvg
     # Fixme: l'alpha n'est pas bien rendu
     # (le fond des polygones est absent)
     # Le fond est bien présent après export avec matplotlib pourtant.
     printer = QPrinter(QPrinter.HighResolution)
     dialog = QPrintDialog(printer, self)
     dialog.setOption(QPrintDialog.PrintPageRange, False)
     dialog.setOption(QPrintDialog.PrintToFile, True)
     dialog.setOption(QPrintDialog.PrintShowPageSize, True)
     dialog.setWindowTitle("Imprimer le document")
     if (dialog.exec_() == QDialog.Accepted):
         painter = QPainter(printer)
         try:
             output = StringIO()
             self.onglet_actuel.canvas.exporter(output, format='svg')
             svg = QSvgRenderer(QByteArray(output.getvalue()), self)
             size = svg.defaultSize()
             size.scale(painter.viewport().size(), Qt.KeepAspectRatio)
             rect = QRectF(0, 0, size.width(), size.height())
             svg.render(painter, rect)
         finally:
             painter.end()
Example #17
0
 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)
Example #18
0
 def slotPrint(self):
     printer = QPrinter()
     dlg = QPrintDialog(printer, self)
     dlg.setWindowTitle(app.caption(_("Print")))
     if dlg.exec_():
         self.webview.print_(printer)
Example #19
0
 def slotPrint(self):
     printer = QPrinter()
     dlg = QPrintDialog(printer, self)
     dlg.setWindowTitle(app.caption(_("Print")))
     if dlg.exec_():
         self.webview.print_(printer)
Example #20
0
def print_(doc, filename=None, widget=None):
    """Prints the popplerqt4.Poppler.Document.
    
    The filename is used in the dialog and print job name.
    If the filename is not given, it defaults to a translation of "PDF Document".
    The widget is a widget to use as parent for the print dialog etc.
    
    """
    # Decide how we will print.
    # on Windows and Mac OS X a print command must be specified, otherwise
    # we'll use raster printing
    s = QSettings()
    s.beginGroup("helper_applications")
    cmd = s.value("printcommand", "", type(""))
    use_dialog = s.value("printcommand/dialog", False, bool)
    resolution = s.value("printcommand/dpi", 300, int)
    linux_lpr = False
    
    if os.name != 'nt' and not sys.platform.startswith('darwin'):
        # we're probably on Linux
        if not cmd:
            cmd = fileprinter.lprCommand()
            if cmd:
                linux_lpr = True
        elif cmd.split('/')[-1] in fileprinter.lpr_commands:
            linux_lpr = True

    print_file = filename
    title = os.path.basename(filename) if filename else _("PDF Document")
    printer = QPrinter()
    printer.setDocName(title)
    printer.setPrintRange(QPrinter.AllPages)
    
    if linux_lpr or use_dialog or not cmd:
        dlg = QPrintDialog(printer, widget)
        dlg.setMinMax(1, doc.numPages())
        dlg.setOption(QPrintDialog.PrintToFile, False)
        dlg.setWindowTitle(app.caption(_("Print {filename}").format(filename=title)))
        
        result = dlg.exec_()
        if widget:
            dlg.deleteLater() # because it has a parent
        if not result:
            return # cancelled
    
    if linux_lpr or '$ps' in cmd:
        # make a PostScript file with the desired paper size
        ps = QTemporaryFile()
        if ps.open() and qpopplerview.printer.psfile(doc, printer, ps):
            ps.close()
            print_file = ps.fileName()
    elif cmd:
        if printer.printRange() != QPrinter.AllPages:
            cmd = None # we can't cut out pages from a PDF file
        elif '$pdf' not in cmd:
            cmd += ' $pdf'
    
    command = []
    if linux_lpr:
        # let all converted pages print
        printer.setPrintRange(QPrinter.AllPages)
        command = fileprinter.printCommand(cmd, printer, ps.fileName())
    elif cmd and print_file:
        for arg in helpers.shell_split(cmd):
            if arg in ('$ps', '$pdf'):
                command.append(print_file)
            else:
                arg = arg.replace('$printer', printer.printerName())
                command.append(arg)
    if command:
        if subprocess.call(command):
            QMessageBox.warning(widget, _("Printing Error"),
                _("Could not send the document to the printer."))
        return
    else:
        # Fall back printing of rendered raster images.
        # It is unsure if the Poppler ArthurBackend ever will be ready for
        # good rendering directly to a painter, so we'll fall back to using
        # raster images.
        
        p = Printer()
        p.setDocument(doc)
        p.setPrinter(printer)
        p.setResolution(resolution)
        
        d = QProgressDialog()
        d.setModal(True)
        d.setMinimumDuration(0)
        d.setRange(0, len(p.pageList()) + 1)
        d.canceled.connect(p.abort)
        
        def progress(num, total, page):
            d.setValue(num)
            d.setLabelText(_("Printing page {page} ({num} of {total})...").format(
                page=page, num=num, total=total))
                
        def finished():
            p.deleteLater()
            d.deleteLater()
            d.hide()
            if not p.success and not p.aborted():
                QMessageBox.warning(widget, _("Printing Error"),
                    _("Could not send the document to the printer."))
            
        p.finished.connect(finished)
        p.printing.connect(progress)
        p.start()
Example #21
0
def print_(doc, filename=None, widget=None):
    """Prints the popplerqt4.Poppler.Document.
    
    The filename is used in the dialog and print job name.
    If the filename is not given, it defaults to a translation of "PDF Document".
    The widget is a widget to use as parent for the print dialog etc.
    
    """
    cmd = fileprinter.lprCommand()
    if not cmd and QMessageBox.information(widget, _("Warning"), _(
        "No print command to print a PostScript file could be found.\n\n"
        "Therefore the document will be printed using raster images at {resolution} DPI. "
        "It is recommended to print using a dedicated PDF viewer.\n\n"
        "Do you want to continue?").format(resolution=300),
        QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
        return # cancelled
        
    filename = os.path.basename(filename) if filename else _("PDF Document")
    
    printer = QPrinter()
    printer.setDocName(filename)
    
    dlg = QPrintDialog(printer, widget)
    dlg.setMinMax(1, doc.numPages())
    dlg.setOption(QPrintDialog.PrintToFile, False)
    dlg.setWindowTitle(app.caption(_("Print {filename}").format(filename=filename)))
    
    result = dlg.exec_()
    if widget:
        dlg.deleteLater() # because it has a parent
    if not result:
        return # cancelled
    
    if cmd:
        # make a PostScript file with the desired paper size
        ps = QTemporaryFile()
        if ps.open() and qpopplerview.printer.psfile(doc, printer, ps):
            ps.close()
            # let all converted pages print
            printer.setPrintRange(QPrinter.AllPages)
            command = fileprinter.printCommand(cmd, printer, ps.fileName())
            if not subprocess.call(command):
                return # success!
        QMessageBox.warning(widget, _("Printing Error"),
            _("Could not send the document to the printer."))
    else:
        # Fall back printing of rendered raster images.
        # It is unsure if the Poppler ArthurBackend ever will be ready for
        # good rendering directly to a painter, so we'll fall back to using
        # 300DPI raster images.
        
        p = Printer()
        p.setDocument(doc)
        p.setPrinter(printer)
        p.setResolution(300)
        
        d = QProgressDialog()
        d.setModal(True)
        d.setMinimumDuration(0)
        d.setRange(0, len(p.pageList()) + 1)
        d.canceled.connect(p.abort)
        
        def progress(num, total, page):
            d.setValue(num)
            d.setLabelText(_("Printing page {page} ({num} of {total})...").format(
                page=page, num=num, total=total))
                
        def finished():
            p.deleteLater()
            d.deleteLater()
            d.hide()
            if not p.success and not p.aborted():
                QMessageBox.warning(widget, _("Printing Error"),
                    _("Could not send the document to the printer."))
            
        p.finished.connect(finished)
        p.printing.connect(progress)
        p.start()
Example #22
0
def print_(doc, filename=None, widget=None):
    """Prints the popplerqt4.Poppler.Document.
    
    The filename is used in the dialog and print job name.
    If the filename is not given, it defaults to a translation of "PDF Document".
    The widget is a widget to use as parent for the print dialog etc.
    
    """
    # Decide how we will print.
    # on Windows and Mac OS X a print command must be specified, otherwise
    # we'll use raster printing
    s = QSettings()
    s.beginGroup("helper_applications")
    cmd = s.value("printcommand", "", type(""))
    use_dialog = s.value("printcommand/dialog", False, bool)
    resolution = s.value("printcommand/dpi", 300, int)
    linux_lpr = False

    if os.name != 'nt' and not sys.platform.startswith('darwin'):
        # we're probably on Linux
        if not cmd:
            cmd = fileprinter.lprCommand()
            if cmd:
                linux_lpr = True
        elif cmd.split('/')[-1] in fileprinter.lpr_commands:
            linux_lpr = True

    print_file = filename
    title = os.path.basename(filename) if filename else _("PDF Document")
    printer = QPrinter()
    printer.setDocName(title)
    printer.setPrintRange(QPrinter.AllPages)

    if linux_lpr or use_dialog or not cmd:
        dlg = QPrintDialog(printer, widget)
        dlg.setMinMax(1, doc.numPages())
        dlg.setOption(QPrintDialog.PrintToFile, False)
        dlg.setWindowTitle(
            app.caption(_("Print {filename}").format(filename=title)))

        result = dlg.exec_()
        if widget:
            dlg.deleteLater()  # because it has a parent
        if not result:
            return  # cancelled

    if linux_lpr or '$ps' in cmd:
        # make a PostScript file with the desired paper size
        ps = QTemporaryFile()
        if ps.open() and qpopplerview.printer.psfile(doc, printer, ps):
            ps.close()
            print_file = ps.fileName()
    elif cmd:
        if printer.printRange() != QPrinter.AllPages:
            cmd = None  # we can't cut out pages from a PDF file
        elif '$pdf' not in cmd:
            cmd += ' $pdf'

    command = []
    if linux_lpr:
        # let all converted pages print
        printer.setPrintRange(QPrinter.AllPages)
        command = fileprinter.printCommand(cmd, printer, ps.fileName())
    elif cmd and print_file:
        for arg in helpers.shell_split(cmd):
            if arg in ('$ps', '$pdf'):
                command.append(print_file)
            else:
                arg = arg.replace('$printer', printer.printerName())
                command.append(arg)
    if command:
        if subprocess.call(command):
            QMessageBox.warning(
                widget, _("Printing Error"),
                _("Could not send the document to the printer."))
        return
    else:
        # Fall back printing of rendered raster images.
        # It is unsure if the Poppler ArthurBackend ever will be ready for
        # good rendering directly to a painter, so we'll fall back to using
        # raster images.

        p = Printer()
        p.setDocument(doc)
        p.setPrinter(printer)
        p.setResolution(resolution)

        d = QProgressDialog()
        d.setModal(True)
        d.setMinimumDuration(0)
        d.setRange(0, len(p.pageList()) + 1)
        d.canceled.connect(p.abort)

        def progress(num, total, page):
            d.setValue(num)
            d.setLabelText(
                _("Printing page {page} ({num} of {total})...").format(
                    page=page, num=num, total=total))

        def finished():
            p.deleteLater()
            d.deleteLater()
            d.hide()
            if not p.success and not p.aborted():
                QMessageBox.warning(
                    widget, _("Printing Error"),
                    _("Could not send the document to the printer."))

        p.finished.connect(finished)
        p.printing.connect(progress)
        p.start()