Example #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
Example #2
0
 def doPrint(self):
     printer = QPrinter()
     dlg = QPrintDialog(printer, self)
     dlg.setWindowTitle('Печать документа')
     if dlg.exec() == QPrintDialog.Accepted:
         self.ui.textBrowser.print(printer)
         self.close()
Example #3
0
    def Print(self):
        printer = QPrinter()
        dlg = QPrintDialog(printer, self)
        if dlg.exec() == QDialog.Accepted:
            #Painter 생성
            qp = QPainter()
            qp.begin(printer)

            # 여백 비율
            wgap = printer.pageRect().width() * 0.1
            hgap = printer.pageRect().height() * 0.1

            # 화면 중앙에 위젯 배치
            xscale = (printer.pageRect().width() -
                      wgap) / self.tabs.tab2.text2.width()
            yscale = (printer.pageRect().height() -
                      hgap) / self.tabs.tab2.text2.height()
            scale = xscale if xscale < yscale else yscale
            qp.translate(
                printer.paperRect().x() + printer.pageRect().width() / 2,
                printer.paperRect().y() + printer.pageRect().height() / 2)
            qp.scale(scale, scale)
            qp.translate(-self.tabs.tab2.text2.width() / 2,
                         -self.tabs.tab2.text2.height() / 2)

            # 인쇄
            self.text2.render(qp)

            qp.end()
Example #4
0
    def showprintdialog(self):
        try:
            # 将绘制的目标重新定向到打印机
            print1 = QPrintDialog(self.printer, self.Dialog)
            if QDialog.Accepted == print1.exec():
                painter = QtGui.QPainter()
                # 将绘制的目标重新定向到打印机
                painter.begin(self.printer)
                self.Dialog.resize(self.Dialog.geometry().width(),
                                   self.Dialog.geometry().height())

                self.label.setText("维保方式")

                self.conserveButton.setVisible(False)
                self.cancelButton.setVisible(False)
                screen = self.Dialog.grab()
                painter.drawPixmap(0, 0,
                                   self.Dialog.geometry().width(),
                                   self.Dialog.geometry().height(), screen)
                # painter.end()
                #print("print")
                self.conserveButton.setVisible(False)
                self.cancelButton.setVisible(False)

                self.label.setText("打印维保方式")
                self.Dialog.close()

        # painter.drawPixmap(100,100, )
        except Exception as e:
            print(e)
Example #5
0
 def printer(self):
     prnt_dialog = QPrintDialog(self)
     if not prnt_dialog.exec():
         prnt_dialog.deleteLater()
         return
     self.page().print(prnt_dialog.printer(),
                       lambda status: prnt_dialog.deleteLater())
Example #6
0
	def printFile(self):
		self.currentTab.updatePreviewBox()
		printer = self.standardPrinter()
		dlg = QPrintDialog(printer, self)
		dlg.setWindowTitle(self.tr("Print document"))
		if (dlg.exec() == QDialog.Accepted):
			document = self.getDocumentForPrint()
			if document != None:
				document.print(printer)
Example #7
0
	def printFile(self):
		self.updatePreviewBox()
		printer = self.standardPrinter()
		dlg = QPrintDialog(printer, self)
		dlg.setWindowTitle(self.tr("Print document"))
		if (dlg.exec() == QDialog.Accepted):
			document = self.getDocumentForPrint()
			if document != None:
				document.print(printer)
Example #8
0
	def printFile(self):
		title, htmltext, preview = self.currentTab.getDocumentForExport()
		printer = self.standardPrinter(title)
		dlg = QPrintDialog(printer, self)
		dlg.setWindowTitle(self.tr("Print document"))
		if (dlg.exec() == QDialog.Accepted):
			document = self.getDocumentForPrint(title, htmltext, preview)
			if document != None:
				document.print(printer)
Example #9
0
	def printFile(self):
		title, htmltext, preview = self.currentTab.getDocumentForExport(includeStyleSheet=True,
										webenv=False)
		printer = self.standardPrinter(title)
		dlg = QPrintDialog(printer, self)
		dlg.setWindowTitle(self.tr("Print document"))
		if (dlg.exec() == QDialog.Accepted):
			document = self.getDocumentForPrint(title, htmltext, preview)
			if document != None:
				document.print(printer)
Example #10
0
    def generate_finish_report(self):
        """Generate finish report, using the information from the dialog's input widgets."""
        document = generate_finish_report(self.modeldb,
                                          self.field_combobox.currentText())

        printer = QPrinter()

        print_dialog = QPrintDialog(printer, self)
        if print_dialog.exec() == QDialog.Accepted:
            document.print(printer)
Example #11
0
 def print(self):
     dialog = QPrintDialog(self.printer, self)
     if dialog.exec():
         painter = QPainter(self.printer)
         rect = painter.viewport()
         size = self.wid.image_frame.pixmap().size()
         size.scale(rect.size(), Qt.KeepAspectRatio)
         painter.setViewport(rect.x(), rect.y(), size.width(),
                             size.height())
         painter.setWindow(self.wid.image_frame.pixmap().rect())
         painter.drawPixmap(0, 0, self.wid.image_frame.pixmap())
Example #12
0
 def slotPrint(self):
     printer = QPrinter()
     printDialog = QPrintDialog(printer, self)
     if printDialog.exec():
         painter = QPrinter(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)
Example #13
0
    def printing(self):
        """
        Docstring.
        """
        document = self.gamePane.document()
        printer = QPrinter()

        dialog = QPrintDialog(printer, self)
        if dialog.exec() != QDialog.Accepted:
            return

        document.print(printer)

        self.statusBar().showMessage("Ready.", 2000)
Example #14
0
    def slotPrint(self):
        import cups
        import subprocess
        from PyQt5.QtPrintSupport import QPrintDialog
        from PyQt5.QtPrintSupport import QPrinter
        from PyQt5 import QtGui
        croppedFilename = "%s-cropped.pdf" % splitext(
            str_unicode(self.fileName))[0]
        # printerCon = cups.Connection()

        printer = QPrinter()
        printDlg = QPrintDialog(printer)
        if printDlg.exec() == QDialog.Accepted:
            printerName = printer.printerName()
            cmdLine = ['lp', '-d', printerName]
            cmdLine += ['-n', str(printer.copyCount())]
            cmdLine += ['-o', 'fit-to-page'
                        ]  # We want to print out the cropped PDF anyway.
            # Handle duplex
            if printer.duplex() == QPrinter.DuplexNone:
                cmdLine += ['-o', 'Duplex=None']
            if printer.duplex() == QPrinter.DuplexLongSide:
                cmdLine += ['-o', 'Duplex=DuplexNoTumble']
            if printer.duplex() == QPrinter.DuplexShortSide:
                cmdLine += ['-o', 'Duplex=DuplexTumble']
            # Orientation
            if printer.pageLayout().orientation() == QPageLayout.Landscape:
                cmdLine += ['-o', 'landscape']
            # Color mode
            if printer.colorMode() == QPrinter.GrayScale:
                cmdLine += ['-o', 'ColorMode=Grayscale']
            if printer.colorMode() == QPrinter.Color:
                cmdLine += ['-o', 'ColorMode=Color']
            # Page size
            pagesizeid_to_pagesize = {}
            for prop_name in QPageSize.__dict__.keys():
                if type(QPageSize.__dict__[prop_name]) == type(
                        QPageSize.PageSizeId()):
                    pagesizeid_to_pagesize[
                        QPageSize.__dict__[prop_name]] = prop_name
            cmdLine += [
                '-o', 'media=' +
                pagesizeid_to_pagesize[printer.pageLayout().pageSize().id()]
            ]

            cmdLine.append(croppedFilename)
            # printersLst = printerCon.getPrinters()
            # printer = QInputDialog.getItem(self, "Please select printer", "", list(printersLst.keys()))
            print('Print command line: ' + ' '.join(cmdLine))
            subprocess.check_call(cmdLine)
Example #15
0
def printCodes():
    #action which is triggered when the user selects 'Print' menu item
    if mw == None:
        raise Exception('Mainwindow is not initialized')
    else:
        print('printing...')

    printer = QPrinter()
    dlg = QPrintDialog(printer)
    if dlg.exec() == QDialog.Accepted:
        painter = QPainter()
        painter.begin(printer)
        drawLabels(painter, mw.labels, printer)
        painter.end()
Example #16
0
    def show_dialog(self) -> None:
        """Print with a QPrintDialog."""
        def print_callback(ok: bool) -> None:
            """Called when printing finished."""
            if not ok:
                message.error("Printing failed!")
            diag.deleteLater()

        def do_print() -> None:
            """Called when the dialog was closed."""
            self.to_printer(diag.printer(), print_callback)

        diag = QPrintDialog(self._tab)
        if utils.is_mac:
            # For some reason we get a segfault when using open() on macOS
            ret = diag.exec()
            if ret == QDialog.Accepted:
                do_print()
        else:
            diag.open(do_print)
Example #17
0
 def print(self):
     """
     Opens an printing dialog
     """
     self.mouse()
     printer = QPrinter(QPrinter.HighResolution)
     printer.setPageSize(QPrinter.A4)
     printer.setOrientation(QPrinter.Portrait)
     self.scene.clearSelection()
     printDialog = QPrintDialog(printer, self)
     if printDialog.exec() == QDialog.Accepted:
         try:
             p = QPainter()
             if p.begin(printer) is False:
                 raise Exception('Error starting painter')
             self.scene.setSceneRect(self.scene.itemsBoundingRect())
             self.scene.render(p)
             p.end()
             self.scene.setSceneRect(QRectF(None))
         except Exception as e:
             MessageBox('Error while printing', e)
def html_to_image(StrPrintHtml="", printer_name="", widthPage=300, heightPage=100, leftPage=-15, topPage=-15 ):
    """
    Функция вывода текста на принтер
    :param StrPrintHtml: - Текст HTML
    :param printer_name: - имя принтера
    :return:
    """
    requestMessage = {}
    try:
        app = QApplication(['mainApp'])
        printer = QPrinter()
        requestMessage = {}
        label = QLabel()
        # '<img width="300"  height="100"  alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALQAAAB2CAIAAADujy7aAAABuUlEQVR42u3YwY7CIBRAUZj4/7/MLEgIFlqf1YwOPWdlsKlVrlDNqVNKSSnlnNvjqo6MR47PjuP9OSNniJw/foWRa4tc7d45n32tyDvtRyLjkWuIfErjGX4S7BAH4kAciANxIA7EgTgQB+JAHCAOxIE4EAfiQByIA3EgDsQB4kAciANxIA7EgTgQB+JAHCAOxIE4EAfiQByIA3EgDsSBOEAciANxIA7EgTgQB+JAHIgDxIE4EAfiQByIA3EgDsSBOEAciANxIA7EgTgQB+JAHIgDcYA4EAfiQByIA3EgDsSBOBAHiANxIA7EgTgQB+JAHIgDcYA4EAfiQByIg0/LpRSfAlYOxMGb3FbbJvPdRplzbo/b+CuD/Ugbnw6K4+vKOA6lTuQrg5tZr684HbStfO+a8alX/PvLEMdjwSmZHtZvDW12T8zxSmVc6IZ0utT3c1n72JvdcXw6stKesuAN6d56ML1tnE726W9/fxvrhvR/7zX9FI5LyHgruvD2ccVt5WCpiM9u5MiVtpKL3nOcWPaX/z3y4O0v8z43X9/Nf1bT/7WmR6bD/7sOinn2d5M4sK0gDsQB4uDQLyTS/Ojjiz5LAAAAAElFTkSuQmCC" />'
        label.setText(StrPrintHtml)
        label.resize(int(widthPage), int(heightPage))
        printer = QPrinter()
        if printer_name == "":
            print_dialog = QPrintDialog(printer)
            if print_dialog.exec() != QDialog.Accepted:
                requestMessage["Error"] = "Printer no select"
                return requestMessage
            printer_name = print_dialog.printer().printerName()
            # printer_name = GetDefaultPrinter()
        printer.setPrinterName(printer_name)
        # printer.setPrinterName("Brother QL-810W")
        printer.setPageMargins(0, 0, 0, 0, QPrinter.DevicePixel)
        # printer.setOutputFileName("C:\\AppServ\\www\\QtPrint\\PrinterFileName.pdf")
        painter = QPainter()
        painter.begin(printer)
        painter.drawPixmap(int(leftPage),int(topPage), label.grab())
        painter.end()
    except Exception:
        requestMessage["Error"] = "%s" % (format_exc())
        return requestMessage
    return requestMessage
Example #19
0
    def printDialog(self):
        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer, self)

        if dialog.exec() == QPrintDialog.Accepted:
            self.TextEdit.print_(printer)
Example #20
0
 def showPrintDialog(self):  # 显示打印对话框
     printdialog = QPrintDialog(self.printer, self)  # 创建打印对话框
     if QDialog.Accepted == printdialog.exec():
         self.editor.print(self.printer)
Example #21
0
 def print_file(self):
     # Диалоговое окно выбора принтера и согласия печатания
     ask_printer = QPrintDialog()
     if ask_printer.exec():
         self.text_editor.print(ask_printer.printer())
Example #22
0
 def print(self, document: QTextDocument):
     dialog = QPrintDialog(self.printer, None)
     if dialog.exec() == QDialog.Rejected:
         pass
     else:
         InsurancePolicyAdapter.print(document, self.printer)
Example #23
0
 def showPrintDialog(self):
     printDailog = QPrintDialog(self.printer, self)
     if QDialog.Accepted == printDailog.exec():
         self.editor.print(self.printer)
Example #24
0
    def printfile(self):
        printer = QPrinter(QPrinter.HighResolution)
        dialog = QPrintDialog(printer, self)

        if dialog.exec() == QPrintDialog.Accepted():
            self.textEdit.print(printer)