1 from Tools.CList import CList
4 # Render Converter Converter Source
6 # a bidirectional connection
8 CHANGED_DEFAULT = 0 # initial "pull" state
9 CHANGED_ALL = 1 # really everything changed
10 CHANGED_CLEAR = 2 # we're expecting a real update soon. don't bother polling NOW, but clear data.
11 CHANGED_SPECIFIC = 3 # second tuple will specify what exactly changed
12 CHANGED_POLL = 4 # a timer expired
15 self.downstream_elements = CList()
18 self.__suspended = True
21 def connectDownstream(self, downstream):
22 self.downstream_elements.append(downstream)
23 if self.master is None:
24 self.master = downstream
26 def connectUpstream(self, upstream):
27 assert self.source is None
28 self.source = upstream
29 self.changed((self.CHANGED_DEFAULT,))
31 def connect(self, upstream):
32 self.connectUpstream(upstream)
33 upstream.connectDownstream(self)
35 # we disconnect from down to up
36 def disconnectAll(self):
37 # we should not disconnect from upstream if
38 # there are still elements depending on us.
39 assert len(self.downstream_elements) == 0, "there are still downstream elements left"
41 # Sources don't have a source themselves. don't do anything here.
42 if self.source is not None:
43 self.source.disconnectDownstream(self)
45 def disconnectDownstream(self, downstream):
46 self.downstream_elements.remove(downstream)
47 if self.master == downstream:
50 if len(self.downstream_elements) == 0:
53 # default action: push downstream
54 def changed(self, *args, **kwargs):
56 self.downstream_elements.changed(*args, **kwargs)
59 def reconnectUpstream(self, new_upstream):
60 assert self.source is not None
61 self.source = new_upstream
66 def setSuspend(self, suspended):
67 changed = self.__suspended != suspended
68 if not self.__suspended and suspended:
70 elif self.__suspended and not suspended:
73 self.__suspended = suspended
74 if self.source is not None and changed:
75 self.source.checkSuspend()
77 suspended = property(lambda self: self.__suspended, setSuspend)
79 def checkSuspend(self):
80 self.suspended = reduce(lambda x, y: x and y.__suspended, self.downstream_elements, True)
82 def doSuspend(self, suspend):