def read_colored_path_from_svg(svg_filename):
# re_split = re.compile('\s+|,')
tree = etree.parse(open(svg_filename))
path_list = {}
for element in tree.iter():
if element.tag.split("}")[1] == "path":
#re_split.split(element.get("d"))
path_color = element.get('style')
if type(path_color) == str:
ind = path_color.find('fill:')
path_color = path_color[(ind+5):(ind+12)]
if path_color == '#ff0000':
path_color = 'red'
elif path_color == '#00ff00':
path_color = 'green'
elif path_color == '#0000ff':
path_color = 'blue'
else:
tkMessageBox.showwarning('Some colors were not rekognized', 'Only blue, red and green traces are imported')
else:
path_color = element.get('fill')
if path_color not in path_list.keys():
path_list[path_color]=[]
path_list[path_color].append(element.get('d'))
#path_list.append(re_split)
Points = {}
for path_color in path_list:
Points[path_color] = string2points(path_list[path_color])
return Points
评论列表
文章目录