Package Gnumed :: Package timelinelib :: Module printing
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.printing

  1  # Copyright (C) 2009, 2010, 2011  Rickard Lindberg, Roger Lindberg 
  2  # 
  3  # This file is part of Timeline. 
  4  # 
  5  # Timeline is free software: you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation, either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Timeline is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18   
 19  import wx 
 20   
 21   
22 -class TimelinePrintout(wx.Printout):
23 """ 24 This class has the functionality of printing out a Timeline document. 25 Responds to calls such as OnPrintPage and HasPage. 26 Instances of this class are passed to wx.Printer.Print() or a 27 wx.PrintPreview object to initiate printing or previewing. 28 """ 29
30 - def __init__(self, drawing_area, preview=False):
31 wx.Printout.__init__(self) 32 self.drawing_area = drawing_area 33 self.preview = preview
34
35 - def OnBeginDocument(self, start, end):
36 return super(TimelinePrintout, self).OnBeginDocument(start, end)
37
38 - def OnEndDocument(self):
39 super(TimelinePrintout, self).OnEndDocument()
40
41 - def OnBeginPrinting(self):
42 super(TimelinePrintout, self).OnBeginPrinting()
43
44 - def OnEndPrinting(self):
45 super(TimelinePrintout, self).OnEndPrinting()
46
47 - def OnPreparePrinting(self):
49
50 - def HasPage(self, page):
51 if page <= 1: 52 return True 53 else: 54 return False
55
56 - def GetPageInfo(self):
57 minPage = 1 58 maxPage = 1 59 pageFrom = 1 60 pageTo = 1 61 return (minPage, maxPage, pageFrom, pageTo)
62
63 - def OnPrintPage(self, page):
64 def SetScaleAndDeviceOrigin(dc): 65 (panel_width, panel_height) = self.drawing_area.GetSize() 66 # Let's have at least 50 device units margin 67 x_margin = 50 68 y_margin = 50 69 # Add the margin to the graphic size 70 x_max = panel_width + (2 * x_margin) 71 y_max = panel_height + (2 * y_margin) 72 # Get the size of the DC in pixels 73 (dc_width, dc_heighth) = dc.GetSizeTuple() 74 # Calculate a suitable scaling factor 75 x_scale = float(dc_width) / x_max 76 y_scale = float(dc_heighth) / y_max 77 # Use x or y scaling factor, whichever fits on the DC 78 scale = min(x_scale, y_scale) 79 # Calculate the position on the DC for centering the graphic 80 x_pos = (dc_width - (panel_width * scale)) / 2.0 81 y_pos = (dc_heighth - (panel_height * scale)) / 2.0 82 dc.SetUserScale(scale, scale) 83 dc.SetDeviceOrigin(int(x_pos), int(y_pos))
84 dc = self.GetDC() 85 SetScaleAndDeviceOrigin(dc) 86 dc.BeginDrawing() 87 dc.DrawBitmap(self.drawing_area.get_current_image(), 0, 0, True) 88 dc.EndDrawing() 89 return True
90 91 104 105 119 120 131