[PythonReports-checkins] PythonReports/PythonReports wxPrint.py, 1.2, 1.3
Brought to you by:
a1s
From: alexander s. <a1...@us...> - 2006-12-06 17:12:51
|
Update of /cvsroot/pythonreports/PythonReports/PythonReports In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12937 Modified Files: wxPrint.py Log Message: sweep pylint warnings; remove WrapLines - all texts must be wrapped by builder Index: wxPrint.py =================================================================== RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/wxPrint.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** wxPrint.py 7 Nov 2006 13:32:02 -0000 1.2 --- wxPrint.py 6 Dec 2006 17:12:47 -0000 1.3 *************** *** 7,10 **** --- 7,12 ---- """ """History (most recent first): + 05-dec-2006 [als] sweep pylint warnings; + remove WrapLines - all texts must be wrapped by builder 07-Nov-2006 [phd] Added shebang. 20-oct-2006 [als] Barcode X dimension attr renamed to "module" *************** *** 31,34 **** --- 33,41 ---- class Printout(wx.Printout): + """wxWidgets printout document""" + + # pylint: disable-msg=R0904 + # R0904: Too many public methods - most come from the base class + def __init__(self, report, title=None): """Initialize printout *************** *** 40,47 **** --- 47,58 ---- """ if isinstance(report, basestring): + # pylint: disable-msg=C0103 + # C0103: Invalid names "report", "title" if title is None: title = report report = prp.load(report) elif title is None: + # pylint: disable-msg=C0103 + # C0103: Invalid name "title" title = "Report Printout" super(Printout, self).__init__(title=title) *************** *** 50,58 **** # element handlers self.handlers = { ! "line": self.DrawLine, ! "rectangle": self.DrawRectangle, ! "image": self.DrawImage, ! "text": self.DrawText, ! "barcode": self.DrawBarcode, } _fonts = {} --- 61,69 ---- # element handlers self.handlers = { ! "line": self.drawLine, ! "rectangle": self.drawRectangle, ! "image": self.drawImage, ! "text": self.drawText, ! "barcode": self.drawBarcode, } _fonts = {} *************** *** 83,93 **** def GetPageInfo(self): _numpages = len(self.pages) return (1, _numpages, 1, _numpages) def HasPage(self, pageno): return (1 <= pageno <= len(self.pages)) ! def GetColor(self, color): """Return wx.Color object for color value of an element attribute""" if color: --- 94,107 ---- def GetPageInfo(self): + """Return available page ranges""" _numpages = len(self.pages) return (1, _numpages, 1, _numpages) def HasPage(self, pageno): + """Return True for existing page number""" return (1 <= pageno <= len(self.pages)) ! @staticmethod ! def getColor(color): """Return wx.Color object for color value of an element attribute""" if color: *************** *** 96,104 **** return wx.NullColour ! def SetPen(self, type, color): """Change the pen of the DC Parameters: ! type: value returned by PenType.fromValue() (PenType or Dimension instance) color: pen color (Color instance) --- 110,118 ---- return wx.NullColour ! def setPen(self, pen_type, color): """Change the pen of the DC Parameters: ! pen_type: value returned by PenType.fromValue() (PenType or Dimension instance) color: pen color (Color instance) *************** *** 106,120 **** """ _width = 1 ! if type == "dot": _style = wx.DOT ! elif type == "dash": _style = wx.SHORT_DASH ! elif type == "dashdot": _style = wx.DOT_DASH else: _style = wx.SOLID ! _width = int(type) if _width: ! _pen = wx.Pen(self.GetColor(color), _width, _style) else: _pen = wx.TRANSPARENT_PEN --- 120,134 ---- """ _width = 1 ! if pen_type == "dot": _style = wx.DOT ! elif pen_type == "dash": _style = wx.SHORT_DASH ! elif pen_type == "dashdot": _style = wx.DOT_DASH else: _style = wx.SOLID ! _width = int(pen_type) if _width: ! _pen = wx.Pen(self.getColor(color), _width, _style) else: _pen = wx.TRANSPARENT_PEN *************** *** 134,141 **** _brush = wx.Brush(wx.NullColour, wx.TRANSPARENT) else: ! _brush = wx.Brush(self.GetColor(color)) return _brush def OnPrintPage(self, pageno): try: _page = self.pages[pageno - 1] --- 148,156 ---- _brush = wx.Brush(wx.NullColour, wx.TRANSPARENT) else: ! _brush = wx.Brush(self.getColor(color)) return _brush def OnPrintPage(self, pageno): + """Draw selected page to the output device context""" try: _page = self.pages[pageno - 1] *************** *** 158,163 **** return True ! def DrawLine(self, line): ! self.SetPen(line.get("pen"), line.get("color")) _box = Box.from_element(line.find("box")) _dc = self.GetDC() --- 173,179 ---- return True ! def drawLine(self, line): ! """Draw a line""" ! self.setPen(line.get("pen"), line.get("color")) _box = Box.from_element(line.find("box")) _dc = self.GetDC() *************** *** 167,176 **** _dc.DrawLine(_box.left, _box.top, _box.right, _box.bottom) ! def DrawRectangle(self, rect): _box = Box.from_element(rect.find("box")) _radius = rect.get("radius") _dc = self.GetDC() _dc.SetBrush(self.GetBrush(rect.get("color"))) ! self.SetPen(rect.get("pen"), rect.get("pencolor")) if _radius: _dc.DrawRoundedRectangle(_box.x, _box.y, _box.width, _box.height, --- 183,193 ---- _dc.DrawLine(_box.left, _box.top, _box.right, _box.bottom) ! def drawRectangle(self, rect): ! """Draw a rectangle""" _box = Box.from_element(rect.find("box")) _radius = rect.get("radius") _dc = self.GetDC() _dc.SetBrush(self.GetBrush(rect.get("color"))) ! self.setPen(rect.get("pen"), rect.get("pencolor")) if _radius: _dc.DrawRoundedRectangle(_box.x, _box.y, _box.width, _box.height, *************** *** 179,183 **** _dc.DrawRectangle(_box.x, _box.y, _box.width, _box.height) ! def DrawImage(self, image): _file = image.get("file") if _file: --- 196,201 ---- _dc.DrawRectangle(_box.x, _box.y, _box.width, _box.height) ! def drawImage(self, image): ! """Draw an image""" _file = image.get("file") if _file: *************** *** 202,234 **** self.GetDC().DrawBitmap(wx.BitmapFromImage(_img), _box.x, _box.y) ! _word_re = re.compile("\s*\S+\s*") ! def WrapLines(self, text, width): ! # allow the text to be 1 point wider (round error?) ! width += 1 ! # if the text is not wider than required, return early ! _dc = self.GetDC() ! (_w, _h) = _dc.GetTextExtent(text) ! if _w <= width: ! return text ! # split text to words. inter-word spaces go to previous word. ! _lines = [] ! _words = self._word_re.findall(text) ! while _words: ! # scan backwards while the line is too wide ! _ii = len(_words) ! while _ii > 1: ! _line = "".join(_words[:_ii]).rstrip() ! (_w, _h) = _dc.GetTextExtent(_line) ! if _w <= width: ! break ! _ii -= 1 ! else: ! _line = _words[0].rstrip() ! # move found line from _words to _lines ! _lines.append(_line) ! _words = _words[_ii:] ! return "\n".join(_lines) ! ! def DrawText(self, text): _content = text.find("data").text if not _content: --- 220,225 ---- self.GetDC().DrawBitmap(wx.BitmapFromImage(_img), _box.x, _box.y) ! def drawText(self, text): ! """Draw a text block""" _content = text.find("data").text if not _content: *************** *** 236,240 **** _dc = self.GetDC() _dc.SetFont(self.fonts[text.get("font")]) ! _dc.SetTextForeground(self.GetColor(text.get("color"))) _align = text.get("align") if _align == "left": --- 227,231 ---- _dc = self.GetDC() _dc.SetFont(self.fonts[text.get("font")]) ! _dc.SetTextForeground(self.getColor(text.get("color"))) _align = text.get("align") if _align == "left": *************** *** 253,257 **** # _dc.DrawLine(_x, _re.y, _x, _re.y + _re.width - 1) ! def DrawBarcode(self, barcode): _stripes = [int(_stripe) for _stripe in barcode.get("stripes").split(",")] --- 244,249 ---- # _dc.DrawLine(_x, _re.y, _x, _re.y + _re.width - 1) ! def drawBarcode(self, barcode): ! """Draw Bar Code symbol""" _stripes = [int(_stripe) for _stripe in barcode.get("stripes").split(",")] *************** *** 287,290 **** --- 279,287 ---- class Preview(wx.PrintPreview): + """Print Preview manager""" + + # pylint: disable-msg=R0904 + # R0904: Too many public methods - same as in the base class + def __init__(self, report, title=None, print_data=None): """Initialize print preview *************** *** 302,321 **** class PrintApp(wx.App): ! def __init__(self, prp, *args, **kwargs): """Intialize the application Parameters: ! prp: name of the printout file remaining arguments are passed to the base class. """ ! self.prp = prp super(PrintApp, self).__init__(*args, **kwargs) def OnInit(self): _preview = Preview(self.prp) if not _preview.Ok(): raise RuntimeError, "Cannot initialize preview" ! return False _frame = wx.PreviewFrame(_preview, None, self.prp, size=(800, 600)) _frame.Initialize() --- 299,325 ---- class PrintApp(wx.App): ! """Simple application for preview and printing of a printout""" ! ! # pylint: disable-msg=R0901,R0904 ! # R0901: Too many ancestors - sorry, cannot help it ! # R0904: Too many public methods - same as in the base class ! ! def __init__(self, printout, *args, **kwargs): """Intialize the application Parameters: ! printout: name of the printout file remaining arguments are passed to the base class. """ ! self.prp = printout super(PrintApp, self).__init__(*args, **kwargs) def OnInit(self): + """Start the application: create main frame and open report preview""" _preview = Preview(self.prp) if not _preview.Ok(): raise RuntimeError, "Cannot initialize preview" ! # if raise is changed to MessageBox, return False here _frame = wx.PreviewFrame(_preview, None, self.prp, size=(800, 600)) _frame.Initialize() *************** *** 324,327 **** --- 328,332 ---- def run(argv=sys.argv): + """Command line executable""" if len(argv) != 2: print "Usage: %s <printout>" % argv[0] |