mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Refactoring layout things
This commit is contained in:
@@ -144,12 +144,12 @@ def convert(input_file, output_format='fmpxml', start=None, end=None, select_ree
|
||||
output_line_count(parsed)
|
||||
output_summary(parsed)
|
||||
|
||||
os.mkdir("Supervisor Logs")
|
||||
os.makedirs("Supervisor Logs", exist_ok=True)
|
||||
os.chdir("Supervisor Logs")
|
||||
output_supervisor_1pg(parsed)
|
||||
|
||||
os.chdir("..")
|
||||
os.mkdir("Talent Scripts")
|
||||
os.makedirs("Talent Scripts", exist_ok=True)
|
||||
os.chdir("Talent Scripts")
|
||||
output_talent_sides(parsed)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from reportlab.pdfbase.pdfmetrics import (getAscent, getDescent)
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.pdfgen import canvas
|
||||
import datetime
|
||||
|
||||
from reportlab.platypus.doctemplate import BaseDocTemplate, Frame, PageTemplate
|
||||
|
||||
# This is from https://code.activestate.com/recipes/576832/ for
|
||||
# generating page count messages
|
||||
@@ -30,7 +30,8 @@ class ReportCanvas(canvas.Canvas):
|
||||
self.setFont("Futura", 10)
|
||||
self.drawString(0.5 * inch, 0.5 * inch, "Page %d of %d" % (self._pageNumber, page_count))
|
||||
right_edge = self._pagesize[0] - 0.5 * inch
|
||||
self.drawRightString(right_edge, 0.5 * inch, self._report_date.strftime("%c"))
|
||||
self.drawRightString(right_edge, 0.5 * inch, self._report_date.strftime("%m/%d/%Y %H:%M"))
|
||||
|
||||
top_line = self.beginPath()
|
||||
top_line.moveTo(0.5 * inch, 0.75 * inch)
|
||||
top_line.lineTo(right_edge, 0.75 * inch)
|
||||
@@ -39,6 +40,41 @@ class ReportCanvas(canvas.Canvas):
|
||||
self.restoreState()
|
||||
|
||||
|
||||
class ADRDocTemplate(BaseDocTemplate):
|
||||
def build(self, flowables, filename=None, canvasmaker=ReportCanvas):
|
||||
BaseDocTemplate.build(self, flowables, filename, canvasmaker)
|
||||
|
||||
|
||||
def make_doc_template(page_size, filename, document_title, record, document_header = ""):
|
||||
left_margin = right_margin = top_margin = bottom_margin = 0.5 * inch
|
||||
page_box = GRect(0., 0., page_size[0], page_size[1])
|
||||
_, page_box = page_box.split_x(left_margin, direction='r')
|
||||
_, page_box = page_box.split_x(right_margin, direction='l')
|
||||
_, page_box = page_box.split_y(bottom_margin, direction='u')
|
||||
_, page_box = page_box.split_y(top_margin, direction='d')
|
||||
|
||||
footer_box, page_box = page_box.split_y(0.25 * inch, direction='u')
|
||||
header_box, page_box = page_box.split_y(0.75 * inch, direction='d')
|
||||
title_box, report_box = header_box.split_x(4. * inch, direction='r')
|
||||
|
||||
page_template = PageTemplate(id="Main",
|
||||
frames=[Frame(page_box.min_x, page_box.min_y, page_box.width, page_box.height)],
|
||||
onPage=lambda c, _: draw_header_footer(c, title_box, report_box, footer_box, record,
|
||||
doc_title=document_header))
|
||||
|
||||
doc = ADRDocTemplate(filename,
|
||||
title=document_title,
|
||||
author=record.get('Supervisor', ""),
|
||||
pagesize=page_size,
|
||||
leftMargin=left_margin, rightMargin=right_margin,
|
||||
topMargin=top_margin, bottomMargin=bottom_margin)
|
||||
|
||||
doc.addPageTemplates([page_template])
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
|
||||
def time_format(mins):
|
||||
if mins < 60.:
|
||||
return "%im" % round(mins)
|
||||
@@ -48,12 +84,21 @@ def time_format(mins):
|
||||
return "%ih%im" % (hh, mm)
|
||||
|
||||
|
||||
# draws the title block inside the given rect
|
||||
def draw_title_block(a_canvas, rect, record):
|
||||
(supervisor, client,), title = rect.divide_y([16., 16., ])
|
||||
def draw_header_footer(a_canvas, title_box, doc_title_box, footer_box, record, doc_title=""):
|
||||
|
||||
(supervisor, client,), title = title_box.divide_y([16., 16., ])
|
||||
title.draw_text_cell(a_canvas, record['Title'], "Futura", 18, inset_y=2.)
|
||||
client.draw_text_cell(a_canvas, record.get('Client', ''), "Futura", 11, inset_y=2.)
|
||||
supervisor.draw_text_cell(a_canvas, record.get('Supervisor', ''), "Futura", 11, inset_y=2.)
|
||||
|
||||
(doc_title_cell, spotting_version_cell,), _ = doc_title_box.divide_y([18., 14], direction='d')
|
||||
|
||||
doc_title_cell.draw_text_cell(a_canvas, doc_title, 'Futura', 14., inset_y=2.)
|
||||
if 'Spot' in record.keys():
|
||||
spotting_version_cell.draw_text_cell(a_canvas, record['Spot'], 'Futura', 12., inset_y=2.)
|
||||
|
||||
a_canvas.setFont('Futura', 11.)
|
||||
a_canvas.drawCentredString(footer_box.min_x + footer_box.width / 2., footer_box.min_y,
|
||||
record.get('Supervisor', 'Supervisor: ________________'))
|
||||
|
||||
|
||||
class GRect:
|
||||
|
||||
@@ -4,13 +4,13 @@ from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.lib.pagesizes import letter
|
||||
from reportlab.lib.pagesizes import letter, landscape, portrait
|
||||
from reportlab.lib import colors
|
||||
|
||||
from reportlab.lib.styles import getSampleStyleSheet
|
||||
from reportlab.platypus import Paragraph, Table, TableStyle
|
||||
|
||||
from .common import GRect, time_format, NumberedCanvas
|
||||
from .common import GRect, time_format, ReportCanvas, make_doc_template
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -76,36 +76,36 @@ def build_columns(records, show_priorities = False):
|
||||
'heading': '>P5',
|
||||
'value_getter': lambda recs: blank_len([r for r in recs if r.get('Priority', 5) > 5]),
|
||||
'style_getter': lambda col_index: [],
|
||||
'width': 0.5 * inch
|
||||
'width': 0.375 * inch
|
||||
})
|
||||
|
||||
columns.append({
|
||||
'heading': 'TV',
|
||||
'value_getter': lambda recs: blank_len([r for r in recs if 'TV' in r.keys()]),
|
||||
'style_getter': lambda col_index: [],
|
||||
'width': 0.5 * inch
|
||||
'width': 0.375 * inch
|
||||
})
|
||||
|
||||
columns.append({
|
||||
'heading': 'OPT',
|
||||
'heading': 'Opt',
|
||||
'value_getter': lambda recs: blank_len([r for r in recs if 'Optional' in r.keys()]),
|
||||
'style_getter': lambda col_index: [],
|
||||
'width': 0.5 * inch
|
||||
'width': 0.375 * inch
|
||||
})
|
||||
|
||||
columns.append({
|
||||
'heading': 'EFF',
|
||||
'heading': 'Eff',
|
||||
'value_getter': lambda recs: blank_len([r for r in recs if 'Effort' in r.keys()]),
|
||||
'style_getter': lambda col_index: [],
|
||||
'width': 0.5 * inch
|
||||
'width': 0.375 * inch
|
||||
})
|
||||
|
||||
columns.append({
|
||||
'heading': 'Total',
|
||||
'value_getter': lambda recs: len([r for r in recs]),
|
||||
'value_getter': lambda recs: len([r for r in recs if 'Omitted' not in r.keys()]),
|
||||
'style_getter': lambda col_index: [(('LINEBEFORE'), (col_index, 0), (col_index, -1), 1.0, colors.black),
|
||||
('ALIGN', (col_index, 0), (col_index, -1), 'RIGHT')],
|
||||
'width': inch
|
||||
'width': 0.5 * inch
|
||||
})
|
||||
|
||||
columns.append({
|
||||
@@ -115,6 +115,13 @@ def build_columns(records, show_priorities = False):
|
||||
'width': inch
|
||||
})
|
||||
|
||||
# columns.append({
|
||||
# 'heading': 'Omit',
|
||||
# 'value_getter': lambda recs: blank_len([r for r in recs if 'Omitted' in r.keys()]),
|
||||
# 'style_getter': lambda col_index: [('LINEBEFORE', (col_index, 0), (col_index, -1), 1.0, colors.black)],
|
||||
# 'width': 0.5 * inch
|
||||
# })
|
||||
|
||||
return columns
|
||||
|
||||
|
||||
@@ -150,15 +157,6 @@ def populate_columns(records, columns):
|
||||
|
||||
|
||||
def output_report(records):
|
||||
# CN
|
||||
# Role
|
||||
# Actor
|
||||
# R1, R2, R3, R4, R5, R6
|
||||
# Opt
|
||||
# TV
|
||||
# EFF
|
||||
# Total
|
||||
|
||||
columns = build_columns(records)
|
||||
data, style, columns_widths = populate_columns(records, columns)
|
||||
style.append(('FONTNAME', [0, 0], (-1, -1), "Futura"))
|
||||
@@ -168,20 +166,28 @@ def output_report(records):
|
||||
|
||||
pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||
|
||||
page: GRect = GRect(0, 0, letter[1], letter[0])
|
||||
page = page.inset(inch * 0.5)
|
||||
title_box, table_box = page.split_y(inch, 'd')
|
||||
|
||||
c = NumberedCanvas('%s Line Count.pdf' % records['events'][0]['Title'], pagesize=(letter[1], letter[0]))
|
||||
c.setFont('Futura', 18.)
|
||||
c.drawCentredString(title_box.center_x, title_box.center_y, "Line Count")
|
||||
title = "%s Line Count" % (records['events'][0]['Title'])
|
||||
filename = title + '.pdf'
|
||||
doc = make_doc_template(portrait(letter), filename=filename,
|
||||
document_title=title,
|
||||
record=records['events'][0], document_header='Line Count')
|
||||
|
||||
# page: GRect = GRect(0, 0, letter[1], letter[0])
|
||||
# page = page.inset(inch * 0.5)
|
||||
# title_box, table_box = page.split_y(inch, 'd')
|
||||
#
|
||||
# c = ReportCanvas('%s Line Count.pdf' % records['events'][0]['Title'], pagesize=(letter[1], letter[0]))
|
||||
# c.setFont('Futura', 18.)
|
||||
# c.drawCentredString(title_box.center_x, title_box.center_y, "Line Count")
|
||||
#
|
||||
table = Table(data=data, style=style, colWidths=columns_widths)
|
||||
#
|
||||
# w, h = table.wrap(table_box.width, table_box.height)
|
||||
# table.drawOn(canvas=c,
|
||||
# x=table_box.min_x + table_box.width / 2. - w / 2.,
|
||||
# y=table_box.max_y - h)
|
||||
|
||||
w, h = table.wrap(table_box.width, table_box.height)
|
||||
table.drawOn(canvas=c,
|
||||
x=table_box.min_x + table_box.width / 2. - w / 2.,
|
||||
y=table_box.max_y - h)
|
||||
doc.build([table])
|
||||
|
||||
c.showPage()
|
||||
c.save()
|
||||
# c.showPage()
|
||||
# c.save()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from .common import GRect, draw_title_block, time_format, NumberedCanvas
|
||||
from .common import GRect, draw_header_footer, time_format, make_doc_template
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.lib.pagesizes import letter, landscape, portrait
|
||||
|
||||
@@ -86,28 +86,14 @@ def build_story(lines):
|
||||
|
||||
|
||||
def output_report(records):
|
||||
page_size = portrait(letter)
|
||||
page_box = GRect(inch * 0.5, inch * 0.5, page_size[0] - inch, page_size[1] - inch)
|
||||
title_box, page_box = page_box.split_y(0.875 * inch, 'd')
|
||||
footer_box, page_box = page_box.split_y(0.25 * inch, 'u')
|
||||
|
||||
title_block, header_block = title_box.split_x(inch * 4., direction='r')
|
||||
|
||||
pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||
|
||||
page_template = PageTemplate(id="Main",
|
||||
frames=[Frame(page_box.min_x, page_box.min_y, page_box.width, page_box.height)],
|
||||
onPage=lambda canvas, _: draw_title_block(canvas, title_block, lines[0]))
|
||||
|
||||
lines = sorted(records['events'], key=lambda line: line['PT.Clip.Start_Seconds'])
|
||||
|
||||
doc = BaseDocTemplate("%s Summary.pdf" % records['events'][0]['Title'],
|
||||
pagesize=page_size, leftMargin=0.5 * inch,
|
||||
rightMargin=0.5 * inch, topMargin=0.5 * inch,
|
||||
bottomMargin=0.5 * inch)
|
||||
title = "%s ADR Report" % (lines[0]['Title'])
|
||||
filename = title + ".pdf"
|
||||
|
||||
doc.addPageTemplates([page_template])
|
||||
doc = make_doc_template(portrait(letter), filename=filename, document_title=title,
|
||||
record=lines[0], document_header='ADR Report')
|
||||
|
||||
story = build_story(lines)
|
||||
|
||||
doc.build(story, canvasmaker=NumberedCanvas)
|
||||
doc.build(story)
|
||||
|
||||
@@ -9,7 +9,7 @@ from reportlab.lib.pagesizes import letter
|
||||
from reportlab.lib.styles import getSampleStyleSheet
|
||||
from reportlab.platypus import Paragraph
|
||||
|
||||
from .common import GRect, draw_title_block
|
||||
from .common import GRect
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -200,7 +200,11 @@ def create_report_for_character(records, report_date):
|
||||
(cue_number_block, timecode_block), reason_block = data_row.divide_x([1.5 * inch, 1.5 * inch])
|
||||
(take_grid_block), aux_block = takes_row.split_x(5.25 * inch)
|
||||
|
||||
c = Canvas(outfile, pagesize=letter)
|
||||
c = Canvas(outfile, pagesize=letter,)
|
||||
|
||||
c.setTitle("%s %s (%s) Supervisor's Log" % (records[0]['Title'], records[0]['Character Name'],
|
||||
records[0]['Character Number']))
|
||||
c.setAuthor(records[0]['Supervisor'])
|
||||
|
||||
recording_time_sec = 0.0
|
||||
total_lines = len(records)
|
||||
@@ -210,7 +214,8 @@ def create_report_for_character(records, report_date):
|
||||
recording_time_sec = recording_time_sec + recording_time_sec_this_line
|
||||
|
||||
draw_header_block(c, cue_header_block, record)
|
||||
draw_title_block(c, title_header_block, record)
|
||||
# FIXME: Draw the title
|
||||
#draw_title_box(c, title_header_block, record)
|
||||
draw_character_row(c, char_row, record)
|
||||
draw_cue_number_block(c, cue_number_block, record)
|
||||
draw_timecode_block(c, timecode_block, record)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from .common import GRect, draw_title_block, NumberedCanvas
|
||||
from .common import GRect, draw_header_footer, ReportCanvas, make_doc_template
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.lib.pagesizes import letter
|
||||
|
||||
@@ -11,10 +11,10 @@ from reportlab.lib import colors
|
||||
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
|
||||
page_box = GRect(inch * 0.5, inch * 0.5, letter[0] - inch, letter[1] - inch)
|
||||
title_box, page_box = page_box.split_y(0.875 * inch, 'd')
|
||||
header_block, title_block = title_box.split_x(inch * 4.)
|
||||
#
|
||||
# page_box = GRect(inch * 0.5, inch * 0.5, letter[0] - inch, letter[1] - inch)
|
||||
# title_box, page_box = page_box.split_y(0.875 * inch, 'd')
|
||||
# header_block, title_block = title_box.split_x(inch * 4.)
|
||||
|
||||
|
||||
def output_report(records):
|
||||
@@ -25,17 +25,14 @@ def output_report(records):
|
||||
lines = [line for line in records['events']
|
||||
if 'Omit' not in line.keys() and line['Character Number'] == n]
|
||||
|
||||
page_template = PageTemplate(id="Main",
|
||||
frames=[Frame(page_box.min_x, page_box.min_y, page_box.width, page_box.height)],
|
||||
onPage=lambda canv, _: draw_title_block(canv, title_block, lines[0]))
|
||||
|
||||
sorted(lines, key=lambda line: line['PT.Clip.Start_Seconds'])
|
||||
|
||||
doc = BaseDocTemplate("%s_%s_%s_Script.pdf" % (lines[0]['Title'], n, lines[0]['Character Name']),
|
||||
pagesize=letter, leftMargin=0.5 * inch,
|
||||
rightMargin=0.5 * inch, topMargin=0.5 * inch, bottomMargin=0.5 * inch)
|
||||
title = "%s (%s) %s ADR Script" % (lines[0]['Title'], lines[0]['Character Name'], n)
|
||||
filename = "%s_%s_%s_ADR Script.pdf" % (lines[0]['Title'], n, lines[0]['Character Name'])
|
||||
|
||||
doc = make_doc_template(page_size=letter, filename=filename, document_title=title,
|
||||
record=lines[0], document_header=lines[0]['Character Name'])
|
||||
|
||||
doc.addPageTemplates([page_template])
|
||||
story = []
|
||||
|
||||
prompt_style = getSampleStyleSheet()['Normal']
|
||||
@@ -58,7 +55,7 @@ def output_report(records):
|
||||
data_block = [[Paragraph(line['Cue Number'], number_style),
|
||||
Paragraph(line['PT.Clip.Start'] + " - " + line['PT.Clip.Finish'], number_style)
|
||||
]]
|
||||
# RIGHTWARDS ARRO→W
|
||||
# RIGHTWARDS ARROW →
|
||||
# Unicode: U+2192, UTF-8: E2 86 92
|
||||
story.append(
|
||||
KeepTogether(
|
||||
@@ -69,4 +66,4 @@ def output_report(records):
|
||||
)
|
||||
)
|
||||
|
||||
doc.build(story, canvasmaker=NumberedCanvas)
|
||||
doc.build(story)
|
||||
|
||||
Reference in New Issue
Block a user