ubietylab.net

Ubiety Lab Blog

ubietylab.net header image 2

New Python API for UbiGraph

May 30th, 2008 · 2 Comments · Uncategorized

I just started programming in Python a couple of weeks ago, but I’m already in love with it. Here’s a taste of the new Python API included with the latest release of UbiGraph. It is such an easy, expressive language!

import ubigraph

U = ubigraph.Ubigraph()
U.clear()

x = U.newVertex(shape="sphere", color="#ffff00")

smallRed = U.newVertexStyle(shape="sphere", color="#ff0000", size="0.2")

previous_r = None
for i in range(0,10):
  r = U.newVertex(style=smallRed, label=str(i))
  U.newEdge(x,r,arrow=True)
  if previous_r != None:
    U.newEdge(r,previous_r,spline=True,stroke="dashed")
  previous_r = r

Tags:

2 responses so far ↓

  • 1 tveldhui // May 31, 2008 at 1:52 am

    In case you play with the Python interface in alpha-0.2.3, I found a couple of bugs today:

    Index: ubigraph.py
    ===================================================================
    --- ubigraph.py (revision 1750)
    +++ ubigraph.py (working copy)
    @@ -85,7 +85,7 @@
             callback)
    
       def destroy(self):
    -    U.G.remove_vertex(self.id)
    +    self.U.G.remove_vertex(self.id)
    
    @@ -111,7 +111,7 @@
                  oriented=None, spline=None, showstrain=None, stroke=None,
                  strength=None, visible=None, width=None):
         if style != None:
    -      self.U.G.change_edge_style_attribute(self.id, style.id)
    +      self.U.G.change_edge_style(self.id, style.id)
         if arrow != None:
           self.U.G.set_edge_attribute(self.id, "arrow", str(arrow))
         if color != None:
    @@ -139,6 +139,8 @@
         if width != None:
           self.U.G.set_edge_attribute(self.id, "width", str(width))
    
    +  def destroy(self):
    +    self.U.G.remove_edge(self.id)
    
     class VertexStyle:
    @@ -190,11 +192,11 @@
    
     class EdgeStyle:
    -  def __init__(self, G, parentStyle=None, id=None, arrow=None, color=None,
    +  def __init__(self, U, parentStyle=None, id=None, arrow=None, color=None,
                  label=None, fontcolor=None, fontfamily=None, fontsize=None,
                  oriented=None, spline=None, showstrain=None, stroke=None,
                  strength=None, visible=None, width=None):
    -    self.G = G
    +    self.U = U
         parentStyle2 = parentStyle
         if parentStyle2 == None:
           if id == 0:
    @@ -202,7 +204,7 @@
             self.id = 0
             return
           else:
    -        parentStyle2 = U.G.defaultEdgeStyle
    +        parentStyle2 = U.defaultEdgeStyle
    
         if id == None:
           self.id = U.G.new_edge_style(parentStyle2.id)
    
  • 2 Arnar Birgisson // Jun 11, 2008 at 11:22 am

    Hey there,

    The API looks good. We used UbiGraph for visualizing a game-tree search algorithm, video here:

    http://www.hvergi.net/2008/06/visualizing-gameplaying-algorithms/

    cheers!

Leave a Comment