1 from Tools.CList import CList
4 # Render Converter Converter Source
6 # a bidirectional connection
15 cache[name] = (True, f(self))
19 class ElementError(Exception):
20 def __init__(self, message):
26 class Element(object):
27 CHANGED_DEFAULT = 0 # initial "pull" state
28 CHANGED_ALL = 1 # really everything changed
29 CHANGED_CLEAR = 2 # we're expecting a real update soon. don't bother polling NOW, but clear data.
30 CHANGED_SPECIFIC = 3 # second tuple will specify what exactly changed
31 CHANGED_POLL = 4 # a timer expired
36 self.downstream_elements = CList()
40 self.__suspended = True
43 def connectDownstream(self, downstream):
44 self.downstream_elements.append(downstream)
45 if self.master is None:
46 self.master = downstream
48 def connectUpstream(self, upstream):
49 assert not self.SINGLE_SOURCE or self.source is None
50 self.sources.append(upstream)
51 # self.source always refers to the last recent source added.
52 self.source = upstream
53 self.changed((self.CHANGED_DEFAULT,))
55 def connect(self, upstream):
56 self.connectUpstream(upstream)
57 upstream.connectDownstream(self)
59 # we disconnect from down to up
60 def disconnectAll(self):
61 # we should not disconnect from upstream if
62 # there are still elements depending on us.
63 assert len(self.downstream_elements) == 0, "there are still downstream elements left"
65 # Sources don't have a source themselves. don't do anything here.
66 for s in self.sources:
67 s.disconnectDownstream(self)
70 # sources are owned by the Screen, so don't destroy them here.
75 def disconnectDownstream(self, downstream):
76 self.downstream_elements.remove(downstream)
77 if self.master == downstream:
80 if len(self.downstream_elements) == 0:
83 # default action: push downstream
84 def changed(self, *args, **kwargs):
86 self.downstream_elements.changed(*args, **kwargs)
89 def setSuspend(self, suspended):
90 changed = self.__suspended != suspended
91 if not self.__suspended and suspended:
93 elif self.__suspended and not suspended:
96 self.__suspended = suspended
98 for s in self.sources:
101 suspended = property(lambda self: self.__suspended, setSuspend)
103 def checkSuspend(self):
104 self.suspended = reduce(lambda x, y: x and y.__suspended, self.downstream_elements, True)
106 def doSuspend(self, suspend):