def _action(): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QDialog.Accepted: self.textArea.document().print_(dialog.printer())
def pdfYazdirEkrani(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QtWidgets.QDialog.Accepted: self.pdfYazdirmaIslemi(dialog.printer())
def on_selectPrinterButton_clicked(self): dialog = QtPrintSupport.QPrintDialog(self.printer) dialog.setWindowTitle(self.tr("Printer Selection")) if dialog.exec_() == QtWidgets.QDialog.Accepted: self.printer = dialog.printer() self.ui.printerName.setText(self.printer.printerName())
def print_dialog(self): self._print_document() dialog = qtps.QPrintDialog(self.printer, self) dialog.exec() self._update_preview_size()
def print_file(self): print_dialog = QtPrintSupport.QPrintDialog() if print_dialog.exec_() == QtWidgets.QDialog.Accepted: self.active_tab.editor_pane.document().print_( print_dialog.printer())
def __init__(self): """MainWindow constructor""" super().__init__() # Main UI code goes here main = qtw.QWidget() main.setLayout(qtw.QHBoxLayout()) self.setCentralWidget(main) form = InvoiceForm() main.layout().addWidget(form) self.preview = InvoiceView() main.layout().addWidget(self.preview) form.submitted.connect(self.preview.build_invoice) print_tb = self.addToolBar('Printing') print_tb.addAction('Configure Printer', self.printer_config) print_tb.addAction('Print Preview', self.print_preview) print_tb.addAction('Print dialog', self.print_dialog) print_tb.addAction('Export PDF', self.export_pdf) self.printer = qtps.QPrinter() self.printer.setOrientation(qtps.QPrinter.Portrait) self.printer.setPageSize(qtg.QPageSize(qtg.QPageSize.Letter) # End main UI code self.show() def printer_config(self): dialog = qtps.QPageSetupDialog(self.printer, self) dialog.exec() self._update_preview_size() def _update_preview_size(self): self.preview.set_page_size(self.printer.pageRect(qtps.QPrinter.Point)) def _print_document(self): self.preview.document().print(self.printer) def print_dialog(self): self._print_document() dialog = qtps.QPrintDialog(self.printer, self) dialog.exec() self._update_preview_size() def print_preview(self): dialog = qtps.QPrintPreviewDialog(self.printer, self) dialog.paintRequested.connect(self._print_document) dialog.exec() self._update_preview_size() def export_pdf(self): filename, _ = qtw.QFileDialog.getSaveFileName(self, "Save to PDF", qtc.QDir.homePath(), "PDF Files (*.pdf)") if filename: self.printer.setOutputFileName(filename) self.printer.setOutputFormat(qtps.QPrinter.PdfFormat) self._print_document() if __name__ == '__main__': app = qtw.QApplication(sys.argv) mw = MainWindow() sys.exit(app.exec())
def printFun(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QDialog.Accepted: self.mainDesign.document(), print_(dialog.printer())
def printer(self): self.print_dialog = QtPrintSupport.QPrintDialog() if self.print_dialog.exec_() == QtWidgets.QDialog.Accepted: self.preview.webView.print_(self.print_dialog.printer()) self.preview.close()
def PrintR(self): pri = QtPrintSupport.QPrinter() dia = QtPrintSupport.QPrintDialog(pri) dia.exec() self.report.print_(pri)
def print_(self): dialog = QtPrintSupport.QPrintDialog(self.printer, self.parent) if not dialog.exec_(): return self.pdfprinter.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat) self.pdfprinter.setOutputFileName(localsettings.TEMP_PDF) for printer in (self.printer, self.pdfprinter): LeftMargin = 50 TopMargin = 150 serifFont = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(serifFont) serifLineHeight = fm.height() painter = QtGui.QPainter(printer) pageRect = printer.pageRect() painter.setPen(QtCore.Qt.black) painter.setFont(serifFont) center = QtGui.QTextOption(QtCore.Qt.AlignCenter) alignRight = QtGui.QTextOption(QtCore.Qt.AlignRight) if self.isDuplicate: painter.drawText( QtCore.QRectF(0, 100, pageRect.width(), serifLineHeight), _("DUPLICATE RECEIPT"), center) x, y = LeftMargin, TopMargin + 30 painter.drawText( x, y, "%s %s %s" % (self.title.title(), self.fname.title(), self.sname.title())) y += serifLineHeight for line in (self.addr1, self.addr2, self.addr3, self.town, self.county): if line != "": painter.drawText(x, y, str(line).title() + ",") y += serifLineHeight if self.pcde != "": painter.drawText(x, y, str(self.pcde + ".")) # postcode x, y = LeftMargin + 50, TopMargin + serifLineHeight * 10 mystr = 'Received on ' w = fm.width(mystr) painter.drawText(x, y, mystr) if not self.isDuplicate: painter.drawText( x + w, y, QtCore.QDate.currentDate().toString( localsettings.QDATE_FORMAT)) else: painter.drawText( x + w, y, self.dupdate.toString(localsettings.QDATE_FORMAT)) y += serifLineHeight * 2 painter.drawText(x, y, _('relating to:-')) y += serifLineHeight for key in list(self.receivedDict.keys()): amount = self.receivedDict[key] if float(amount) != 0: rect_f = QtCore.QRectF(x, y, 180, serifLineHeight) painter.drawText(rect_f, str(key)) rect_f = QtCore.QRectF(x + 180, y, 100, serifLineHeight) text = localsettings.formatMoney(amount) painter.drawText(rect_f, text, alignRight) y += serifLineHeight y += serifLineHeight painter.drawLine(int(x), int(y), int(x) + 280, int(y)) # 130+150=280 y += serifLineHeight * 1.5 rect_f = QtCore.QRectF(x, y, 180, serifLineHeight) painter.drawText(rect_f, "TOTAL") rect_f = QtCore.QRectF(x + 180, y, 100, serifLineHeight) text = localsettings.formatMoney(self.total) painter.drawText(rect_f, text, alignRight) y += serifLineHeight * 4 font = QtGui.QFont("Helvetica", 7) font.setItalic(True) painter.setFont(font) painter.drawText(x, y, _("Thankyou for your custom.")) return True
def file_print(self): dlg = QtPrintSupport.QPrintDialog() if dlg.exec_(): self.editor.print_(dlg.printer())
def handlePrint(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QtWidgets.QDialog.Accepted: #self.centralWidget.document().print_(dialog.printer()) self.text.document().print_(dialog.printer())
def print_(self): dialog = QtPrintSupport.QPrintDialog(self.printer, self.om_gui) if not dialog.exec_(): return font = QtGui.QFont("Helvetica", 11) fm = QtGui.QFontMetrics(font) line_height = fm.height() italic_font = QtGui.QFont(font) italic_font.setItalic(True) sigFont = QtGui.QFont("URW Chancery L", 18) sigFont.setBold(True) sig_font_height = QtGui.QFontMetrics(sigFont).height() * 1.2 pageRect = self.printer.pageRect() LEFT = 60 RIGHT = 80 TOP = 170 RECT_WIDTH = pageRect.width() - (LEFT + RIGHT) ADDRESS_LEFT = 80 ADDRESS_HEIGHT = 140 FOOTER_HEIGHT = 180 DATE_HEIGHT = 2 * line_height BODY_HEIGHT = pageRect.height() - (TOP + ADDRESS_HEIGHT + FOOTER_HEIGHT + DATE_HEIGHT) addressRect = QtCore.QRectF(ADDRESS_LEFT, TOP, 300, ADDRESS_HEIGHT) dateRect = QtCore.QRectF(LEFT, addressRect.bottom(), RECT_WIDTH, DATE_HEIGHT) bodyRect = QtCore.QRectF(LEFT, dateRect.bottom(), RECT_WIDTH, BODY_HEIGHT) footerRect = QtCore.QRectF(LEFT, pageRect.height() - FOOTER_HEIGHT, RECT_WIDTH, FOOTER_HEIGHT) painter = QtGui.QPainter(self.printer) first_page = True page_no = 0 for letter in self.iterate_letters(): page_no += 1 if dialog.printRange() == dialog.PageRange: if page_no < dialog.fromPage(): continue if dialog.toPage() != 0 and page_no > dialog.toPage(): continue if not first_page: self.printer.newPage() first_page = False painter.save() painter.setFont(font) painter.setPen(QtCore.Qt.black) option = QtGui.QTextOption(QtCore.Qt.AlignLeft) option.setWrapMode(QtGui.QTextOption.WordWrap) # address painter.drawText(addressRect, letter.address, option) if DEBUG: painter.drawRect(addressRect.adjusted(2, 2, -2, -2)) # date if self.use_given_recall_date: pdate = letter.recd else: pdate = self.adate if self.LONGDATE: pdate_str = localsettings.longDate(pdate) else: pdate_str = "%s %s" % (localsettings.monthName(pdate), pdate.year) painter.drawText(dateRect, pdate_str, QtGui.QTextOption(QtCore.Qt.AlignRight)) if DEBUG: painter.drawRect(dateRect.adjusted(2, 2, -2, -2)) # salutation rect = bodyRect.adjusted(0, 0, 0, 2 * line_height - bodyRect.height()) painter.drawText(rect, letter.salutation, option) if DEBUG: painter.drawRect(rect.adjusted(2, 2, -2, -2)) # subject # option = QtGui.QTextOption(QtCore.Qt.AlignCenter) font.setBold(True) painter.setFont(font) subject_count = len(letter.subjects) + 1 rect = QtCore.QRectF(rect.bottomLeft().x(), rect.bottomLeft().y(), bodyRect.width(), line_height * subject_count) subj_rect = rect.adjusted(50, 0, -50, 0) painter.drawText(subj_rect, letter.subject_text, option) if DEBUG: painter.drawRect(subj_rect.adjusted(2, 2, -2, -2)) font.setBold(False) painter.setFont(font) # body line_count = letter.text.count("\n") + 3 body_rect = QtCore.QRectF(rect.bottomLeft().x(), subj_rect.bottomLeft().y(), bodyRect.width(), line_height * line_count) painter.drawText(body_rect, letter.text, option) if DEBUG: painter.drawRect(body_rect.adjusted(2, 2, -2, -2)) # custom line_count = CUSTOM_TEXT.count("\n") + 5 custom_rect = QtCore.QRectF(body_rect.bottomLeft().x(), body_rect.bottomLeft().y(), bodyRect.width(), line_height * line_count) painter.setFont(font) painter.drawText(custom_rect, CUSTOM_TEXT, option) if DEBUG: painter.drawRect(custom_rect.adjusted(2, 2, -2, -2)) # signature # place signature immediately after the body # + custom text (which will vary) sign_off_rect = QtCore.QRectF(custom_rect.bottomLeft().x(), custom_rect.bottomLeft().y(), body_rect.width(), line_height * 1.5) painter.drawText(sign_off_rect, SIGN_OFF, option) if DEBUG: painter.drawRect(sign_off_rect.adjusted(2, 2, -2, -2)) sig_rect = sign_off_rect.adjusted(20, sign_off_rect.height(), 0, sig_font_height) painter.save() painter.setFont(sigFont) painter.drawText(sig_rect, localsettings.PRACTICE_NAME, option) if DEBUG: painter.drawRect(sig_rect.adjusted(2, 2, -2, -2)) painter.restore() # ps line_count = PS_TEXT.count("\n") + 2 ps_rect = QtCore.QRectF( body_rect.bottomLeft().x(), sig_rect.bottomLeft().y() + line_height * 2, bodyRect.width(), line_height * line_count) painter.setFont(font) painter.drawText(ps_rect, PS_TEXT, option) if DEBUG: painter.drawRect(ps_rect.adjusted(2, 2, -2, -2)) # footer option = QtGui.QTextOption(QtCore.Qt.AlignHCenter) option.setWrapMode(QtGui.QTextOption.WordWrap) painter.drawLine(footerRect.topLeft(), footerRect.topRight()) painter.setFont(italic_font) painter.drawText(footerRect, FOOTER, option) if DEBUG: painter.drawRect(footerRect.adjusted(2, 2, -2, -2)) # fold marks pen = QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), 3) painter.setPen(pen) top_fold_y = pageRect.height() / 3 painter.drawLine(0, top_fold_y, 10, top_fold_y) top_fold_y = pageRect.height() * 2 / 3 painter.drawLine(0, top_fold_y, 10, top_fold_y) painter.restore()
def printHandler(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QtWidgets.QDialog.Accepted: self.text.document().print_(dialog.printer())
def print_file(self): dlg = qtp.QPrintDialog() if dlg.exec_(): self.editor.print_(dlg.printer())
def handlePrint(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QtPrintSupport.QPrintDialog.Accepted: self.handlePaintRequest(dialog.printer())
def print_handler(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QDialog.Accepted: self.handle_paint_request(dialog.printer())
def onPrint(self): pd = QtPrintSupport.QPrintDialog(self.printer, parent=self) pd.setOptions(QtPrintSupport.QAbstractPrintDialog.PrintToFile | QtPrintSupport.QAbstractPrintDialog.PrintSelection) if pd.exec() == QtWidgets.QDialog.Accepted: self.sudoku.print(self.printer)
def print_(self, expanded=False): ''' if expanded, the list will fill the page ''' dialog = QtPrintSupport.QPrintDialog(self.printer, self.parent) if not dialog.exec_(): return # leave space at the bottom for notes? LeftMargin, RightMargin, TopMargin, BottomMargin = 30, 30, 30, 100 sansFont = QtGui.QFont("Helvetica", 9) fm = QtGui.QFontMetrics(sansFont) pageWidth = self.printer.pageRect().width() - LeftMargin - RightMargin painter = QtGui.QPainter(self.printer) option_center = QtGui.QTextOption(QtCore.Qt.AlignCenter) option_right = QtGui.QTextOption( QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) option_topright = QtGui.QTextOption(QtCore.Qt.AlignRight) for page, date_ in enumerate(self.dates): painter.save() rowCount = len(self.apps[page]) if not expanded: rowHeight = fm.height() else: pageHeight = self.printer.pageRect( ).height() - TopMargin - BottomMargin rowHeight = pageHeight / \ (rowCount + 3) # +3 allows for headings # get col widths. colwidths = {} # start,end,name,serialno,code0,code1,code2,note for app in self.apps[page]: # get widths app_tup = ("88888", "(888 mins)", app.name, "88888", "888", app.treat, app.note) for i, att in enumerate(app_tup): w = fm.width(str(att)) try: if colwidths[i] < w: colwidths[i] = w except KeyError: colwidths[i] = w total = sum(colwidths.values()) for i in range(len(colwidths)): colwidths[i] = colwidths[i] * pageWidth / total x, y = LeftMargin, TopMargin painter.setPen(QtCore.Qt.black) painter.setFont(sansFont) rect = QtCore.QRectF(x, y, pageWidth, rowHeight) now = QtCore.QDateTime.currentDateTime().toString() painter.drawText( rect, "%s %s %s" % (_("Daylist for"), self.dentist[page], self.dayMemo[page]), option_center) y += rowHeight rect = QtCore.QRectF(x, y, pageWidth, rowHeight) painter.drawText(rect, date_, option_center) y += rowHeight * 1.5 painter.setBrush(QtGui.QColor("#eeeeee")) for i, column in enumerate((_("Start"), _("Len"), _("Name"), _("No."), _(""), _("Treat"), _("memo"))): rect = QtCore.QRectF(x, y, colwidths[i], rowHeight) painter.drawRect(rect) painter.drawText( rect.adjusted(2, 0, -2, 0), column, option_center) x += colwidths[i] y += rowHeight painter.setBrush(QtCore.Qt.transparent) for app in self.apps[page]: app_tup = (app.start, "(%d %s)" % (app.length(), _("mins")), app.name, app.serialno, app.cset, app.treat.strip(), app.note) x = LeftMargin for i, att in enumerate(app_tup): option = option_right if i == 3 else option_center rect = QtCore.QRectF(x, y, colwidths[i], rowHeight) painter.drawRect(rect) rect = rect.adjusted(2, 0, -2, 0) if att: painter.drawText(rect, str(att), option) if i == 2 and app.mh_form_required: painter.drawText(rect, "+", option_topright) x += colwidths[i] y += rowHeight y += rowHeight rect = QtCore.QRectF(LeftMargin, y, pageWidth, rowHeight) painter.drawText(rect, "%s %s" % (_("Printed"), now), option) if page < len(self.dates) - 1: self.printer.newPage() painter.restore()
def yazdir(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QDialog.Accepted: doc = self.model_olustur() dialog.printer().setPageMargins(5, 5, 5, 5, QPrinter.Millimeter) doc.print_(dialog.printer())
def dialogExec(self): dl = QtPrintSupport.QPrintDialog(self.printer, self.parent) return dl.exec_()