add command list
This commit is contained in:
parent
bae25e220a
commit
71bffa4243
@ -24,13 +24,48 @@ def to_docx(filename, program, data):
|
||||
for x in program.keys():
|
||||
rows = max(list(program[x].keys())[-1] + 1, rows)
|
||||
|
||||
program_table = [None] * rows
|
||||
|
||||
for i in range(rows):
|
||||
program_table[i] = [None] * cols
|
||||
|
||||
symbols = [None] * cols
|
||||
|
||||
for j, (symbol, value) in enumerate(program.items()):
|
||||
symbols[j] = symbol
|
||||
for i, (state, action) in enumerate(value.items()):
|
||||
program_table[state][j] = action
|
||||
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
action = program_table[i][j]
|
||||
if action is None: continue
|
||||
|
||||
p = document.add_paragraph()
|
||||
p.paragraph_format.space_after = Pt(0)
|
||||
p.paragraph_format.space_before = Pt(0)
|
||||
p.paragraph_format.line_spacing_rule = WD_LINE_SPACING.DOUBLE
|
||||
add_state(p, i)
|
||||
|
||||
symbol, direction, state = action
|
||||
|
||||
p.add_run(symbols[j] + ' → ')
|
||||
add_state(p, state)
|
||||
p.add_run(symbol + 'R' if direction == '>' else 'L')
|
||||
|
||||
|
||||
p = document.add_paragraph()
|
||||
p.paragraph_format.space_after = Pt(0)
|
||||
p.paragraph_format.space_before = Pt(0)
|
||||
p.paragraph_format.line_spacing_rule = WD_LINE_SPACING.DOUBLE
|
||||
|
||||
table = document.add_table(rows + 1, cols + 1)
|
||||
table.style = 'Table Grid'
|
||||
table.autofit = True
|
||||
table.allow_autofit = True
|
||||
|
||||
for i in range(1, rows + 1):
|
||||
p = table.rows[i].cells[0].paragraphs[0]
|
||||
for i in range(0, rows):
|
||||
p = table.rows[i + 1].cells[0].paragraphs[0]
|
||||
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
p.paragraph_format.space_after = Pt(0)
|
||||
p.paragraph_format.space_before = Pt(0)
|
||||
@ -45,9 +80,12 @@ def to_docx(filename, program, data):
|
||||
p.paragraph_format.line_spacing_rule = WD_LINE_SPACING.DOUBLE
|
||||
p.add_run(x)
|
||||
|
||||
for j, (value) in enumerate(program.values()):
|
||||
for i, (state, action) in enumerate(value.items()):
|
||||
p = table.rows[state + 1].cells[j + 1].paragraphs[0]
|
||||
for i in range(rows):
|
||||
for j in range(cols):
|
||||
action = program_table[i][j]
|
||||
if action is None: continue
|
||||
|
||||
p = table.rows[i + 1].cells[j + 1].paragraphs[0]
|
||||
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
||||
p.paragraph_format.space_after = Pt(0)
|
||||
p.paragraph_format.space_before = Pt(0)
|
||||
@ -58,6 +96,7 @@ def to_docx(filename, program, data):
|
||||
p.add_run(symbol)
|
||||
p.add_run('R' if direction == '>' else 'L')
|
||||
|
||||
|
||||
p = document.add_paragraph()
|
||||
p.paragraph_format.space_after = Pt(0)
|
||||
p.paragraph_format.space_before = Pt(0)
|
||||
|
Loading…
Reference in New Issue
Block a user