1 from nepi.util import guid
3 guid_gen = guid.GuidGenerator()
5 class Attributes(object):
7 super(Attributes, self).__init__()
8 self._attributes = dict()
10 def __getattr__(self, name):
12 return self._attributes[name]
14 return super(Attributes, self).__getattribute__(name)
16 def __setattr__(self, name, value):
19 old = self._attributes[name]
20 del self._attributes[name]
23 self._attributes[name] = value
26 return super(Attributes, self).__setattr__(name, value)
28 class Connections(object):
30 super(Connections, self).__init__()
31 self._connections = set()
33 def __getattr__(self, guid_or_label):
35 for b in self._connections:
36 if guid_or_label in [b.guid, b.label]:
39 return super(Connections, self).__getattribute__(guid_or_label)
42 def __init__(self, label = None, guid = None):
43 super(Box, self).__init__()
44 self._guid = guid_gen.next(guid)
45 self._a = Attributes()
46 self._c = Connections()
48 self.label = label or self._guid
50 # Graphical information to draw box
62 return self._a._attributes.keys()
77 def connections(self):
78 return set(self._c._connections)
84 self._tags.remove(name)
87 return name in self._tags
89 def connect(self, box, cascade = True):
90 self._c._connections.add(box)
92 box.connect(self, cascade = False)
94 def disconnect(self, box, cascade = True):
95 self._c._connections.remove(box)
97 box.disconnect(self, cascade = False)
99 def is_connected(self, box):
100 return box in self.connections