Package Camelot :: Package camelot :: Package view :: Package controls :: Module printer
[frames] | no frames]

Source Code for Module Camelot.camelot.view.controls.printer

  1  #  ================================================================================== 
  2  # 
  3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved. 
  4  #  www.conceptive.be / project-camelot@conceptive.be 
  5  # 
  6  #  This file is part of the Camelot Library. 
  7  # 
  8  #  This file may be used under the terms of the GNU General Public 
  9  #  License version 2.0 as published by the Free Software Foundation 
 10  #  and appearing in the file LICENSE.GPL included in the packaging of 
 11  #  this file.  Please review the following information to ensure GNU 
 12  #  General Public Licensing requirements will be met: 
 13  #  http://www.trolltech.com/products/qt/opensource.html 
 14  # 
 15  #  If you are unsure which license is appropriate for your use, please 
 16  #  review the following information: 
 17  #  http://www.trolltech.com/products/qt/licensing.html or contact 
 18  #  project-camelot@conceptive.be. 
 19  # 
 20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 
 21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
 22  # 
 23  #  For use of this library in commercial applications, please contact 
 24  #  project-camelot@conceptive.be 
 25  # 
 26  #  ================================================================================== 
 27   
 28  """ 
 29  class to handle printing 
 30  """ 
 31   
 32  import logging 
 33  logger = logging.getLogger( 'printer' ) 
 34   
 35  from PyQt4 import QtGui 
 36  from camelot.view.model_thread import post 
 37   
 38  icon = '../art/tango/32x32/apps/system-users.png' 
 39   
40 -class Printer:
41 - def __init__( self ):
42 self.printer = QtGui.QPrinter() 43 self.printer.setPageSize( QtGui.QPrinter.Letter )
44
45 - def printView( self, view, parent ):
46 import settings 47 logger.debug( 'printing table view' ) 48 dialog = QtGui.QPrintDialog( self.printer, parent ) 49 if not dialog.exec_(): 50 return 51 52 client_address = '<br/>'.join( ['2 Azalea St.', 53 'Fredericksburg', 54 '22406 VA'] ) 55 56 import datetime 57 ts = datetime.datetime.today() 58 datestring = 'Date: %s/%s/%s' % ( ts.month, ts.day, ts.year ) 59 60 view_content = view.to_html() 61 context = { 62 'logo' : icon, 63 'company_name' : 'Conceptive Engineering', 64 'company_address_1' : 'L. Van Bauwelstraat 16', 65 'company_address_2' : '2220 Heist-op-den-Berg', 66 'city' : 'Belgium', 67 'date' : datestring, 68 'client_address' : client_address, 69 'client_name' : 'Client', 70 'content' : view_content, 71 'signature' : 'M. Anager' 72 } 73 74 from jinja import Environment, FileSystemLoader 75 fileloader = FileSystemLoader( settings.CANTATE_TEMPLATES_DIRECTORY ) 76 e = Environment( loader = fileloader ) 77 t = e.get_template( 'base.html' ) 78 html = t.render( context ) 79 80 doc = QtGui.QTextDocument() 81 doc.setHtml( html ) 82 doc.print_( self.printer )
83
84 - def preview( self, view, parent ):
85 logger.debug( 'print preview dialog' ) 86 87 def generate_html(): 88 client_address = '<br/>'.join( ['2 Azalea St.', 89 'Fredericksburg', 90 '22406 VA'] ) 91 92 import datetime 93 ts = datetime.datetime.today() 94 datestring = 'Date: %s/%s/%s' % ( ts.month, ts.day, ts.year ) 95 96 view_content = view.to_html() 97 context = { 98 'logo' : icon, 99 'company_name' : 'Conceptive Engineering', 100 'company_address_1' : 'L. Van Bauwelstraat 16', 101 'company_address_2' : '2220 Heist-op-den-Berg', 102 'city' : 'Belgium', 103 'date' : datestring, 104 'client_address' : client_address, 105 'client_name' : 'Client', 106 'content' : view_content, 107 'signature' : 'M. Anager' 108 } 109 110 from jinja import Environment 111 from camelot.view.templates import loader 112 e = Environment( loader = loader ) 113 t = e.get_template( 'base.html' ) 114 html = t.render( context ) 115 return html
116 117 from camelot.view.export.printer import open_html_in_print_preview_from_gui_thread 118 post( generate_html, open_html_in_print_preview_from_gui_thread )
119