home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / hplip / fax / coverpages.py < prev    next >
Encoding:
Python Source  |  2006-08-30  |  5.6 KB  |  163 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2003-2006 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program 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 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program 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 this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. from reportlab.platypus.paragraph import Paragraph  
  23. from reportlab.platypus.doctemplate import *
  24. from reportlab.platypus import SimpleDocTemplate, Spacer
  25. from reportlab.platypus.tables import Table, TableStyle #, LIST_STYLE
  26.  
  27. from reportlab.lib.pagesizes import letter, legal, A4
  28. from reportlab.lib.units import inch
  29. from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
  30. from reportlab.lib import colors
  31.  
  32. from time import localtime, strftime
  33.  
  34. from base import utils
  35.  
  36. PAGE_SIZE_LETTER = 'letter'
  37. PAGE_SIZE_LEGAL = 'legal'
  38. PAGE_SIZE_A4 = 'a4'
  39.  
  40.  
  41. def createStandardCoverPage(page_size=PAGE_SIZE_LETTER,
  42.                             total_pages=1, 
  43.                             
  44.                             recipient_name='', 
  45.                             recipient_phone='', 
  46.                             recipient_fax='', 
  47.                             
  48.                             sender_name='', 
  49.                             sender_phone='',
  50.                             sender_fax='', 
  51.                             sender_email='', 
  52.                             
  53.                             regarding='', 
  54.                             message=''):
  55.  
  56.                     
  57.     s = getSampleStyleSheet()
  58.     
  59.     story = []
  60.     
  61.     ps = ParagraphStyle(name="title", 
  62.                         parent=None, 
  63.                         fontName='helvetica-bold',
  64.                         fontSize=36,
  65.                         )
  66.  
  67.     story.append(Paragraph("Fax", ps))
  68.     
  69.     story.append(Spacer(1, inch))
  70.     
  71.     ps = ParagraphStyle(name='normal',
  72.                         fontName='Times-Roman',
  73.                         fontSize=12) #,
  74.                         #leading=12)
  75.     
  76.     
  77.     recipient_name_label = Paragraph("To:", ps)
  78.     recipient_name_text = Paragraph(recipient_name[:64], ps)
  79.     
  80.     recipient_fax_label = Paragraph("Fax:", ps)
  81.     recipient_fax_text = Paragraph(recipient_fax[:64], ps)
  82.     
  83.     recipient_phone_label = Paragraph("Phone:", ps)
  84.     recipient_phone_text = Paragraph(recipient_phone[:64], ps)
  85.     
  86.     
  87.     sender_name_label = Paragraph("From:", ps)
  88.     sender_name_text = Paragraph(sender_name[:64], ps)
  89.  
  90.     sender_phone_label = Paragraph("Phone:", ps)
  91.     sender_phone_text = Paragraph(sender_phone[:64], ps)
  92.     
  93.     sender_email_label = Paragraph("Email:", ps)
  94.     sender_email_text = Paragraph(sender_email[:64], ps)
  95.     
  96.     
  97.     regarding_label = Paragraph("Regarding:", ps)
  98.     regarding_text = Paragraph(regarding[:128], ps)
  99.     
  100.     date_time_label = Paragraph("Date:", ps)
  101.     date_time_text = Paragraph(strftime("%a, %d %b %Y %H:%M:%S (%Z)", localtime()), ps)
  102.     
  103.     total_pages_label = Paragraph("Total Pages:", ps)
  104.     total_pages_text = Paragraph("%d" % total_pages, ps)
  105.  
  106.     data = [[recipient_name_label, recipient_name_text, sender_name_label, sender_name_text],
  107.             [recipient_fax_label, recipient_fax_text, sender_phone_label, sender_phone_text],
  108.             #[recipient_phone_label, recipient_phone_text, sender_email_label, sender_email_text],
  109.             [date_time_label, date_time_text, sender_email_label, sender_email_text],
  110.             #[ '', '', date_time_label, date_time_text],
  111.             [regarding_label, regarding_text, total_pages_label, total_pages_text]]
  112.             
  113.     LIST_STYLE = TableStyle([('LINEABOVE', (0,0), (-1,0), 2, colors.black),
  114.                              ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
  115.                              ('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
  116.                              ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
  117.                              ('VALIGN', (0, 0), (-1, -1), 'TOP'), 
  118.                             ])
  119.     
  120.     t = Table(data, style=LIST_STYLE)
  121.    
  122.     story.append(t)
  123.     
  124.     if message:
  125.         
  126.         MSG_STYLE = TableStyle([('LINEABOVE', (0,0), (-1,0), 2, colors.black),
  127.                                  ('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black),
  128.                                  ('LINEBELOW', (0,-1), (-1,-1), 2, colors.black),
  129.                                  ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
  130.                                  ('VALIGN', (0, 0), (-1, -1), 'TOP'),
  131.                                  ('SPAN', (-2, 1), (-1, -1)), 
  132.                                 ])
  133.     
  134.         story.append(Spacer(1, 0.5*inch))
  135.         
  136.         data = [[Paragraph("Comments/Notes:", ps), ''],
  137.                 [Paragraph(message[:2048], ps), ''],]
  138.                 
  139.         t = Table(data, style=MSG_STYLE)
  140.         
  141.         story.append(t)
  142.     
  143.     if page_size == PAGE_SIZE_LETTER:
  144.         pgsz = letter
  145.     elif page_size == PAGE_SIZE_LEGAL:
  146.         pgsz = legal
  147.     else:
  148.         pgsz = A4
  149.         
  150.     f_fd, f = utils.make_temp_file()
  151.     
  152.     doc = SimpleDocTemplate(f, pagesize=pgsz)
  153.     doc.build(story)
  154.     
  155.     return f
  156.     
  157.     
  158.     
  159. #            { "name" : (function, "thumbnail.png"), ... }    
  160. COVERPAGES = { "basic": (createStandardCoverPage, 'standard_coverpage.png'),
  161.              }
  162.  
  163.