Пример #1
0
    def show_with_dot(self):
        from ctree.visual.dot_manager import DotManager
        # start_node = self.currentItem().ast_node
        #
        # def find_appropriate_node(node):
        #     if not node:
        #         return None
        #     if isinstance(node, ast.AST):
        #         return node
        #     if hasattr(node, 'parent'):
        #         return find_appropriate_node(node.parent)
        #     return None
        #
        # start_node = find_appropriate_node(start_node)
        start_item = self.currentItem()

        def find_appropriate_node(item):
            if not item:
                return None
            if hasattr(item, 'ast_node') and isinstance(item.ast_node, ast.AST):
                return item.ast_node
            if hasattr(item, 'parent'):
                return find_appropriate_node(item.parent())
            print("bad node %s" % item)
            import pprint
            pprint(dir(item))
            return None

        start_node = find_appropriate_node(start_item)
        if not start_node:
            self.code_presenter.show_error("Sorry, cannot find an ast node to begin graph")
            return

        file_name = os.path.join(tempfile.gettempdir(), 'tree_%s.png' % self.tab_name)
        DotManager.dot_ast_to_browser(start_node, file_name)
Пример #2
0
def browser_show_ast(tree, file_name):
    """
    convenience method to display an AST in ipython
    converts tree in place to a dot format
    then renders that into a png file
    """
    return DotManager.dot_ast_to_browser(tree, file_name)
Пример #3
0
def browser_show_ast(tree, file_name):
    """
    convenience method to display an AST in ipython
    converts tree in place to a dot format
    then renders that into a png file
    """
    return DotManager.dot_ast_to_browser(tree, file_name)
Пример #4
0
 def ast_command(self, command):
     fields = command.split()
     if len(fields) < 2 or fields[1].startswith("list"):
         self.show_asts()
     elif fields[1].startswith("del"):
         if len(fields) > 2 and self.delete_ast(fields[2]):
             pass
         else:
             print("error: delete command must specify index of tree to delete")
     elif fields[1].startswith("cle"):
         self.controller.ast_tree_manager.clear()
     elif fields[1].startswith("sho"):
         try:
             index = int(fields[2])
             from ctree.visual.dot_manager import DotManager
             print("calling open")
             DotManager.dot_ast_to_browser(self.controller.ast_tree_manager[index].ast_tree, "tree%d.png" % index)
         except IOError as e:
             print("ast show requires numeric index of ast, msg %s" % e.message)
     else:
         print("unknown ast command")
Пример #5
0
    def show_with_dot(self):
        from ctree.visual.dot_manager import DotManager
        # start_node = self.currentItem().ast_node
        #
        # def find_appropriate_node(node):
        #     if not node:
        #         return None
        #     if isinstance(node, ast.AST):
        #         return node
        #     if hasattr(node, 'parent'):
        #         return find_appropriate_node(node.parent)
        #     return None
        #
        # start_node = find_appropriate_node(start_node)
        start_item = self.currentItem()

        def find_appropriate_node(item):
            if not item:
                return None
            if hasattr(item, 'ast_node') and isinstance(
                    item.ast_node, ast.AST):
                return item.ast_node
            if hasattr(item, 'parent'):
                return find_appropriate_node(item.parent())
            print("bad node %s" % item)
            import pprint
            pprint(dir(item))
            return None

        start_node = find_appropriate_node(start_item)
        if not start_node:
            self.code_presenter.show_error(
                "Sorry, cannot find an ast node to begin graph")
            return

        file_name = os.path.join(tempfile.gettempdir(),
                                 'tree_%s.png' % self.tab_name)
        DotManager.dot_ast_to_browser(start_node, file_name)