Browse code

Record id in the Node. Add __repr__() for both Node and Edge.

Paul Sokolovsky authored on 12/02/2013 19:03:36 • José Fonseca committed on 12/05/2013 12:44:15
Showing 1 changed files

  • xdot.py index 0c804c9..28e2f82 100755
... ...
@@ -372,9 +372,10 @@ class Element(CompoundShape):
372 372
 
373 373
 class Node(Element):
374 374
 
375
-    def __init__(self, x, y, w, h, shapes, url):
375
+    def __init__(self, id, x, y, w, h, shapes, url):
376 376
         Element.__init__(self, shapes)
377 377
 
378
+        self.id = id
378 379
         self.x = x
379 380
         self.y = y
380 381
 
... ...
@@ -400,6 +401,9 @@ class Node(Element):
400 401
             return Jump(self, self.x, self.y)
401 402
         return None
402 403
 
404
+    def __repr__(self):
405
+        return "<Node %s>" % self.id
406
+
403 407
 
404 408
 def square_distance(x1, y1, x2, y2):
405 409
     deltax = x2 - x1
... ...
@@ -424,6 +428,9 @@ class Edge(Element):
424 428
             return Jump(self, self.src.x, self.src.y, highlight=set([self, self.src]))
425 429
         return None
426 430
 
431
+    def __repr__(self):
432
+        return "<Edge %s -> %s>" % (self.src, self.dst)
433
+
427 434
 
428 435
 class Graph(Shape):
429 436
 
... ...
@@ -1149,7 +1156,7 @@ class XDotParser(DotParser):
1149 1156
                 parser = XDotAttrParser(self, attrs[attr])
1150 1157
                 shapes.extend(parser.parse())
1151 1158
         url = attrs.get('URL', None)
1152
-        node = Node(x, y, w, h, shapes, url)
1159
+        node = Node(id, x, y, w, h, shapes, url)
1153 1160
         self.node_by_name[id] = node
1154 1161
         if shapes:
1155 1162
             self.nodes.append(node)