project.py 文件源码

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

项目:radiant-voices 作者: metrasynth 项目源码 文件源码
def layout(self, prog='dot', factor=8, offset=0):
        """Use GraphViz to auto-layout modules."""
        if pgv is not None:
            g = pgv.AGraph(self.graph(), directed=True, strict=False)
            g.layout(prog=prog)
            for node in g.nodes():
                x, y = node.attr['pos'].split(',')
                x, y = int(float(x)), int(float(y))
                idx = int(node)
                mod = self.modules[idx]
                if isinstance(factor, int):
                    xfactor, yfactor = factor, factor
                else:
                    xfactor, yfactor = factor
                if isinstance(offset, int):
                    xoffset, yoffset = offset, offset
                else:
                    xoffset, yoffset = offset
                mod.x = x * xfactor + xoffset
                mod.y = y * yfactor + yoffset
            return True
        else:
            logging.warning('GraphViz not available; could not auto-layout.')
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号