Fix a bug or two. Now working as intended

This commit is contained in:
Dominic Zimmer 2019-11-13 14:58:34 +01:00
parent 3e12fed614
commit c0800a5ead

71
generate_svgs.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/bin/python3
import xml.etree.ElementTree as ET
import argparse
import re
@ -41,6 +42,11 @@ parsed = vars(parser.parse_args())
disable_tables = [
list(range(size)) for size in table_group_sizes
]
# open XML
tree = ET.parse(parsed["input"])
root = tree.getroot()
if parsed["all"]:
disable_tables = []
else:
@ -58,47 +64,36 @@ else:
tableid = f"{lower}{thechar}"
if parsed[tableid]:
disable_tables[i].remove(j)
print(disable_tables)
pattern_rect = re.compile("table_(.)(.*)")
pattern_text = re.compile("label_(.)")
# parse XML for the table rects
rects = root.findall(".//{http://www.w3.org/2000/svg}rect")
rects = list(filter(lambda rect: pattern_rect.match(rect.attrib["id"]), rects))
# parse XML for the text containers
texts = root.findall(".//{http://www.w3.org/2000/svg}text")
texts = list(filter(lambda text: pattern_text.match(text.attrib["id"]), texts))
pattern_rect = re.compile("table_(.)(.*)")
pattern_text = re.compile("label_(.)")
for text in texts:
# parse group of text
match = pattern_text.match(text.attrib["id"])
group = ord(match.group(1)) - ord('a')
# disable text if all of its childs are disabled
all_childs_disabled = len(disable_tables[group]) == table_group_sizes[group] # no element removed
if all_childs_disabled:
span = list(text)[0]
style_span="font-size:3.17499995px;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332;"
span.attrib["style"] = style_span
# otherwise do nothing, we start with a full canvas
tree = ET.parse(parsed["input"])
root = tree.getroot()
# parse XML for the table rects
rects = root.findall(".//{http://www.w3.org/2000/svg}rect")
rects = list(filter(lambda rect: pattern_rect.match(rect.attrib["id"]), rects))
# parse XML for the text containers
texts = root.findall(".//{http://www.w3.org/2000/svg}text")
texts = list(filter(lambda text: pattern_text.match(text.attrib["id"]), texts))
for text in texts:
# parse group of text
match = pattern_text.match(text.attrib["id"])
group = ord(match.group(1)) - ord('a')
# disable text if all of its childs are disabled
all_childs_disabled = len(disable_tables[group]) == table_group_sizes[group] # no element removed
if all_childs_disabled:
print("disable group", group)
span = list(text)[0]
style_span="font-size:3.17499995px;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332;"
span.attrib["style"] = style_span
else:
print("dont disable group", group)
# do nothing, we start with a full canvas
for rect in rects:
match = pattern_rect.match(rect.attrib["id"])
group, number = ord(match.group(1)) - ord('a'), table_char_to_num[match.group(2)]
print(group, number)
if number in disable_tables[group]:
#other group, color grey
rect.attrib["style"] = "fill:#808080;stroke-width:0.26458332"
#groupstring = chr(ord('a') + group_id)
for rect in rects:
match = pattern_rect.match(rect.attrib["id"])
group, number = ord(match.group(1)) - ord('a'), table_char_to_num[match.group(2)]
if number in disable_tables[group]:
#other group, color grey
rect.attrib["style"] = "fill:#808080;stroke-width:0.26458332"
#groupstring = chr(ord('a') + group_id)
tree.write(parsed["output"])