示例#1
0
 def select_printer(self):
     try:
         printer = QtPrintSupport.QPrinter()
         pd = QPrintDialog(printer)
         pd.setOption(QAbstractPrintDialog.PrintSelection)
         pd.exec_()
         return printer.printerName()
     except Exception as e:
         logging.error(str(e))
     return None
示例#2
0
    def print(self):
        printer = QPrinter()
        # Create painter
        painter = QPainter()
        # Start painter
        painter.begin(printer)
        # Grab a widget you want to print
        screen = self.text.grab()
        # Draw grabbed pixmap
        painter.drawPixmap(10, 10, screen)
        # End painting
        painter.end()

        print_dialog = QPrintDialog(printer, self)
        print_dialog.exec_()
示例#3
0
    def printImage(self):  #Ok
        """Imprimir Imagem
        """
        printer = QPrinter()
        printer.setOutputFormat(QPrinter.NativeFormat)

        prnt_dlg = QPrintDialog(printer)

        if (prnt_dlg.exec_() == QPrintDialog.Accepted):

            painter = QPainter()

            painter.begin(printer)

            rect = QRect(painter.viewport())

            size = QSize(self.img_lbl.pixmap().size())
            size.scale(rect.size(), Qt.KeepAspectRatio)

            painter.setViewport(rect.x(), rect.y(), size.width(),
                                size.height())
            painter.setWindow(self.img_lbl.pixmap().rect())

            painter.drawPixmap(0, 0, self.img_lbl.pixmap())

            painter.end()
示例#4
0
def fix_pyside_exec(namespace):
    if namespace.get("__name__") == "AnyQt.QtWidgets":
        from PySide2.QtWidgets import QApplication, QDialog, QMenu
        if "exec" not in QApplication.__dict__:
            QApplication.exec = lambda self: QApplication.exec_()
        if not hasattr(QDialog, "exec"):
            QDialog.exec = lambda self: QDialog.exec_(self)
        if not hasattr(QMenu, "exec"):
            QMenu.exec = lambda self: QMenu.exec_(self)
    if namespace.get("__name__") == "AnyQt.QtGui":
        from PySide2.QtGui import QGuiApplication, QDrag
        if "exec" not in QGuiApplication.__dict__:
            QGuiApplication.exec = lambda self: QGuiApplication.exec_()
        if not hasattr(QDrag, "exec"):
            QDrag.exec = (lambda self, *args, **kwargs: QDrag.exec_(
                self, *args, **kwargs))
    elif namespace.get("__name__") == "AnyQt.QtCore":
        from PySide2.QtCore import QCoreApplication, QEventLoop, QThread
        if not hasattr(QCoreApplication, "exec"):
            QCoreApplication.exec = lambda self: QCoreApplication.exec_()
        if not hasattr(QEventLoop, "exec"):
            QEventLoop.exec = (lambda self, *args, **kwargs: QEventLoop.exec_(
                self, *args, **kwargs))
        if not hasattr(QThread, "exec"):
            QThread.exec = lambda self: QThread.exec_(self)
    elif namespace.get("__name__") == "AnyQt.QtPrintSupport":
        from PySide2.QtPrintSupport import QPageSetupDialog, QPrintDialog
        if "exec" not in QPageSetupDialog.__dict__:
            QPageSetupDialog.exec = lambda self: QPageSetupDialog.exec_(self)
        if "exec" not in QPrintDialog.__dict__:
            QPrintDialog.exec = lambda self: QPrintDialog.exec_(self)
示例#5
0
文件: main.py 项目: KDAB/KDChart
    def slotPrint(self):
        printer = QPrinter(QPrinter.HighResolution)
        pd = QPrintDialog(printer, self)

        if pd.exec_() == QDialog.Accepted:
            r = self.view.graphicsView().mapToScene(
                self.view.graphicsView().viewport().rect()).boundingRect()
            self.view.print(printer, r.left(), r.right())
示例#6
0
    def print_page(self):
        page = self.tabs.currentWidget().page()

        def callback(*args):
            pass

        dlg = QPrintDialog(self.printer)
        dlg.accepted.connect(callback)
        if dlg.exec_() == QDialog.Accepted:
            page.print(self.printer, callback)
示例#7
0
    def print_page(self):
        page = self.browser.page()

        def callback(*args):
            pass

        dlg = QPrintDialog(self.printer)
        dlg.accepted.connect(callback)
        if dlg.exec_() == QDialog.Accepted:
            page.print(self.printer, callback)
示例#8
0
文件: main.py 项目: nwagu/pablo
    def print_(self):
        document = self.paged_text_edit.document()
        printer = QPrinter()

        dlg = QPrintDialog(printer, self)
        if dlg.exec_() != QDialog.Accepted:
            return

        document.print_(printer)

        self.statusBar.writeMessageOnStatus("Ready", 2000)
示例#9
0
    def print_(self):
        document = self.textEdit.document()
        printer = QPrinter()

        dlg = QPrintDialog(printer, self)
        if dlg.exec_() != QDialog.Accepted:
            return

        document.print_(printer)

        self.statusBar().showMessage("Ready", 2000)
示例#10
0
    def print_with_setup(self, text_edit: Union[QTextEdit, MyPlainTextEdit]):
        """
        Get printer settings from the user, then print at High Resolution with those settings or cancel.

        :param text_edit: A text editor containing a `document()` QTextDocument.
        :return: None. Side effect: modal dialog, possibly printing.
        """
        if text_edit == self.md_text_edit:
            self.update_markdown_viewer()
        printer = QPrinter(QPrinter.HighResolution)
        print_dialog = QPrintDialog(printer, self)
        if print_dialog.exec_() == QDialog.Accepted:
            self.print_(printer, text_edit)
示例#11
0
 def print(self):
     printer = QPrinter()
     print_dialog = QPrintDialog(printer, self)
     # Check if the dialog is accepted by the user
     if print_dialog.exec_() == QDialog.Accepted:
         # Create painter
         painter = QPainter()
         # Start painter
         painter.begin(printer)
         # Grab a widget you want to print
         screen = self.text.grab()
         # Draw grabbed pixmap
         painter.drawPixmap(10, 10, screen)
         # End painting
         painter.end()
示例#12
0
    def printImage(self, printer):
        "Prints the current diagram"
        self.image = QImage('test1.tif')

        # # Create the printer
        printerobject = QPrinter()
        # Set the settings
        printdialog = QPrintDialog(printerobject)
        if printdialog.exec_() == QDialog.Accepted:
            painter = QPainter(printer)
            rect = painter.viewport()
            size = self.image.size()
            size.scale(rect.size(), Qt.KeepAspectRatio)
            painter.setViewport(rect.x(), rect.y(), size.width(),
                                size.height())
            painter.setWindow(self.image.rect())
            painter.drawImage(0, 0, self.image)
示例#13
0
    def print_report(self):
        if not self.validate_report_dates():
            return

        entries = self.model.get_records(
            self.view.report_date_from.date().toPython(),
            self.view.report_date_to.date().toPython(),
            self.view.comboBox.currentText(),
        )
        balance = self.model.get_balance(
            self.view.report_date_from.date().toPython(),
            self.view.report_date_to.date().toPython(),
        )
        if not self.create_pdf(self.model.pdf_file.name, entries, balance):
            return

        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer)
        if dialog.exec_() != QPrintDialog.Accepted:
            return

        with TemporaryDirectory() as path:
            images = convert_from_path(self.model.pdf_file.name,
                                       dpi=300,
                                       output_folder=path)
            painter = QPainter()
            painter.begin(printer)
            for i, image in enumerate(images):
                if i > 0:
                    printer.newPage()
                rect = painter.viewport()
                qtImage = ImageQt(image)
                qtImageScaled = qtImage.scaled(rect.size(), Qt.KeepAspectRatio,
                                               Qt.SmoothTransformation)
                painter.drawImage(rect, qtImageScaled)
            painter.end()
    def printDialog(self):
        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer, self)

        if dialog.exec_() == QPrintDialog.Accepted:
            self.textEdit.print_(printer)
示例#15
0
 def handlePrint(self):
     dialog = QPrintDialog()
     if dialog.exec_() == QtGui.QDialog.Accepted:
         self.handlePaintRequest(dialog.printer())
示例#16
0
 def file_print(self):
     dlg = QPrintDialog()
     if dlg.exec_():
         self.editor.print_(dlg.printer())