| 1 | from PyQt4.QtCore import * |
|---|
| 2 | from PyQt4.QtGui import * |
|---|
| 3 | from PyQt4.QtNetwork import * |
|---|
| 4 | from PyQt4.Qsci import * |
|---|
| 5 | |
|---|
| 6 | from PyQt4 import QtCore, QtGui |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | class PrinterTwedit(QsciPrinter): |
|---|
| 10 | """ |
|---|
| 11 | Class implementing the QextScintillaPrinter with a header. |
|---|
| 12 | """ |
|---|
| 13 | def __init__(self, mode = QPrinter.ScreenResolution): |
|---|
| 14 | """ |
|---|
| 15 | Constructor |
|---|
| 16 | |
|---|
| 17 | @param mode mode of the printer (QPrinter.PrinterMode) |
|---|
| 18 | """ |
|---|
| 19 | QsciPrinter.__init__(self, mode) |
|---|
| 20 | self.time = QTime.currentTime().toString(Qt.LocalDate) |
|---|
| 21 | self.date = QDate.currentDate().toString(Qt.LocalDate) |
|---|
| 22 | |
|---|
| 23 | def formatPage(self, painter, drawing, area, pagenr): |
|---|
| 24 | """ |
|---|
| 25 | Private method to generate a header line. |
|---|
| 26 | |
|---|
| 27 | @param painter the paint canvas (QPainter) |
|---|
| 28 | @param drawing flag indicating that something should be drawn |
|---|
| 29 | @param area the drawing area (QRect) |
|---|
| 30 | @param pagenr the page number (int) |
|---|
| 31 | """ |
|---|
| 32 | fn = self.docName() |
|---|
| 33 | |
|---|
| 34 | header = QApplication.translate('Printer', '%1 - Printed on %2, %3 ')\ |
|---|
| 35 | .arg(fn)\ |
|---|
| 36 | .arg(self.date)\ |
|---|
| 37 | .arg(self.time) |
|---|
| 38 | header.insert(0,"Twedit: ") |
|---|
| 39 | |
|---|
| 40 | footer = QApplication.translate('Printer', 'Page %1').arg(pagenr) |
|---|
| 41 | |
|---|
| 42 | painter.save() |
|---|
| 43 | painter.setFont(QFont("Arial")) |
|---|
| 44 | painter.setPen(QColor("#848484")) |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | if drawing: |
|---|
| 48 | |
|---|
| 49 | painter.drawText(area.left(),area.top() + painter.fontMetrics().ascent()+5, header) |
|---|
| 50 | |
|---|
| 51 | painter.drawText((area.width()-painter.fontMetrics().width(footer))/2,area.bottom()-5 , footer) |
|---|
| 52 | |
|---|
| 53 | area.setTop(area.top() + painter.fontMetrics().height() + 10) |
|---|
| 54 | area.setBottom(area.bottom() - (painter.fontMetrics().height() + 10) ) |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | painter.restore() |
|---|