mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2026-01-01 09:20:49 +00:00
flake8
This commit is contained in:
@@ -4,7 +4,7 @@ from typing import Tuple, List
|
||||
from reportlab.lib.pagesizes import portrait, letter
|
||||
from reportlab.lib.styles import getSampleStyleSheet
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.platypus import Paragraph, Table, Spacer
|
||||
from reportlab.platypus import Paragraph, Table
|
||||
|
||||
from ptulsconv.broadcast_timecode import TimecodeFormat
|
||||
from ptulsconv.pdf import make_doc_template
|
||||
@@ -12,14 +12,15 @@ from ptulsconv.pdf import make_doc_template
|
||||
|
||||
# TODO: A Continuity
|
||||
|
||||
def table_for_scene(scene, tc_format, font_name = 'Helvetica'):
|
||||
def table_for_scene(scene, tc_format, font_name='Helvetica'):
|
||||
scene_style = getSampleStyleSheet()['Normal']
|
||||
scene_style.fontName = font_name
|
||||
scene_style.leftIndent = 0.
|
||||
scene_style.leftPadding = 0.
|
||||
scene_style.spaceAfter = 18.
|
||||
|
||||
tc_data = "<em>%s</em><br />%s" % (tc_format.seconds_to_smpte(scene[2]), tc_format.seconds_to_smpte(scene[3]))
|
||||
tc_data = "<em>%s</em><br />%s" % (tc_format.seconds_to_smpte(scene[2]),
|
||||
tc_format.seconds_to_smpte(scene[3]))
|
||||
|
||||
row = [
|
||||
Paragraph(tc_data, scene_style),
|
||||
@@ -36,7 +37,7 @@ def table_for_scene(scene, tc_format, font_name = 'Helvetica'):
|
||||
|
||||
def output_report(scenes: List[Tuple[str, str, Fraction, Fraction]],
|
||||
tc_display_format: TimecodeFormat,
|
||||
title: str, client: str, supervisor, paper_size = letter):
|
||||
title: str, client: str, supervisor, paper_size=letter):
|
||||
filename = "%s Continuity.pdf" % title
|
||||
document_header = "Continuity"
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@ from .__init__ import time_format, make_doc_template
|
||||
from ..docparser.adr_entity import ADRLine
|
||||
|
||||
|
||||
def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]], show_priorities=False, include_omitted=False):
|
||||
def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]],
|
||||
show_priorities=False, include_omitted=False):
|
||||
columns = list()
|
||||
reel_numbers = reel_list or sorted(set([x.reel for x in lines if x.reel is not None]))
|
||||
reel_numbers = reel_list or sorted(
|
||||
set([x.reel for x in lines if x.reel is not None])
|
||||
)
|
||||
|
||||
num_column_width = 15. / 32. * inch
|
||||
|
||||
@@ -33,19 +36,26 @@ def build_columns(lines: List[ADRLine], reel_list: Optional[List[str]], show_pri
|
||||
'heading': 'Role',
|
||||
'value_getter': lambda recs: recs[0].character_name,
|
||||
'value_getter2': lambda recs: recs[0].actor_name or "",
|
||||
'style_getter': lambda col_index: [('LINEAFTER', (col_index, 0), (col_index, -1), 1.0, colors.black)],
|
||||
'style_getter': lambda col_index: [('LINEAFTER',
|
||||
(col_index, 0),
|
||||
(col_index, -1),
|
||||
1.0, colors.black)],
|
||||
'width': 1.75 * inch,
|
||||
'summarize': False
|
||||
})
|
||||
|
||||
columns.append({
|
||||
'heading': 'TV',
|
||||
'value_getter': lambda recs: len([r for r in recs if r.tv]),
|
||||
'value_getter2': lambda recs: time_format(sum([r.time_budget_mins or 0.
|
||||
for r in recs if r.tv])),
|
||||
'style_getter': lambda col_index: [('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
|
||||
('LINEBEFORE', (col_index, 0), (col_index, -1), 1., colors.black),
|
||||
('LINEAFTER', (col_index, 0), (col_index, -1), .5, colors.gray)],
|
||||
'value_getter': (lambda recs: len([r for r in recs if r.tv])),
|
||||
'value_getter2': (lambda recs:
|
||||
time_format(sum([r.time_budget_mins or 0.
|
||||
for r in recs if r.tv]))),
|
||||
'style_getter': (lambda col_index:
|
||||
[('ALIGN', (col_index, 0), (col_index, -1), 'CENTER'),
|
||||
('LINEBEFORE', (col_index, 0), (col_index, -1),
|
||||
1., colors.black),
|
||||
('LINEAFTER', (col_index, 0), (col_index, -1),
|
||||
.5, colors.gray)]),
|
||||
'width': num_column_width
|
||||
})
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from reportlab.pdfgen.canvas import Canvas
|
||||
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
# from reportlab.pdfbase import pdfmetrics
|
||||
# from reportlab.pdfbase.ttfonts import TTFont
|
||||
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.lib.pagesizes import letter
|
||||
@@ -11,20 +11,23 @@ from reportlab.platypus import Paragraph
|
||||
|
||||
from .__init__ import GRect
|
||||
|
||||
from ptulsconv.broadcast_timecode import TimecodeFormat, footage_to_frame_count
|
||||
from ptulsconv.broadcast_timecode import TimecodeFormat
|
||||
from ptulsconv.docparser.adr_entity import ADRLine
|
||||
|
||||
import datetime
|
||||
|
||||
font_name = 'Helvetica'
|
||||
|
||||
|
||||
def draw_header_block(canvas, rect, record: ADRLine):
|
||||
rect.draw_text_cell(canvas, record.cue_number, "Helvetica", 44, vertical_align='m')
|
||||
rect.draw_text_cell(canvas, record.cue_number, "Helvetica", 44,
|
||||
vertical_align='m')
|
||||
|
||||
|
||||
def draw_character_row(canvas, rect, record: ADRLine):
|
||||
label_frame, value_frame = rect.split_x(1.25 * inch)
|
||||
label_frame.draw_text_cell(canvas, "CHARACTER", font_name, 10, force_baseline=9.)
|
||||
label_frame.draw_text_cell(canvas, "CHARACTER", font_name, 10,
|
||||
force_baseline=9.)
|
||||
line = "%s / %s" % (record.character_id, record.character_name)
|
||||
if record.actor_name is not None:
|
||||
line = line + " / " + record.actor_name
|
||||
@@ -33,7 +36,8 @@ def draw_character_row(canvas, rect, record: ADRLine):
|
||||
|
||||
|
||||
def draw_cue_number_block(canvas, rect, record: ADRLine):
|
||||
(label_frame, number_frame,), aux_frame = rect.divide_y([0.20 * inch, 0.375 * inch], direction='d')
|
||||
(label_frame, number_frame,), aux_frame = \
|
||||
rect.divide_y([0.20 * inch, 0.375 * inch], direction='d')
|
||||
label_frame.draw_text_cell(canvas, "CUE NUMBER", font_name, 10,
|
||||
inset_y=5., vertical_align='t')
|
||||
number_frame.draw_text_cell(canvas, record.cue_number, font_name, 14,
|
||||
@@ -55,18 +59,25 @@ def draw_cue_number_block(canvas, rect, record: ADRLine):
|
||||
rect.draw_border(canvas, 'max_x')
|
||||
|
||||
|
||||
def draw_timecode_block(canvas, rect, record: ADRLine, tc_display_format: TimecodeFormat):
|
||||
def draw_timecode_block(canvas, rect, record: ADRLine,
|
||||
tc_display_format: TimecodeFormat):
|
||||
(in_label_frame, in_frame, out_label_frame, out_frame), _ = rect.divide_y(
|
||||
[0.20 * inch, 0.25 * inch, 0.20 * inch, 0.25 * inch], direction='d')
|
||||
|
||||
in_label_frame.draw_text_cell(canvas, "IN", font_name, 10,
|
||||
vertical_align='t', inset_y=5., inset_x=5.)
|
||||
in_frame.draw_text_cell(canvas, tc_display_format.seconds_to_smpte(record.start), font_name, 14,
|
||||
inset_x=10., inset_y=2., draw_baseline=True)
|
||||
in_frame.draw_text_cell(canvas,
|
||||
tc_display_format.seconds_to_smpte(record.start),
|
||||
font_name, 14,
|
||||
inset_x=10., inset_y=2.,
|
||||
draw_baseline=True)
|
||||
out_label_frame.draw_text_cell(canvas, "OUT", font_name, 10,
|
||||
vertical_align='t', inset_y=5., inset_x=5.)
|
||||
out_frame.draw_text_cell(canvas, tc_display_format.seconds_to_smpte(record.finish), font_name, 14,
|
||||
inset_x=10., inset_y=2., draw_baseline=True)
|
||||
out_frame.draw_text_cell(canvas,
|
||||
tc_display_format.seconds_to_smpte(record.finish),
|
||||
font_name, 14,
|
||||
inset_x=10., inset_y=2.,
|
||||
draw_baseline=True)
|
||||
|
||||
rect.draw_border(canvas, 'max_x')
|
||||
|
||||
@@ -91,13 +102,15 @@ def draw_reason_block(canvas, rect, record: ADRLine):
|
||||
|
||||
p = Paragraph(record.note or "", style)
|
||||
|
||||
notes_value.draw_flowable(canvas, p, draw_baselines=True, inset_x=5., inset_y=5.)
|
||||
notes_value.draw_flowable(canvas, p, draw_baselines=True,
|
||||
inset_x=5., inset_y=5.)
|
||||
|
||||
|
||||
def draw_prompt(canvas, rect, prompt=""):
|
||||
label, block = rect.split_y(0.20 * inch, direction='d')
|
||||
|
||||
label.draw_text_cell(canvas, "PROMPT", font_name, 10, vertical_align='t', inset_y=5., inset_x=0.)
|
||||
label.draw_text_cell(canvas, "PROMPT", font_name, 10, vertical_align='t',
|
||||
inset_y=5., inset_x=0.)
|
||||
|
||||
style = getSampleStyleSheet()['BodyText']
|
||||
style.fontName = font_name
|
||||
@@ -117,7 +130,8 @@ def draw_prompt(canvas, rect, prompt=""):
|
||||
def draw_notes(canvas, rect, note=""):
|
||||
label, block = rect.split_y(0.20 * inch, direction='d')
|
||||
|
||||
label.draw_text_cell(canvas, "NOTES", font_name, 10, vertical_align='t', inset_y=5., inset_x=0.)
|
||||
label.draw_text_cell(canvas, "NOTES", font_name, 10, vertical_align='t',
|
||||
inset_y=5., inset_x=0.)
|
||||
|
||||
style = getSampleStyleSheet()['BodyText']
|
||||
style.fontName = font_name
|
||||
@@ -169,31 +183,43 @@ def draw_take_grid(canvas, rect):
|
||||
canvas.restoreState()
|
||||
|
||||
|
||||
def draw_aux_block(canvas, rect, recording_time_sec_this_line, recording_time_sec):
|
||||
def draw_aux_block(canvas, rect, recording_time_sec_this_line,
|
||||
recording_time_sec):
|
||||
rect.draw_border(canvas, 'min_x')
|
||||
|
||||
content_rect = rect.inset_xy(10., 10.)
|
||||
lines, last_line = content_rect.divide_y([12., 12., 24., 24., 24., 24.], direction='d')
|
||||
lines, last_line = content_rect.divide_y([12., 12., 24., 24., 24., 24.],
|
||||
direction='d')
|
||||
|
||||
lines[0].draw_text_cell(canvas,
|
||||
"Time for this line: %.1f mins" % (recording_time_sec_this_line / 60.), font_name, 9.)
|
||||
lines[1].draw_text_cell(canvas, "Running time: %03.1f mins" % (recording_time_sec / 60.), font_name, 9.)
|
||||
lines[2].draw_text_cell(canvas, "Actual Start: ______________", font_name, 9., vertical_align='b')
|
||||
lines[3].draw_text_cell(canvas, "Record Date: ______________", font_name, 9., vertical_align='b')
|
||||
lines[4].draw_text_cell(canvas, "Engineer: ______________", font_name, 9., vertical_align='b')
|
||||
lines[5].draw_text_cell(canvas, "Location: ______________", font_name, 9., vertical_align='b')
|
||||
"Time for this line: %.1f mins" %
|
||||
(recording_time_sec_this_line / 60.),
|
||||
font_name, 9.)
|
||||
lines[1].draw_text_cell(canvas, "Running time: %03.1f mins" %
|
||||
(recording_time_sec / 60.), font_name, 9.)
|
||||
lines[2].draw_text_cell(canvas, "Actual Start: ______________",
|
||||
font_name, 9., vertical_align='b')
|
||||
lines[3].draw_text_cell(canvas, "Record Date: ______________",
|
||||
font_name, 9., vertical_align='b')
|
||||
lines[4].draw_text_cell(canvas, "Engineer: ______________",
|
||||
font_name, 9., vertical_align='b')
|
||||
lines[5].draw_text_cell(canvas, "Location: ______________",
|
||||
font_name, 9., vertical_align='b')
|
||||
|
||||
|
||||
def draw_footer(canvas, rect, record: ADRLine, report_date, line_no, total_lines):
|
||||
def draw_footer(canvas, rect, record: ADRLine, report_date, line_no,
|
||||
total_lines):
|
||||
rect.draw_border(canvas, 'max_y')
|
||||
report_date_s = [report_date.strftime("%c")]
|
||||
spotting_name = [record.spot] if record.spot is not None else []
|
||||
pages_s = ["Line %i of %i" % (line_no, total_lines)]
|
||||
footer_s = " - ".join(report_date_s + spotting_name + pages_s)
|
||||
rect.draw_text_cell(canvas, footer_s, font_name=font_name, font_size=10., inset_y=2.)
|
||||
rect.draw_text_cell(canvas, footer_s, font_name=font_name, font_size=10.,
|
||||
inset_y=2.)
|
||||
|
||||
|
||||
def create_report_for_character(records, report_date, tc_display_format: TimecodeFormat):
|
||||
def create_report_for_character(records, report_date,
|
||||
tc_display_format: TimecodeFormat):
|
||||
|
||||
outfile = "%s_%s_%s_Log.pdf" % (records[0].title,
|
||||
records[0].character_id,
|
||||
@@ -201,20 +227,24 @@ def create_report_for_character(records, report_date, tc_display_format: Timecod
|
||||
assert outfile is not None
|
||||
assert outfile[-4:] == '.pdf', "Output file must have 'pdf' extension!"
|
||||
|
||||
#pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||
# pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||
|
||||
page: GRect = GRect(0, 0, letter[0], letter[1])
|
||||
page = page.inset(inch * 0.5)
|
||||
(header_row, char_row, data_row, prompt_row, notes_row, takes_row), footer = \
|
||||
page.divide_y([0.875 * inch, 0.375 * inch, inch, 3.0 * inch, 1.5 * inch, 3 * inch], direction='d')
|
||||
(header_row, char_row, data_row,
|
||||
prompt_row, notes_row, takes_row), footer = \
|
||||
page.divide_y([0.875 * inch, 0.375 * inch, inch,
|
||||
3.0 * inch, 1.5 * inch, 3 * inch], direction='d')
|
||||
|
||||
cue_header_block, title_header_block = header_row.split_x(4.0 * inch)
|
||||
(cue_number_block, timecode_block), reason_block = data_row.divide_x([1.5 * inch, 1.5 * inch])
|
||||
(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.setTitle("%s %s (%s) Supervisor's Log" % (records[0].title, records[0].character_name,
|
||||
c.setTitle("%s %s (%s) Supervisor's Log" % (records[0].title,
|
||||
records[0].character_name,
|
||||
records[0].character_id))
|
||||
c.setAuthor(records[0].supervisor)
|
||||
|
||||
@@ -223,7 +253,8 @@ def create_report_for_character(records, report_date, tc_display_format: Timecod
|
||||
line_n = 1
|
||||
for record in records:
|
||||
record: ADRLine
|
||||
recording_time_sec_this_line: float = (record.time_budget_mins or 6.0) * 60.0
|
||||
recording_time_sec_this_line: float = (
|
||||
record.time_budget_mins or 6.0) * 60.0
|
||||
recording_time_sec = recording_time_sec + recording_time_sec_this_line
|
||||
|
||||
draw_header_block(c, cue_header_block, record)
|
||||
@@ -233,14 +264,17 @@ def create_report_for_character(records, report_date, tc_display_format: Timecod
|
||||
# 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, tc_display_format=tc_display_format)
|
||||
draw_timecode_block(c, timecode_block, record,
|
||||
tc_display_format=tc_display_format)
|
||||
draw_reason_block(c, reason_block, record)
|
||||
draw_prompt(c, prompt_row, prompt=record.prompt)
|
||||
draw_prompt(c, prompt_row, prompt=record.prompt or "")
|
||||
draw_notes(c, notes_row, note="")
|
||||
draw_take_grid(c, take_grid_block)
|
||||
draw_aux_block(c, aux_block, recording_time_sec_this_line, recording_time_sec)
|
||||
draw_aux_block(c, aux_block, recording_time_sec_this_line,
|
||||
recording_time_sec)
|
||||
|
||||
draw_footer(c, footer, record, report_date, line_no=line_n, total_lines=total_lines)
|
||||
draw_footer(c, footer, record, report_date, line_no=line_n,
|
||||
total_lines=total_lines)
|
||||
line_n = line_n + 1
|
||||
|
||||
c.showPage()
|
||||
@@ -254,5 +288,6 @@ def output_report(lines, tc_display_format: TimecodeFormat):
|
||||
character_numbers = set([x.character_id for x in lines])
|
||||
|
||||
for n in character_numbers:
|
||||
create_report_for_character([e for e in events if e.character_id == n], report_date,
|
||||
create_report_for_character([e for e in events if e.character_id == n],
|
||||
report_date,
|
||||
tc_display_format=tc_display_format)
|
||||
|
||||
@@ -5,36 +5,42 @@ from .__init__ import make_doc_template
|
||||
from reportlab.lib.units import inch
|
||||
from reportlab.lib.pagesizes import letter
|
||||
|
||||
from reportlab.platypus import Paragraph, Spacer, KeepTogether, Table, HRFlowable
|
||||
from reportlab.platypus import Paragraph, Spacer, KeepTogether, Table,\
|
||||
HRFlowable
|
||||
from reportlab.lib.styles import getSampleStyleSheet
|
||||
from reportlab.lib import colors
|
||||
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
# from reportlab.pdfbase import pdfmetrics
|
||||
# from reportlab.pdfbase.ttfonts import TTFont
|
||||
|
||||
from ..broadcast_timecode import TimecodeFormat
|
||||
from ..docparser.adr_entity import ADRLine
|
||||
|
||||
|
||||
def output_report(lines: List[ADRLine], tc_display_format: TimecodeFormat, font_name="Helvetica"):
|
||||
def output_report(lines: List[ADRLine], tc_display_format: TimecodeFormat,
|
||||
font_name="Helvetica"):
|
||||
character_numbers = set([n.character_id for n in lines])
|
||||
#pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||
# pdfmetrics.registerFont(TTFont('Futura', 'Futura.ttc'))
|
||||
|
||||
for n in character_numbers:
|
||||
char_lines = [line for line in lines if not line.omitted and line.character_id == n]
|
||||
char_lines = [line for line in lines
|
||||
if not line.omitted and line.character_id == n]
|
||||
character_name = char_lines[0].character_name
|
||||
|
||||
char_lines = sorted(char_lines, key=lambda line: line.start)
|
||||
|
||||
title = "%s (%s) %s ADR Script" % (char_lines[0].title, character_name, n)
|
||||
filename = "%s_%s_%s_ADR Script.pdf" % (char_lines[0].title, n, character_name)
|
||||
title = "%s (%s) %s ADR Script" % (char_lines[0].title,
|
||||
character_name, n)
|
||||
filename = "%s_%s_%s_ADR Script.pdf" % (char_lines[0].title,
|
||||
n, character_name)
|
||||
|
||||
doc = make_doc_template(page_size=letter, filename=filename, document_title=title,
|
||||
doc = make_doc_template(page_size=letter, filename=filename,
|
||||
document_title=title,
|
||||
title=char_lines[0].title,
|
||||
document_subheader=char_lines[0].spot,
|
||||
supervisor=char_lines[0].supervisor,
|
||||
client=char_lines[0].client,
|
||||
document_header=character_name)
|
||||
document_subheader=char_lines[0].spot or "",
|
||||
supervisor=char_lines[0].supervisor or "",
|
||||
client=char_lines[0].client or "",
|
||||
document_header=character_name or "")
|
||||
|
||||
story = []
|
||||
|
||||
@@ -58,7 +64,8 @@ def output_report(lines: List[ADRLine], tc_display_format: TimecodeFormat, font_
|
||||
start_tc = tc_display_format.seconds_to_smpte(line.start)
|
||||
finish_tc = tc_display_format.seconds_to_smpte(line.finish)
|
||||
data_block = [[Paragraph(line.cue_number, number_style),
|
||||
Paragraph(start_tc + " - " + finish_tc, number_style)
|
||||
Paragraph(start_tc + " - " + finish_tc,
|
||||
number_style)
|
||||
]]
|
||||
|
||||
# RIGHTWARDS ARROW →
|
||||
|
||||
Reference in New Issue
Block a user