root/branch/twedit/PrinterTwedit.py

Revision 1584, 2.1 kB (checked in by mswat, 16 months ago)
Line 
1from PyQt4.QtCore import *
2from PyQt4.QtGui import *
3from PyQt4.QtNetwork import *
4from PyQt4.Qsci import *
5
6from PyQt4 import QtCore, QtGui
7
8# this code is basedon Eric 4 code
9class 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        #formatting header
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        #formatting footer   
40        footer = QApplication.translate('Printer', 'Page %1').arg(pagenr)
41       
42        painter.save()
43        painter.setFont(QFont("Arial"))    # set our header font       
44        painter.setPen(QColor("#848484"))            # set color
45 
46
47        if drawing:
48            # printing header
49            painter.drawText(area.left(),area.top() + painter.fontMetrics().ascent()+5, header)           
50            # printing footer
51            painter.drawText((area.width()-painter.fontMetrics().width(footer))/2,area.bottom()-5 , footer)
52        # resetting main print area bounding rectangle   
53        area.setTop(area.top() + painter.fontMetrics().height() + 10)       
54        area.setBottom(area.bottom() - (painter.fontMetrics().height() + 10) )
55
56       
57        painter.restore()
Note: See TracBrowser for help on using the browser.