Package camelot :: Package camelot :: Package view :: Package controls :: Module printer
[hide private]
[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 os 
 33  import sys 
 34  import logging 
 35   
 36  #FORMAT = '[%(levelname)-5s] [%(name)-35s] - %(message)s'  
 37  #logging.basicConfig(level=logging.DEBUG, format=FORMAT) 
 38  logger = logging.getLogger('printer') 
 39  logger.setLevel(logging.DEBUG) 
 40   
 41  import settings 
 42   
 43  from PyQt4 import QtGui 
 44  from PyQt4 import QtCore 
 45  from PyQt4.QtCore import Qt 
 46   
 47  icon = '../art/tango/32x32/apps/system-users.png' 
 48   
49 -class Printer:
50 - def __init__(self):
51 self.printer = QtGui.QPrinter() 52 self.printer.setPageSize(QtGui.QPrinter.Letter)
53
54 - def printView(self, view, parent):
55 logger.debug('printing table view') 56 dialog = QtGui.QPrintDialog(self.printer, parent) 57 if not dialog.exec_(): 58 return 59 60 client_address = '<br/>'.join(['2 Azalea St.', 61 'Fredericksburg', 62 '22406 VA']) 63 64 import datetime 65 ts = datetime.datetime.today() 66 datestring = 'Date: %s/%s/%s' % (ts.month, ts.day, ts.year) 67 68 view_content = view.toHtml() 69 context = { 70 'logo' : icon, 71 'company_name' : 'Conceptive Engineering', 72 'company_address_1' : 'L. Van Bauwelstraat 16', 73 'company_address_2' : '2220 Heist-op-den-Berg', 74 'city' : 'Belgium', 75 'date' : datestring, 76 'client_address' : client_address, 77 'client_name' : 'Client', 78 'content' : view_content, 79 'signature' : 'M. Anager' 80 } 81 82 from jinja import Environment, FileSystemLoader 83 fileloader = FileSystemLoader(settings.CANTATE_TEMPLATES_DIRECTORY) 84 e = Environment(loader=fileloader) 85 t = e.get_template('base.html') 86 html = t.render(context) 87 88 doc = QtGui.QTextDocument() 89 doc.setHtml(html) 90 doc.print_(self.printer)
91
92 - def preview(self, view, parent):
93 logger.debug('print preview dialog') 94 95 def generate_html(): 96 client_address = '<br/>'.join(['2 Azalea St.', 97 'Fredericksburg', 98 '22406 VA']) 99 100 import datetime 101 ts = datetime.datetime.today() 102 datestring = 'Date: %s/%s/%s' % (ts.month, ts.day, ts.year) 103 104 view_content = view.toHtml() 105 context = { 106 'logo' : icon, 107 'company_name' : 'Conceptive Engineering', 108 'company_address_1' : 'L. Van Bauwelstraat 16', 109 'company_address_2' : '2220 Heist-op-den-Berg', 110 'city' : 'Belgium', 111 'date' : datestring, 112 'client_address' : client_address, 113 'client_name' : 'Client', 114 'content' : view_content, 115 'signature' : 'M. Anager' 116 } 117 118 from jinja import Environment, FileSystemLoader 119 fileloader = FileSystemLoader(settings.CAMELOT_TEMPLATES_DIRECTORY) 120 e = Environment(loader=fileloader) 121 t = e.get_template('base.html') 122 html = t.render(context) 123 return html
124 125 from camelot.view.model_thread import get_model_thread 126 from camelot.view.export.printer import open_html_in_print_preview_from_gui_thread 127 mt = get_model_thread() 128 mt.post(generate_html, open_html_in_print_preview_from_gui_thread)
129