1 from Tools.CList import CList
4 # Render Converter Converter Source
6 # a bidirectional connection
15 cache[name] = (True, f(self))
19 class Element(object):
20 CHANGED_DEFAULT = 0 # initial "pull" state
21 CHANGED_ALL = 1 # really everything changed
22 CHANGED_CLEAR = 2 # we're expecting a real update soon. don't bother polling NOW, but clear data.
23 CHANGED_SPECIFIC = 3 # second tuple will specify what exactly changed
24 CHANGED_POLL = 4 # a timer expired
27 self.downstream_elements = CList()
30 self.__suspended = True
33 def connectDownstream(self, downstream):
34 self.downstream_elements.append(downstream)
35 if self.master is None:
36 self.master = downstream
38 def connectUpstream(self, upstream):
39 assert self.source is None
40 self.source = upstream
41 self.changed((self.CHANGED_DEFAULT,))
43 def connect(self, upstream):
44 self.connectUpstream(upstream)
45 upstream.connectDownstream(self)
47 # we disconnect from down to up
48 def disconnectAll(self):
49 # we should not disconnect from upstream if
50 # there are still elements depending on us.
51 assert len(self.downstream_elements) == 0, "there are still downstream elements left"
53 # Sources don't have a source themselves. don't do anything here.
54 if self.source is not None:
55 self.source.disconnectDownstream(self)
56 # sources are owned by the Screen, so don't destroy them here.
59 def disconnectDownstream(self, downstream):
60 self.downstream_elements.remove(downstream)
61 if self.master == downstream:
64 if len(self.downstream_elements) == 0:
67 # default action: push downstream
68 def changed(self, *args, **kwargs):
70 self.downstream_elements.changed(*args, **kwargs)
73 def reconnectUpstream(self, new_upstream):
74 assert self.source is not None
75 self.source = new_upstream
77 def setSuspend(self, suspended):
78 changed = self.__suspended != suspended
79 if not self.__suspended and suspended:
81 elif self.__suspended and not suspended:
84 self.__suspended = suspended
85 if self.source is not None and changed:
86 self.source.checkSuspend()
88 suspended = property(lambda self: self.__suspended, setSuspend)
90 def checkSuspend(self):
91 self.suspended = reduce(lambda x, y: x and y.__suspended, self.downstream_elements, True)
93 def doSuspend(self, suspend):