Files
fmd26/build_problem_card.py
T

255 lines
9.4 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 shade(cell, hex_color):
tcPr = cell._tc.get_or_add_tcPr()
shd = OxmlElement('w:shd')
shd.set(qn('w:val'), 'clear')
shd.set(qn('w:color'), 'auto')
shd.set(qn('w:fill'), hex_color)
tcPr.append(shd)
def cell_margins(table, top=70, bottom=70, left=110, right=110):
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 table_borders(table, color='C9D6CF', size=6):
tblPr = table._tbl.tblPr
borders = OxmlElement('w:tblBorders')
for edge in ('top', 'left', 'bottom', 'right', 'insideH', 'insideV'):
el = OxmlElement('w:' + edge)
el.set(qn('w:val'), 'single')
el.set(qn('w:sz'), str(size))
el.set(qn('w:space'), '0')
el.set(qn('w:color'), color)
borders.append(el)
tblPr.append(borders)
def add_line_table(cell, lines=2, width_cm=8.0, height_cm=0.5):
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 add_block(cell, num, title, prompt, color=GREEN, fill='F3F9F6', lines=2, width_cm=8.0):
cell.text = ''
shade(cell, fill)
p = cell.paragraphs[0]
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(1)
r = p.add_run(num + ' ')
set_run(r, size=7.5, bold=True, color=color)
r = p.add_run(title)
set_run(r, size=9.5, bold=True, color=color)
p = cell.add_paragraph()
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(3)
p.paragraph_format.line_spacing = 1.0
r = p.add_run(prompt)
set_run(r, size=7.5, color=GRAY)
add_line_table(cell, lines=lines, width_cm=width_cm, height_cm=0.5)
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.3)
section.bottom_margin = Cm(1.1)
section.left_margin = Cm(1.4)
section.right_margin = Cm(1.4)
normal = doc.styles['Normal']
normal.font.name = 'Arial'
normal.font.size = Pt(9)
normal.font.color.rgb = DARK
# Header
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(0)
r = p.add_run('КАРТА ПРОБЛЕМЫ')
set_run(r, name='Georgia', size=20, bold=True, color=GREEN)
p = doc.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=9, bold=True, color=GRAY)
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(5)
r = p.add_run('Команда: ______________________________ Проблемное поле: ______________________________________')
set_run(r, size=8.5, color=GRAY)
# Main table
table = doc.add_table(rows=7, cols=2)
table.alignment = WD_TABLE_ALIGNMENT.CENTER
table.autofit = False
table_borders(table)
cell_margins(table)
heights = [3.0, 3.0, 3.0, 1.8, 3.8, 3.2, 2.8]
for i, row in enumerate(table.rows):
row.height = Cm(heights[i])
for cell in row.cells:
cell.width = Cm(9.0)
# Rows 0-2: two columns
blocks = [
('01', 'КТО?', 'Конкретная группа. Не «люди», а кто именно.', 0, 0),
('02', 'КОГДА И ГДЕ?', 'Контекст: в какой момент и в каком месте возникает проблема.', 0, 1),
('03', 'ЧТО ПЫТАЕТСЯ СДЕЛАТЬ?', 'Действие человека: какую задачу он решает.', 1, 0),
('04', 'ЧТО МЕШАЕТ?', 'Барьер: что конкретно не даёт это сделать.', 1, 1),
('05', 'ЧТО ТЕРЯЕТ?', 'Последствие: время, деньги, здоровье, нервы.', 2, 0),
('06', 'КАК РЕШАЕТ СЕЙЧАС?', 'Обходной путь — главный признак реальной боли.', 2, 1),
]
for num, title, prompt, row, col in blocks:
add_block(table.cell(row, col), num, title, prompt, lines=2, width_cm=8.2)
# Row 3: scale (merged)
c = table.cell(3, 0).merge(table.cell(3, 1))
add_block(c, '07', 'МАСШТАБ', 'Сколько таких людей? Как часто возникает проблема?', lines=1, width_cm=17.2)
# Row 4: evidence (merged)
c = table.cell(4, 0).merge(table.cell(4, 1))
add_block(c, '08', 'ДОКАЗАТЕЛЬСТВА', '5 цитат • 2–3 цифры • 1 наблюдение. Записывайте точные слова людей.', lines=4, width_cm=17.2)
# Row 5: 5 why (merged)
c = table.cell(5, 0).merge(table.cell(5, 1))
c.text = ''
shade(c, 'FDF4F6')
p = c.paragraphs[0]
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(1)
r = p.add_run('09 ')
set_run(r, size=7.5, bold=True, color=ROSE)
r = p.add_run('5 ПОЧЕМУ')
set_run(r, size=9.5, bold=True, color=ROSE)
p = c.add_paragraph()
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(3)
r = p.add_run('Цепочка до причины, а не симптома.')
set_run(r, size=7.5, color=GRAY)
why = c.add_table(rows=1, cols=5)
why.autofit = False
tblPr = why._tbl.tblPr
borders = OxmlElement('w:tblBorders')
for edge in ('top', 'left', 'bottom', 'right', 'insideH', 'insideV'):
el = OxmlElement('w:' + edge)
el.set(qn('w:val'), 'single')
el.set(qn('w:sz'), '4')
el.set(qn('w:space'), '0')
el.set(qn('w:color'), 'D9E2DD')
borders.append(el)
tblPr.append(borders)
for i, cell in enumerate(why.rows[0].cells):
cell.width = Cm(3.4)
cell.text = ''
p = cell.paragraphs[0]
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(0)
r = p.add_run(str(i + 1))
set_run(r, size=8, bold=True, color=ROSE)
p2 = cell.add_paragraph()
p2.paragraph_format.space_before = Pt(0)
p2.paragraph_format.space_after = Pt(0)
r = p2.add_run('Почему?')
set_run(r, size=7, color=GRAY)
# Row 6: formulation (merged)
c = table.cell(6, 0).merge(table.cell(6, 1))
c.text = ''
shade(c, 'F3F9F6')
p = c.paragraphs[0]
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(1)
r = p.add_run('10 ')
set_run(r, size=7.5, bold=True, color=GREEN)
r = p.add_run('ФОРМУЛИРОВКА ПРОБЛЕМЫ')
set_run(r, size=9.5, bold=True, color=GREEN)
p = c.add_paragraph()
p.paragraph_format.space_before = Pt(0)
p.paragraph_format.space_after = Pt(2)
r = p.add_run('«___________ не может ___________, потому что ___________. Это стоит им ___________.»')
set_run(r, size=8, italic=True, color=GRAY)
add_line_table(c, lines=1, width_cm=17.2, height_cm=0.5)
# Footer
p = doc.add_paragraph()
p.paragraph_format.space_before = Pt(5)
p.paragraph_format.space_after = Pt(0)
r = p.add_run('Не называйте решение. Сначала проблема. • Метод Дегтярева • Форум молодёжи Донбасса, 2026')
set_run(r, size=7.5, color=LIGHT)
doc.save(OUT)
print('saved', OUT)
if __name__ == '__main__':
build()