Exemple #1
0
    def _get(self, handle, node="", edge="", subg=""):
        """ Gets Graphviz.<Type> items from parent graph (given by handle).
        """
        # Default return value if item is not found
        head, tail = '', ''
        if edge:
            head, tail = edge

        node, head, tail, subg = map(encode_page, [node, head, tail, subg])

        graphvizitem = None
        if head and tail:
            item = gv.findedge(gv.findnode(handle, head),
                               gv.findnode(handle, tail))
            if item:
                graphvizitem = GraphvizEdge(self, item)
        elif node:
            item = gv.findnode(handle, node)
            if item:
                graphvizitem = GraphvizNode(self, item)
        elif subg:
            item = gv.findsubg(handle, subg)
            if item:
                graphvizitem = GraphvizSubgraph(self, item)
        else:
            raise ValueError("No graph element type specified")
        return graphvizitem
Exemple #2
0
    def _del(self, handle="", node="", edge="", subg=""):
        """ Deletes items.

        Finds the item handle by type, if necessary, and removes the
        item from graph
        """
        head, tail = '', ''
        if edge:
            head, tail = edge

        node, head, tail, subg = map(encode_page, [node, head, tail, subg])

        self.changed = 1
        if head and tail:
            item = gv.findedge(gv.findnode(handle, head),
                               gv.findnode(handle, tail))
        elif node:
            item = gv.findnode(handle, node)
        elif subg:
            item = gv.findsubg(handle, subg)
        elif handle:
            item = handle
        else:
            raise ValueError("No graph element or element type specified")
        if item:
            gv.rm(item)
Exemple #3
0
    def _setattrs(self, handle="",
                  edge="", node="", subg="", proto="",
                  **attrs):
        """ Sets attributes for item by handle or by name and type

        Finds the item handle by type, if necessary, and sets given
        attributes.
        """
        head, tail = '', ''
        if edge:
            head, tail = edge

        node, head, tail, subg = map(encode_page, [node, head, tail, subg])

        self.changed = 1

        if proto in ["node", "edge"]:
            # Gets handle when called from Subraphs.set()
            if subg:
                handle = gv.findsubg(self.handle, subg)
            # Called by self.set() and GraphvizSubgraph.set(), handle known
            item = getattr(gv, "proto%s" % proto)(handle)
            # print "item = gv.proto" + proto + "(g)"
        elif head and tail:
            item = gv.findedge(gv.findnode(handle, head),
                               gv.findnode(handle, tail))
            # print "item = gv.findedge(gv.findnode(g, '" + head + "')," + \
            #       "gv.findnode(g, '" + tail + "'))"
        elif node:
            item = gv.findnode(handle, node)
            # print "item = gv.findnode(g, '" + node + "')"
        elif subg:
            item = gv.findsubg(handle, subg)
            # print "item = gv.findsubg(g, '" + subg + "')"
        elif handle:
            item = handle
        else:
            raise ValueError("No graph element or element type specified")

        for key, elem in attrs.iteritems():
            if isinstance(elem, set):
                for e in elem:
                    key, e = map(encode_page, [key, e])
                    gv.setv(item, key, e)
            else:
                key, elem = map(encode_page, [key, elem])
                gv.setv(item, key, elem)