Skip to content
Snippets Groups Projects
Node.py 735 B
Newer Older
  • Learn to ignore specific revisions
  • Lukas Kettenbach's avatar
    Lukas Kettenbach committed
    import abc
    
    Lukas Kettenbach's avatar
    Lukas Kettenbach committed
    
    
    class Node(object):
        __metaclass__ = abc.ABCMeta
    
        name = "UninitializedName"
    
        position = (0, 0)
    
    Lukas Kettenbach's avatar
    Lukas Kettenbach committed
    
        def __init__(self, node_name):
    
            # Remove all special characters and replace " " with "_"
            name = re.sub(r"[^a-zA-Z_0-9 ]*", "", node_name)
    
            self.name = name.replace(" ", "_")        
            # for visual illustration
            self.pos = (0, 0)
    
    Lukas Kettenbach's avatar
    Lukas Kettenbach committed
    
        @abc.abstractmethod
        def announce_parent(self, node):
            """This method will be called by the graph-management to inform nodes
            which just became children of other nodes, so they can adapt themselves
            (e.g. their cpt)"""
            return
    
        def __str__(self):
            print self.name
            return self.name