How to use the pygraphviz.graphviz.agget function in pygraphviz

To help you get started, we’ve selected a few pygraphviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esa / opengeode / opengeode / Statechart.py View on Github external
# Compute all the coordinates (self-modifying function)
    # Force the fontsize of the nodes to be 12, as in OpenGEODE
    # use -n1 below to keep user-specified node coordinates
    if dump_gfx:
        dump_name = 'sc_' + os.path.basename(dump_gfx)
        dump_gfx = os.path.dirname(dump_gfx) or '.' + os.sep + dump_name
        if dump_gfx.split('.')[-1].lower() != 'png':
            dump_gfx += '.png'

    graph.layout(prog='neato', args='{cfg} {kp} {dump}'
            .format(cfg=config, kp='-n1' if keep_pos else '',
                    dump=('-Tpng -o' + dump_gfx) if dump_gfx else ''))
    # bb is not visible directly - extract it from the low level api:
    bounding_rect = [float(val) for val in
            dotgraph.graphviz.agget(graph.handle, b'bb').split(b',')]
    dot_dpi = float(dotgraph.graphviz.agget(graph.handle, b'dpi'))

    #fontname = graph.graph_attr.get('fontname')
    #fontsize = graph.graph_attr.get('fontsize')
    #with open('statechart.dot', 'w') as output:
    #    output.write(graph.to_string())

    nodes = preprocess_nodes(graph, bounding_rect, dot_dpi)
    node_symbols = []
    for node in nodes:
        shape = node.get('shape')
        try:
            node_symbol = lookup[shape](node, graph)
            if str(node_symbol) in graphtree['children'] \
                    and shape == 'record':
                # Use a different color for non-terminal states
                node_symbol.setBrush(QBrush(QColor(249, 249, 249)))
github esa / opengeode / opengeode / Statechart.py View on Github external
# Compute all the coordinates (self-modifying function)
    # Force the fontsize of the nodes to be 12, as in OpenGEODE
    # use -n1 below to keep user-specified node coordinates
    if dump_gfx:
        dump_name = 'sc_' + os.path.basename(dump_gfx)
        dump_gfx = os.path.dirname(dump_gfx) or '.' + os.sep + dump_name
        if dump_gfx.split('.')[-1].lower() != 'png':
            dump_gfx += '.png'

    graph.layout(prog='neato', args='{cfg} {kp} {dump}'
            .format(cfg=config, kp='-n1' if keep_pos else '',
                    dump=('-Tpng -o' + dump_gfx) if dump_gfx else ''))
    # bb is not visible directly - extract it from the low level api:
    bounding_rect = [float(val) for val in
            dotgraph.graphviz.agget(graph.handle, b'bb').split(b',')]
    dot_dpi = float(dotgraph.graphviz.agget(graph.handle, b'dpi'))

    #fontname = graph.graph_attr.get('fontname')
    #fontsize = graph.graph_attr.get('fontsize')
    #with open('statechart.dot', 'w') as output:
    #    output.write(graph.to_string())

    nodes = preprocess_nodes(graph, bounding_rect, dot_dpi)
    node_symbols = []
    for node in nodes:
        shape = node.get('shape')
        try:
            node_symbol = lookup[shape](node, graph)
            if str(node_symbol) in graphtree['children'] \
                    and shape == 'record':
                # Use a different color for non-terminal states
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
# get the charset from the string to properly encode it for
            # writing to the temporary file in from_string()
            match = re.search(r'charset\s*=\s*"([^"]+)"', string)
            if match is not None:
                self.encoding = match.group(1)
            else:
                self.encoding = _DEFAULT_ENCODING
            self.from_string(string)
        else:
            # no handle, need to
            self.handle = None

        if self.handle is not None:
            # the handle was specified or created
            # get the encoding from the "charset" graph attribute
            item=gv.agget(self.handle,'charset')
            if item is not None:
                self.encoding = item
            else:
                self.encoding = _DEFAULT_ENCODING
        else:
            # no handle was specified or created
            # get encoding from the "charset" kwarg
            self.encoding = attr.get('charset', _DEFAULT_ENCODING)
            try:
                if name is None:
                    name = ''
                # instantiate a new, empty graph
                self.handle=gv.agraphnew(name,
                                         strict,directed)
            except TypeError:
                raise TypeError("Graph name must be a string: %s"%name)
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def __getitem__(self, name):
        val = gv.agget(self.handle, name.encode(self.encoding))
        if val is not None:
            val = val.decode(self.encoding)
        return val
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
# get the charset from the string to properly encode it for
            # writing to the temporary file in from_string()
            match = re.search(r'charset\s*=\s*"([^"]+)"', string)
            if match is not None:
                self.encoding = match.group(1)
            else:
                self.encoding = _DEFAULT_ENCODING
            self.from_string(string)
        else:
            # no handle, need to
            self.handle = None

        if self.handle is not None:
            # the handle was specified or created
            # get the encoding from the "charset" graph attribute
            item = gv.agget(self.handle, b'charset')
            if item is not None:
                self.encoding = item
            else:
                self.encoding = _DEFAULT_ENCODING
        else:
            # no handle was specified or created
            # get encoding from the "charset" kwarg
            self.encoding = attr.get('charset', _DEFAULT_ENCODING)
            try:
                if name is None:
                    name = ''
                    # instantiate a new, empty graph
                self.handle = gv.agraphnew(name.encode(self.encoding),
                                           strict, directed)
            except TypeError:
                raise TypeError("Graph name must be a string: %s" % name)
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
def __getitem__(self, name):
        item=gv.agget(self.handle,name.encode(self.encoding))
        if item is None:
            ah=gv.agattr(self.handle,self.type,
                         name,
                         None)
            item=gv.agattrdefval(ah)
        return item.decode(self.encoding)
github philipaxer / pygraphviz / pygraphviz / agraph.py View on Github external
def __getitem__(self, name):
        val = gv.agget(self.handle,name)
        if val is not None:
            val = val.decode(self.encoding)
        return val
github pygraphviz / pygraphviz / pygraphviz / agraph.py View on Github external
def __getitem__(self, name):
        item = gv.agget(self.handle, name.encode(self.encoding))
        if item is None:
            ah = gv.agattr(self.handle, self.type,
                           name.encode(self.encoding),
                           None)
            item = gv.agattrdefval(ah)
        return item.decode(self.encoding)