home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / fax / coverpages.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  4.2 KB  |  109 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. from reportlab.platypus.paragraph import Paragraph
  5. from reportlab.platypus.flowables import Preformatted
  6. from reportlab.platypus.doctemplate import *
  7. from reportlab.platypus import SimpleDocTemplate, Spacer
  8. from reportlab.platypus.tables import Table, TableStyle
  9. from reportlab.lib.pagesizes import letter, legal, A4
  10. from reportlab.lib.units import inch
  11. from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
  12. from reportlab.lib import colors
  13. from time import localtime, strftime
  14. from base import utils
  15. PAGE_SIZE_LETTER = 'letter'
  16. PAGE_SIZE_LEGAL = 'legal'
  17. PAGE_SIZE_A4 = 'a4'
  18.  
  19. def escape(s):
  20.     return s.replace('&', '&').replace('>', '>').replace('<', '<')
  21.  
  22.  
  23. def createStandardCoverPage(page_size = PAGE_SIZE_LETTER, total_pages = 1, recipient_name = '', recipient_phone = '', recipient_fax = '', sender_name = '', sender_phone = '', sender_fax = '', sender_email = '', regarding = '', message = ''):
  24.     s = getSampleStyleSheet()
  25.     story = []
  26.     ps = ParagraphStyle(name = 'title', parent = None, fontName = 'helvetica-bold', fontSize = 36)
  27.     story.append(Paragraph('Fax', ps))
  28.     story.append(Spacer(1, inch))
  29.     ps = ParagraphStyle(name = 'normal', fontName = 'Times-Roman', fontSize = 12)
  30.     recipient_name_label = Paragraph('To:', ps)
  31.     recipient_name_text = Paragraph(escape(recipient_name[:64]), ps)
  32.     recipient_fax_label = Paragraph('Fax:', ps)
  33.     recipient_fax_text = Paragraph(escape(recipient_fax[:64]), ps)
  34.     recipient_phone_label = Paragraph('Phone:', ps)
  35.     recipient_phone_text = Paragraph(escape(recipient_phone[:64]), ps)
  36.     sender_name_label = Paragraph('From:', ps)
  37.     sender_name_text = Paragraph(escape(sender_name[:64]), ps)
  38.     sender_phone_label = Paragraph('Phone:', ps)
  39.     sender_phone_text = Paragraph(escape(sender_phone[:64]), ps)
  40.     sender_email_label = Paragraph('Email:', ps)
  41.     sender_email_text = Paragraph(escape(sender_email[:64]), ps)
  42.     regarding_label = Paragraph('Regarding:', ps)
  43.     regarding_text = Paragraph(escape(regarding[:128]), ps)
  44.     date_time_label = Paragraph('Date:', ps)
  45.     date_time_text = Paragraph(strftime('%a, %d %b %Y %H:%M:%S (%Z)', localtime()), ps)
  46.     total_pages_label = Paragraph('Total Pages:', ps)
  47.     total_pages_text = Paragraph('%d' % total_pages, ps)
  48.     data = [
  49.         [
  50.             recipient_name_label,
  51.             recipient_name_text,
  52.             sender_name_label,
  53.             sender_name_text],
  54.         [
  55.             recipient_fax_label,
  56.             recipient_fax_text,
  57.             sender_phone_label,
  58.             sender_phone_text],
  59.         [
  60.             date_time_label,
  61.             date_time_text,
  62.             sender_email_label,
  63.             sender_email_text],
  64.         [
  65.             regarding_label,
  66.             regarding_text,
  67.             total_pages_label,
  68.             total_pages_text]]
  69.     LIST_STYLE = TableStyle([
  70.         ('LINEABOVE', (0, 0), (-1, 0), 2, colors.black),
  71.         ('LINEABOVE', (0, 1), (-1, -1), 0.25, colors.black),
  72.         ('LINEBELOW', (0, -1), (-1, -1), 2, colors.black),
  73.         ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  74.         ('VALIGN', (0, 0), (-1, -1), 'TOP')])
  75.     t = Table(data, style = LIST_STYLE)
  76.     story.append(t)
  77.     if message:
  78.         MSG_STYLE = TableStyle([
  79.             ('LINEABOVE', (0, 0), (-1, 0), 2, colors.black),
  80.             ('LINEABOVE', (0, 1), (-1, -1), 0.25, colors.black),
  81.             ('LINEBELOW', (0, -1), (-1, -1), 2, colors.black),
  82.             ('ALIGN', (1, 1), (-1, -1), 'RIGHT'),
  83.             ('VALIGN', (0, 0), (-1, -1), 'TOP'),
  84.             ('SPAN', (-2, 1), (-1, -1))])
  85.         story.append(Spacer(1, 0.5 * inch))
  86.         data = [
  87.             [
  88.                 Paragraph('Comments/Notes:', ps),
  89.                 ''],
  90.             [
  91.                 Paragraph(escape(message[:2048]), ps),
  92.                 '']]
  93.         t = Table(data, style = MSG_STYLE)
  94.         story.append(t)
  95.     
  96.     if page_size == PAGE_SIZE_LETTER:
  97.         pgsz = letter
  98.     elif page_size == PAGE_SIZE_LEGAL:
  99.         pgsz = legal
  100.     else:
  101.         pgsz = A4
  102.     (f_fd, f) = utils.make_temp_file()
  103.     doc = SimpleDocTemplate(f, pagesize = pgsz)
  104.     doc.build(story)
  105.     return f
  106.  
  107. COVERPAGES = {
  108.     'basic': (createStandardCoverPage, 'standard_coverpage.png') }
  109.