Thread: [PythonReports-checkins] PythonReports/PythonReports pdf.py, 1.2, 1.3
Brought to you by:
a1s
From: alexander s. <a1...@us...> - 2006-12-06 16:48:59
|
Update of /cvsroot/pythonreports/PythonReports/PythonReports In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3974 Modified Files: pdf.py Log Message: sweep pylint warnings; remove pdf autostart (can be easily done in command line) Index: pdf.py =================================================================== RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/pdf.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pdf.py 7 Nov 2006 13:32:02 -0000 1.2 --- pdf.py 6 Dec 2006 16:48:56 -0000 1.3 *************** *** 2,5 **** --- 2,7 ---- """PDF output for PythonReports""" """History (most recent first): + 05-dec-2006 [als] sweep pylint warnings; + remove pdf autostart (can be easily done in command line) 07-Nov-2006 [phd] Added shebang. 20-oct-2006 [als] Barcode X dimension attr renamed to "module" *************** *** 54,58 **** wordspace = 0 ! def __init__(self, report, filepath=None): """Initialize the writer --- 56,60 ---- wordspace = 0 ! def __init__(self, report): """Initialize the writer *************** *** 63,80 **** super(PdfWriter, self).__init__() if isinstance(report, basestring): ! report = prp.load(report) ! self.report = report # element handlers self.handlers = { ! "line": self.DrawLine, ! "rectangle": self.DrawRectangle, ! "text": self.DrawText, ! "barcode": self.DrawBarcode, } if Image: # PIL is loaded - can process images ! self.handlers["image"] = self.DrawImage _images = {} ! for _element in report.findall("data"): _data = StringIO(Data.get_data(_element)) # data blocks may be used for other purposes too. --- 65,83 ---- super(PdfWriter, self).__init__() if isinstance(report, basestring): ! self.report = prp.load(report) ! else: ! self.report = report # element handlers self.handlers = { ! "line": self.drawLine, ! "rectangle": self.drawRectangle, ! "text": self.drawText, ! "barcode": self.drawBarcode, } if Image: # PIL is loaded - can process images ! self.handlers["image"] = self.drawImage _images = {} ! for _element in self.report.findall("data"): _data = StringIO(Data.get_data(_element)) # data blocks may be used for other purposes too. *************** *** 89,93 **** _fonts = {} _registered = set() ! for (_name, _font) in report.fonts.iteritems(): _typeface = _font.get("typeface") _bold = _font.get("bold") --- 92,96 ---- _fonts = {} _registered = set() ! for (_name, _font) in self.report.fonts.iteritems(): _typeface = _font.get("typeface") _bold = _font.get("bold") *************** *** 270,274 **** _box.get("width"), _height) ! def DrawLine(self, line): # set line style, return if the line is not visible if not (self.setStrokeColor(line.get("color")) --- 273,278 ---- _box.get("width"), _height) ! def drawLine(self, line): ! """Draw a line""" # set line style, return if the line is not visible if not (self.setStrokeColor(line.get("color")) *************** *** 287,291 **** self.canvas.line(_x1, _y1, _x2, _y2) ! def DrawRectangle(self, rect): _stroke = self.setStrokeColor(rect.get("pencolor")) \ and self.setPen(rect.get("pen")) --- 291,296 ---- self.canvas.line(_x1, _y1, _x2, _y2) ! def drawRectangle(self, rect): ! """Draw a rectangle""" _stroke = self.setStrokeColor(rect.get("pencolor")) \ and self.setPen(rect.get("pen")) *************** *** 298,302 **** self.canvas.rect(*(self.getDimensions(rect) + (_stroke, _fill))) ! def DrawImage(self, image): _scale = image.get("scale", True) _img = image.get("file") --- 303,308 ---- self.canvas.rect(*(self.getDimensions(rect) + (_stroke, _fill))) ! def drawImage(self, image): ! """Draw an image""" _scale = image.get("scale", True) _img = image.get("file") *************** *** 323,327 **** self.canvas.drawImage(ImageReader(_img), _x, _y) ! def DrawText(self, text): _content = text.find("data").text if not _content: --- 329,334 ---- self.canvas.drawImage(ImageReader(_img), _x, _y) ! def drawText(self, text): ! """Draw a text block""" _content = text.find("data").text if not _content: *************** *** 377,381 **** _tobj.textLine(_line) ! def DrawBarcode(self, barcode): _xdim = barcode.get("module") / 1000. * 72. _stripes = [int(_stripe) * _xdim --- 384,389 ---- _tobj.textLine(_line) ! def drawBarcode(self, barcode): ! """Draw Bar Code symbol""" _xdim = barcode.get("module") / 1000. * 72. _stripes = [int(_stripe) * _xdim *************** *** 412,415 **** --- 420,424 ---- def run(argv=sys.argv): + """Command line executable""" if len(argv) not in (2, 3): print "Usage: %s <printout> [<pdf>]" % argv[0] *************** *** 421,426 **** _pdf = os.path.splitext(_printout)[0] + ".pdf" write(_printout, _pdf) - # XXX DEBUG: run the pdf - os.system(_pdf) if __name__ == "__main__": --- 430,433 ---- |