svg_toolbox.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Tweezer_design 作者: AntoineRiaud 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号