11 :synopsis: Repackaging of the limiting ROS qt_dotgraph.dot_to_qt module. 13 Oh my spaghettified magnificence, 14 Bless my noggin with a tickle from your noodly appendages! 27 pyparsing._noncomma =
"".join([c
for c
in pyparsing.printables
if c !=
","])
30 from python_qt_binding.QtCore
import QPointF, QRectF
31 from python_qt_binding.QtGui
import QColor
33 from .edge_item
import EdgeItem
34 from .node_item
import NodeItem
46 value = item.get(name)
50 return value.strip(
'"\n"')
51 except AttributeError:
72 for name
in subgraph.get_attributes().iterkeys():
75 obj_dic = subgraph.__getattribute__(
"obj_dict")
77 if name
not in [
'nodes',
'attributes',
'parent_graph']
and obj_dic[name]
is not None:
80 for key
in obj_dic[
'nodes'][
'graph'][0][
'attributes']:
81 attr[key] =
get_unquoted(obj_dic[
'nodes'][
'graph'][0][
'attributes'], key)
84 bb = subgraph.attr.get(
'bb',
None)
88 bb = bb.strip(
'"').split(
',')
92 bounding_box = QRectF(0, 0, float(bb[2]) - float(bb[0]), float(bb[3]) - float(bb[1]))
93 if 'lp' in subgraph.attr:
94 label_pos = subgraph.attr[
'lp'].strip(
'"').split(
',')
96 label_pos = (float(bb[0]) + (float(bb[2]) - float(bb[0])) / 2, float(bb[1]) + (float(bb[3]) - float(bb[1])) - LABEL_HEIGHT / 2)
97 bounding_box.moveCenter(QPointF(float(bb[0]) + (float(bb[2]) - float(bb[0])) / 2, -float(bb[1]) - (float(bb[3]) - float(bb[1])) / 2))
98 name = subgraph.attr.get(
'label',
'')
99 color = QColor(subgraph.attr[
'color'])
if 'color' in subgraph.attr
else None 100 subgraph_nodeitem = NodeItem(highlight_level,
105 label_pos=QPointF(float(label_pos[0]), -float(label_pos[1])))
106 bounding_box = QRectF(bounding_box)
111 bounding_box.setHeight(LABEL_HEIGHT)
112 subgraph_nodeitem.set_hovershape(bounding_box)
113 return subgraph_nodeitem
117 returns a pyqt NodeItem object, or None in case of error or invisible style 130 if 'style' in node.attr:
131 if node.attr[
'style'] ==
'invis':
134 color = QColor(node.attr[
'color'])
if 'color' in node.attr
else None 136 if 'label' in node.attr:
137 name = node.attr[
'label']
138 elif 'name' in node.attr:
139 name = node.attr[
'name']
141 print(
"Error, no label defined for node with attr: %s" % node.attr)
145 print(
"Error, label is None for node %s, pygraphviz version may be too old." % node)
147 name = name.decode(
'string_escape')
150 bb_width = len(name) / 5
151 if 'width' in node.attr:
152 bb_width = node.attr[
'width']
154 if 'width' in node.attr:
155 bb_height = node.attr[
'height']
156 bounding_box = QRectF(0, 0, POINTS_PER_INCH * float(bb_width) - 1.0, POINTS_PER_INCH * float(bb_height) - 1.0)
158 if 'pos' in node.attr:
159 pos = node.attr[
'pos'].split(
',')
160 bounding_box.moveCenter(QPointF(float(pos[0]), -float(pos[1])))
162 node_item = NodeItem(highlight_level=highlight_level,
163 bounding_box=bounding_box,
165 shape=node.attr.get(
'shape',
'ellipse'),
167 tooltip=node.attr.get(
'tooltip',
None)
174 def addEdgeItem(self, edge, nodes, edges, highlight_level, same_label_siblings=False):
176 adds EdgeItem by data in edge to edges 177 :param same_label_siblings: if true, edges with same label will be considered siblings (collective highlighting) 186 if 'style' in edge.attr:
187 if edge.attr[
'style'] ==
'invis':
189 style = edge.attr.get(
'style',
None)
191 label = edge.attr.get(
'label',
None)
192 label_pos = edge.attr.get(
'lp',
None)
194 if label_pos
is not None:
195 label_pos = label_pos.split(
',')
196 label_center = QPointF(float(label_pos[0]), -float(label_pos[1]))
199 source_node = edge.get_source()
if hasattr(edge,
'get_source')
else edge[0]
200 destination_node = edge.get_destination()
if hasattr(edge,
'get_destination')
else edge[1]
204 if 'pos' in edge.attr:
205 edge_pos = edge.attr[
'pos']
206 if label
is not None:
207 label = label.decode(
'string_escape')
210 if 'colorR' in edge.attr
and 'colorG' in edge.attr
and 'colorB' in edge.attr:
211 r = edge.attr[
'colorR']
212 g = edge.attr[
'colorG']
213 b = edge.attr[
'colorB']
214 color = QColor(float(r), float(g), float(b))
216 edge_item = EdgeItem(highlight_level=highlight_level,
218 label_center=label_center,
220 from_node=nodes[source_node],
221 to_node=nodes[destination_node],
222 penwidth=int(edge.attr[
'penwidth']),
226 if same_label_siblings:
229 label =
"%s_%s" % (source_node, destination_node)
232 for sibling
in edges[label]:
233 edge_item.add_sibling_edge(sibling)
234 sibling.add_sibling_edge(edge_item)
236 if label
not in edges:
238 edges[label].append(edge_item)
242 takes dotcode, runs layout, and creates qt items based on the dot layout. 243 returns two dicts, one mapping node names to Node_Item, one mapping edge names to lists of Edge_Item 244 :param same_label_siblings: if true, edges with same label will be considered siblings (collective highlighting) 258 graph = pygraphviz.AGraph(string=dotcode.encode(
"ascii",
"ignore"), strict=
False, directed=
True)
259 graph.layout(prog=
'dot')
262 for subgraph
in graph.subgraphs_iter():
265 if subgraph_nodeitem
is None:
268 subgraph.nodes_iter = subgraph.get_node_list
269 nodes[subgraph.get_name()] = subgraph_nodeitem
270 for node
in subgraph.nodes_iter():
272 if node.get_name()
in (
'graph',
'node',
'empty'):
275 for node
in graph.nodes_iter():
277 if node.get_name()
in (
'graph',
'node',
'empty'):
283 for subgraph
in graph.subgraphs_iter():
284 subgraph.edges_iter = subgraph.get_edge_list
285 for edge
in subgraph.edges_iter():
287 highlight_level=highlight_level,
288 same_label_siblings=same_label_siblings)
290 for edge
in graph.edges_iter():
292 highlight_level=highlight_level,
293 same_label_siblings=same_label_siblings)
299 takes a pydot/pygraphviz graph and creates qt items based on the dot layout. 300 returns two dicts, one mapping node names to Node_Item, one mapping edge names to lists of Edge_Item 301 :param same_label_siblings: if true, edges with same label will be considered siblings (collective highlighting) 312 for subgraph
in graph.subgraphs_iter():
315 if subgraph_nodeitem
is None:
318 subgraph.nodes_iter = subgraph.get_node_list
319 nodes[subgraph.get_name()] = subgraph_nodeitem
320 for node
in subgraph.nodes_iter():
322 if node.get_name()
in (
'graph',
'node',
'empty'):
325 for node
in graph.nodes_iter():
327 if node.get_name()
in (
'graph',
'node',
'empty'):
333 for subgraph
in graph.subgraphs_iter():
334 subgraph.edges_iter = subgraph.get_edge_list
335 for edge
in subgraph.edges_iter():
337 highlight_level=highlight_level,
338 same_label_siblings=same_label_siblings)
340 for edge
in graph.edges_iter():
342 highlight_level=highlight_level,
343 same_label_siblings=same_label_siblings)
def addEdgeItem(self, edge, nodes, edges, highlight_level, same_label_siblings=False)
def graph_to_qt_items(self, graph, highlight_level, same_label_siblings=False)
def getNodeItemForNode(self, node, highlight_level)
def get_unquoted(item, name)
Support.
def dotcode_to_qt_items(self, dotcode, highlight_level, same_label_siblings=False)
def getNodeItemForSubgraph(self, subgraph, highlight_level)