201 lines
7.0 KiB
Python
201 lines
7.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
from docx import Document
|
|
from docx.shared import Pt, Cm, RGBColor
|
|
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
|
from docx.enum.table import WD_TABLE_ALIGNMENT
|
|
from docx.oxml.ns import qn
|
|
from docx.oxml import OxmlElement
|
|
|
|
OUT = 'Метод_Дегтярева_гайд_интервью.docx'
|
|
|
|
GREEN = RGBColor(0x2E, 0x7D, 0x5B)
|
|
ROSE = RGBColor(0xB0, 0x3A, 0x55)
|
|
DARK = RGBColor(0x1A, 0x1A, 0x1A)
|
|
GRAY = RGBColor(0x5F, 0x66, 0x6B)
|
|
LIGHT = RGBColor(0x8A, 0x90, 0x95)
|
|
|
|
|
|
def set_run(run, name='Arial', size=9, bold=False, italic=False, color=DARK):
|
|
run.font.name = name
|
|
run.font.size = Pt(size)
|
|
run.font.bold = bold
|
|
run.font.italic = italic
|
|
run.font.color.rgb = color
|
|
rPr = run._element.get_or_add_rPr()
|
|
rFonts = rPr.find(qn('w:rFonts'))
|
|
if rFonts is None:
|
|
rFonts = OxmlElement('w:rFonts')
|
|
rPr.append(rFonts)
|
|
for attr in ('w:ascii', 'w:hAnsi', 'w:eastAsia', 'w:cs'):
|
|
rFonts.set(qn(attr), name)
|
|
|
|
|
|
def cell_margins(table, top=80, bottom=80, left=180, right=180):
|
|
tblPr = table._tbl.tblPr
|
|
mar = OxmlElement('w:tblCellMar')
|
|
for tag, val in (('top', top), ('left', left), ('bottom', bottom), ('right', right)):
|
|
el = OxmlElement('w:' + tag)
|
|
el.set(qn('w:w'), str(val))
|
|
el.set(qn('w:type'), 'dxa')
|
|
mar.append(el)
|
|
tblPr.append(mar)
|
|
|
|
|
|
def add_line_table(cell, lines=4, width_cm=17.5, height_cm=0.6):
|
|
tbl = cell.add_table(rows=lines, cols=1)
|
|
tbl.autofit = False
|
|
tblPr = tbl._tbl.tblPr
|
|
borders = OxmlElement('w:tblBorders')
|
|
for edge in ('top', 'left', 'bottom', 'right', 'insideH', 'insideV'):
|
|
el = OxmlElement('w:' + edge)
|
|
el.set(qn('w:val'), 'none')
|
|
borders.append(el)
|
|
tblPr.append(borders)
|
|
for row in tbl.rows:
|
|
row.height = Cm(height_cm)
|
|
c = row.cells[0]
|
|
c.width = Cm(width_cm)
|
|
tcPr = c._tc.get_or_add_tcPr()
|
|
tcBorders = OxmlElement('w:tcBorders')
|
|
bottom = OxmlElement('w:bottom')
|
|
bottom.set(qn('w:val'), 'dotted')
|
|
bottom.set(qn('w:sz'), '4')
|
|
bottom.set(qn('w:space'), '0')
|
|
bottom.set(qn('w:color'), 'AFC4B9')
|
|
tcBorders.append(bottom)
|
|
tcPr.append(tcBorders)
|
|
p = c.paragraphs[0]
|
|
p.paragraph_format.space_before = Pt(0)
|
|
p.paragraph_format.space_after = Pt(0)
|
|
p.paragraph_format.line_spacing = 1.0
|
|
|
|
|
|
def card_border(cell):
|
|
tcPr = cell._tc.get_or_add_tcPr()
|
|
tcBorders = OxmlElement('w:tcBorders')
|
|
for edge in ('top', 'left', 'bottom', 'right'):
|
|
el = OxmlElement('w:' + edge)
|
|
el.set(qn('w:val'), 'single')
|
|
el.set(qn('w:sz'), '14' if edge == 'top' else '4')
|
|
el.set(qn('w:space'), '0')
|
|
el.set(qn('w:color'), '2E7D5B' if edge == 'top' else 'C9D6CF')
|
|
tcBorders.append(el)
|
|
tcPr.append(tcBorders)
|
|
|
|
|
|
def add_card(cell):
|
|
cell.text = ''
|
|
card_border(cell)
|
|
|
|
p = cell.paragraphs[0]
|
|
p.paragraph_format.space_before = Pt(0)
|
|
p.paragraph_format.space_after = Pt(0)
|
|
r = p.add_run('ГАЙД ИНТЕРВЬЮ')
|
|
set_run(r, name='Georgia', size=15, bold=True, color=GREEN)
|
|
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(1)
|
|
p.paragraph_format.space_after = Pt(1)
|
|
r = p.add_run('Шаг 1. «Забой» • Метод Дегтярева')
|
|
set_run(r, size=8, bold=True, color=GRAY)
|
|
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(0)
|
|
p.paragraph_format.space_after = Pt(4)
|
|
r = p.add_run('Команда: ______________________________')
|
|
set_run(r, size=8, color=GRAY)
|
|
|
|
questions = [
|
|
'Расскажите, как вы в последний раз решали эту задачу?',
|
|
'Что в этом процессе было самым неприятным? Почему?',
|
|
'Что вы сделали, чтобы это обойти?',
|
|
'Сколько времени, денег или сил это у вас забрало?',
|
|
'Кто ещё с этим сталкивается?',
|
|
'Что происходит, если проблему не решить?',
|
|
'Если бы это исчезло, что бы изменилось?',
|
|
]
|
|
for i, q in enumerate(questions, 1):
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(0)
|
|
p.paragraph_format.space_after = Pt(1)
|
|
p.paragraph_format.left_indent = Cm(0.5)
|
|
p.paragraph_format.first_line_indent = Cm(-0.5)
|
|
p.paragraph_format.line_spacing = 1.0
|
|
r = p.add_run(f'{i}. ')
|
|
set_run(r, size=9, bold=True, color=GREEN)
|
|
r = p.add_run(q)
|
|
set_run(r, size=9, color=DARK)
|
|
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(4)
|
|
p.paragraph_format.space_after = Pt(1)
|
|
r = p.add_run('ПРАВИЛА')
|
|
set_run(r, size=8, bold=True, color=ROSE)
|
|
|
|
rules = [
|
|
'Спрашивайте о прошлом, а не о будущем.',
|
|
'Не презентуйте свою идею — слушайте.',
|
|
'Записывайте точные цитаты.',
|
|
'Ищите повторяемость, а не яркие истории.',
|
|
'Минимум 5 интервью, лучше 10.',
|
|
]
|
|
for rule in rules:
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(0)
|
|
p.paragraph_format.space_after = Pt(0)
|
|
p.paragraph_format.left_indent = Cm(0.45)
|
|
p.paragraph_format.first_line_indent = Cm(-0.45)
|
|
p.paragraph_format.line_spacing = 1.0
|
|
r = p.add_run('• ')
|
|
set_run(r, size=8, color=ROSE)
|
|
r = p.add_run(rule)
|
|
set_run(r, size=8, color=GRAY)
|
|
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(4)
|
|
p.paragraph_format.space_after = Pt(1)
|
|
r = p.add_run('ЗАМЕТКИ')
|
|
set_run(r, size=8, bold=True, color=GREEN)
|
|
add_line_table(cell, lines=4, width_cm=17.5, height_cm=0.6)
|
|
|
|
p = cell.add_paragraph()
|
|
p.paragraph_format.space_before = Pt(2)
|
|
p.paragraph_format.space_after = Pt(0)
|
|
r = p.add_run('5 интервью — минимум. Спрашивайте о прошлом, не о будущем.')
|
|
set_run(r, size=7, italic=True, color=LIGHT)
|
|
|
|
|
|
def build():
|
|
doc = Document()
|
|
section = doc.sections[0]
|
|
section.page_width = Cm(21.0)
|
|
section.page_height = Cm(29.7)
|
|
section.top_margin = Cm(1.0)
|
|
section.bottom_margin = Cm(1.0)
|
|
section.left_margin = Cm(1.0)
|
|
section.right_margin = Cm(1.0)
|
|
|
|
normal = doc.styles['Normal']
|
|
normal.font.name = 'Arial'
|
|
normal.font.size = Pt(9)
|
|
normal.font.color.rgb = DARK
|
|
|
|
for page in range(4):
|
|
table = doc.add_table(rows=2, cols=1)
|
|
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
|
table.autofit = False
|
|
cell_margins(table)
|
|
for row in table.rows:
|
|
row.height = Cm(13.2)
|
|
row.cells[0].width = Cm(19.0)
|
|
add_card(row.cells[0])
|
|
if page < 3:
|
|
doc.add_page_break()
|
|
|
|
doc.save(OUT)
|
|
print('saved', OUT)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
build()
|